Class BaseGenerator<E>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean stopped
      Set to true when the generator is stopped.
      private Generator<?> wrappedGenerator
      A 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.
      boolean isStopped()
      Check if the generator is stopped.
      void stop()
      Stop the generator.
      java.util.Collection<? super E> to​(java.util.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.
      java.util.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
    • Field Detail

      • wrappedGenerator

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

        private boolean stopped
        Set to true when the generator is stopped.
    • 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 java.util.Collection<? super E> to​(java.util.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 java.util.Collection<E> toCollection()
        Same as to(new CollectionTransformer()). Same as to(new CollectionTransformer()).
        Specified by:
        toCollection in interface Generator<E>
        Returns:
        Collection