gshute.util
Class NestedIterator

java.lang.Object
  |
  +--gshute.util.NestedIterator

public class NestedIterator
extends java.lang.Object
implements java.util.Iterator

A NestedIterator consists of an outer iterator for a set of objects, each of which can provide an inner iterator for a set of objects. The iteration sequence for the nested iterator is the concatenation, in outer iteration sequence order, of the iteration sequences of all of the inner iterators. The constructor for a nested iterator specifies the outer iterator and an iterator converter. The iterator converter determines the inner iterator for each of the objects in the outer iteration sequence.


Field Summary
protected  java.util.Iterator currentInnerIterator
          currentInnerIterator is the current inner iterator.
protected static IteratorConverter defaultConverter
           
protected  IteratorConverter iteratorConverter
          iteratorConverter generates the inner iterators.
protected  java.util.Iterator lastInnerIterator
          lastInnerIterator is the inner iterator used in the last next() message.
protected  java.util.Iterator outerIterator
          outerIterator is the outer iterator.
 
Constructor Summary
NestedIterator(java.util.Collection c)
          new NestedIterator(c) returns a new nested iterator whose outer iterator is a default iterator for c.
NestedIterator(java.util.Collection c, IteratorConverter icvtr)
          new NestedIterator(c, icvtr) returns a new nested iterator whose outer iterator is a default iterator for c.
NestedIterator(java.util.Iterator iter)
          new NestedIterator(iter) returns a new nested iterator with outer iterator iter.
NestedIterator(java.util.Iterator iter, IteratorConverter icvtr)
          new NestedIterator(iter, icvtr) returns a new nested iterator with outer iterator iter.
 
Method Summary
 boolean hasNext()
          iter.hasNext() returns true if there is another object in iter.
 java.lang.Object next()
          iter.next() returns the next object in iter and advances iter.
 void remove()
          iter.remove() removes the last object returned by iter.next() from its underlying collection.
protected  void validate()
          validate() advances the outer iterator for this nested iterator while the inner iterator is exhausted and the outer iterator is not exhausted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outerIterator

protected java.util.Iterator outerIterator
outerIterator is the outer iterator.

iteratorConverter

protected IteratorConverter iteratorConverter
iteratorConverter generates the inner iterators.

currentInnerIterator

protected java.util.Iterator currentInnerIterator
currentInnerIterator is the current inner iterator.

lastInnerIterator

protected java.util.Iterator lastInnerIterator
lastInnerIterator is the inner iterator used in the last next() message.

defaultConverter

protected static IteratorConverter defaultConverter
Constructor Detail

NestedIterator

public NestedIterator(java.util.Collection c)
new NestedIterator(c) returns a new nested iterator whose outer iterator is a default iterator for c. The inner iterators are default iterators from objects in the outer iteration sequence, which must implement the Collection interface.

NestedIterator

public NestedIterator(java.util.Collection c,
                      IteratorConverter icvtr)
new NestedIterator(c, icvtr) returns a new nested iterator whose outer iterator is a default iterator for c. The inner iterators are generated by icvtr from objects in the outer iteration sequence.

NestedIterator

public NestedIterator(java.util.Iterator iter)
new NestedIterator(iter) returns a new nested iterator with outer iterator iter. The inner iterators are default iterators from objects in the outer iteration sequence, which must implement the Collection interface.

NestedIterator

public NestedIterator(java.util.Iterator iter,
                      IteratorConverter icvtr)
new NestedIterator(iter, icvtr) returns a new nested iterator with outer iterator iter. The inner iterators are generated by icvtr from objects in the outer iteration sequence.
Method Detail

hasNext

public boolean hasNext()
iter.hasNext() returns true if there is another object in iter.
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
iter.next() returns the next object in iter and advances iter.
Specified by:
next in interface java.util.Iterator

remove

public void remove()
iter.remove() removes the last object returned by iter.next() from its underlying collection. This operation is supported by a nested iterator only if it is supported by its inner iterators. This method should not be used if two of the inner iterators have the same underlying collection.
Specified by:
remove in interface java.util.Iterator

validate

protected void validate()
validate() advances the outer iterator for this nested iterator while the inner iterator is exhausted and the outer iterator is not exhausted.