Created
September 20, 2012 02:57
-
-
Save kinow/3753698 to your computer and use it in GitHub Desktop.
new CollectionTransformer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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