Class BaseGenerator<E>
- java.lang.Object
-
- org.apache.commons.functor.generator.BaseGenerator<E>
-
- Type Parameters:
E- the type of elements held in this generator.
- All Implemented Interfaces:
Generator<E>
- Direct Known Subclasses:
FilteredGenerator,GenerateUntil,GenerateWhile,IntegerRange,IteratorToGeneratorAdapter,LongRange,TransformedGenerator,UntilGenerate,WhileGenerate
public abstract class BaseGenerator<E> extends java.lang.Object implements Generator<E>
Base class for generators. Adds support for all of theAlgorithmsto each subclass.- Since:
- 1.0
- Version:
- $Revision$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description private booleanstoppedSet to true when the generator isstopped.private Generator<?>wrappedGeneratorA generator can wrap another generator.
-
Constructor Summary
Constructors Constructor Description BaseGenerator()Create a new generator.BaseGenerator(Generator<?> generator)A generator can wrap another generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Generator<?>getWrappedGenerator()Get the generator that is being wrapped.booleanisStopped()Check if the generator is stopped.voidstop()Stop the generator.java.util.Collection<? super E>to(java.util.Collection<? super E> collection)Same as to(new CollectionTransformer(collection)).<T> Tto(UnaryFunction<Generator<? extends E>,? extends T> transformer)Transforms this generator using the passed in transformer.java.util.Collection<E>toCollection()Same as to(new CollectionTransformer()).
-
-
-
Method Detail
-
getWrappedGenerator
protected Generator<?> getWrappedGenerator()
Get the generator that is being wrapped.- Returns:
- Generator
-
stop
public void stop()
Stop the generator. Will stop the wrapped generator if one was set. Stop the generator. Will stop the wrapped generator if one was set.
-
isStopped
public boolean isStopped()
Check if the generator is stopped. Check if the generator is stopped.
-
to
public final <T> T to(UnaryFunction<Generator<? extends E>,? extends T> transformer)
Transforms this generator using the passed in transformer. An example transformer might turn the contents of the generator into aCollectionof elements. Transforms this generator using the passed in UnaryFunction. An example function might turn the contents of the generator into aCollectionof elements.- Specified by:
toin interfaceGenerator<E>- Type Parameters:
T- the returned value type of the inputUnaryFunction.- Parameters:
transformer- UnaryFunction to apply to this- Returns:
- transformation result
-
to
public final java.util.Collection<? super E> to(java.util.Collection<? super E> collection)
Same as to(new CollectionTransformer(collection)). Same as to(new CollectionTransformer(collection)).
-
toCollection
public final java.util.Collection<E> toCollection()
Same as to(new CollectionTransformer()). Same as to(new CollectionTransformer()).- Specified by:
toCollectionin interfaceGenerator<E>- Returns:
- Collection
-
-