org.apache.commons.functor.generator
Class BaseGenerator<E>

java.lang.Object
  extended by org.apache.commons.functor.generator.BaseGenerator<E>
All Implemented Interfaces:
Generator<E>
Direct Known Subclasses:
FilteredGenerator, GenerateUntil, GenerateWhile, IntegerRange, IteratorToGeneratorAdapter, LongRange, TransformedGenerator, UntilGenerate, WhileGenerate

public abstract class BaseGenerator<E>
extends Object
implements Generator<E>

Base class for generators. Adds support for all of the Algorithms to each subclass.

Since:
1.0
Version:
$Revision: 1156778 $ $Date: 2011-08-11 21:50:51 +0200 (Thu, 11 Aug 2011) $
Author:
Jason Horman (jason@jhorman.org)

Constructor Summary
BaseGenerator()
          Create a new generator.
BaseGenerator(Generator<?> generator)
          A generator can wrap another generator.
 
Method Summary
protected  Generator<?> getWrappedGenerator()
          Get the generator that is being wrapped.
 boolean isStopped()
          Check if the generator is stopped.
 void stop()
          Stop the generator.
 Collection<? super E> to(Collection<? super E> collection)
          Same as to(new CollectionTransformer(collection)).
<T> T
to(UnaryFunction<Generator<? extends E>,? extends T> transformer)
          Transforms this generator using the passed in transformer.
 Collection<E> toCollection()
          Same as to(new CollectionTransformer()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.functor.generator.Generator
run
 

Constructor Detail

BaseGenerator

public BaseGenerator()
Create a new generator.


BaseGenerator

public BaseGenerator(Generator<?> generator)
A generator can wrap another generator. When wrapping generators you should use probably this constructor since doing so will cause the stop() method to stop the wrapped generator as well.

Parameters:
generator - Generator to wrap
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.

Specified by:
stop in interface Generator<E>

isStopped

public boolean isStopped()
Check if the generator is stopped. Check if the generator is stopped.

Specified by:
isStopped in interface Generator<E>
Returns:
true if 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 a Collection of elements. Transforms this generator using the passed in UnaryFunction. An example function might turn the contents of the generator into a Collection of elements.

Specified by:
to in interface Generator<E>
Type Parameters:
T - the returned value type of the input UnaryFunction.
Parameters:
transformer - UnaryFunction to apply to this
Returns:
transformation result

to

public final Collection<? super E> to(Collection<? super E> collection)
Same as to(new CollectionTransformer(collection)). Same as to(new CollectionTransformer(collection)).

Specified by:
to in interface Generator<E>
Parameters:
collection - Collection to which my elements should be added
Returns:
collection

toCollection

public final Collection<E> toCollection()
Same as to(new CollectionTransformer()). Same as to(new CollectionTransformer()).

Specified by:
toCollection in interface Generator<E>
Returns:
Collection


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.