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
Base class for generators. Adds support for all of the
to
each subclass.
invalid reference
Algorithms
- Since:
- 1.0
- Version:
- $Revision$ $Date$
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new generator.BaseGenerator(Generator<?> generator) A generator can wrap another generator. -
Method Summary
Modifier and TypeMethodDescriptionprotected Generator<?> Get the generator that is being wrapped.booleanCheck if the generator is stopped.voidstop()Stop the generator.final Collection<? super E> to(Collection<? super E> collection) Same as to(new CollectionTransformer(collection)).final <T> Tto(UnaryFunction<Generator<? extends E>, ? extends T> transformer) Transforms this generator using the passed in transformer.final Collection<E> Same as to(new CollectionTransformer()).
-
Field Details
-
wrappedGenerator
A generator can wrap another generator. -
stopped
private boolean stoppedSet to true when the generator isstopped.
-
-
Constructor Details
-
BaseGenerator
public BaseGenerator()Create a new generator. -
BaseGenerator
A generator can wrap another generator. When wrapping generators you should use probably this constructor since doing so will cause thestop()method to stop the wrapped generator as well.- Parameters:
generator- Generator to wrap
-
-
Method Details
-
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
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
Same as to(new CollectionTransformer(collection)). Same as to(new CollectionTransformer(collection)). -
toCollection
Same as to(new CollectionTransformer()). Same as to(new CollectionTransformer()).- Specified by:
toCollectionin interfaceGenerator<E>- Returns:
- Collection
-