Skip to content

Instantly share code, notes, and snippets.

@kinow
Created September 20, 2012 02:57
Show Gist options
  • Save kinow/3753698 to your computer and use it in GitHub Desktop.
Save kinow/3753698 to your computer and use it in GitHub Desktop.
new CollectionTransformer
public class CollectionTransformer<E> implements UnaryFunction<Generator<? extends E>, Collection<? super E>> {
// instance methods
//---------------------------------------------------
/**
* {@inheritDoc}
*/
public Collection<? super E> evaluate(Generator<? extends E> generator) {
final List<? super E> list = new ArrayList<E>();
generator.run(new UnaryProcedure<E>() {
public void run(E obj) {
list.add(obj);
}
});
return list;
}
/**
* Get a {@link CollectionTransformer} instance that simply returns any {@link Collection}.
* @return {@link CollectionTransformer}
*/
public static <E> CollectionTransformer<E> toCollection() {
return new CollectionTransformer<E>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment