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 Object implements Generator<E>
Base class for generators. Adds support for all of the
invalid reference
Algorithms
to each subclass.
Since:
1.0
Version:
$Revision$ $Date$
  • Field Details

    • wrappedGenerator

      private final Generator<?> wrappedGenerator
      A generator can wrap another generator.
    • stopped

      private boolean stopped
      Set to true when the generator is stopped.
  • Constructor Details

    • 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 Details

    • 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