Say I have a large collection of Java static methods in a class of only static methods. All of them apply to some type of collection class. How can I scan this class, and using Groovy add each of them to the respective metaclasses?
So a sample might look something like this:
public class CollectionUtilities {
public static <T> T duplicates(Collection<T> coll) {
return // some code to isolate the duplicates
}
}
I'd want that to end up so I could call [1, 2, 2].duplicates() => [2]
Collection.metaClass.duplicates = { -> // replace coll usages with delegate }
Has anyone done anything like this?
Any idea of a good way to go about it?