net.sf.jauvm.util
Class Generator<T>

java.lang.Object
  extended by net.sf.jauvm.util.Generator<T>

public abstract class Generator<T>
extends Object

The abstract base class for generators.

This class serves as the base class for generators, providing them the generate(Object... args) and yield(T value) methods. Sub-classes must implement the run(Object... args) method.

Note: the same Generator object is not to be used to iterate on more than one iterator simultaneously. For that purpose, you should create two (or more) Generator objects of the same class.

See Also:
Iterable, Iterator

Constructor Summary
Generator()
           
 
Method Summary
 Iterable<T> generate(Object... args)
          Creates an Iterable object that will have the values for its iterators generated by this Generator object.
protected abstract  void run(Object... args)
          Generates the next value for the present iterator.
protected  void yield(T value)
          Hands down the next value to be yielded by the present iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Generator

public Generator()
Method Detail

run

protected abstract void run(Object... args)
Generates the next value for the present iterator.

This method is called by the Iterator objects associated with the Iterable object returned by the generate(Object... args) method to produce each next value for the iterator.

Values are successively passed from this method to those iterators by calling the yield method and proceding with determining the next value to pass. When no more values can be produced, this method should return.

The arguments passed to this method are the arguments given to the generate(Object... args) method that returned the Iterable object whose iterators are invoking this method.

Parameters:
args - the args passed to the generate(Object... args) method
See Also:
generate(Object...), yield(Object)

yield

protected final void yield(T value)
Hands down the next value to be yielded by the present iterator.

This method should be called by the run(Object... args) method to pass the next value to be yielded to the iterator.

Parameters:
value - the next value to pass to the iterator
Throws:
UnsupportedOperationException - if yield is invoked outside the context of an iterator.

generate

public final Iterable<T> generate(Object... args)
Creates an Iterable object that will have the values for its iterators generated by this Generator object. The arguments to this method will be passed to the run(Object... args) method, which will successively generate each value for the returned Iterable object's iterators.

Parameters:
args - the arguments to be handed down to the run(Object... args) method
Returns:
the new Iterable object