net.sf.molae.pipe.tree
Class DepthFirstIterator<E>

java.lang.Object
  extended by net.sf.molae.pipe.tree.DepthFirstIterator<E>
All Implemented Interfaces:
Iterator<E>

public final class DepthFirstIterator<E>
extends Object
implements Iterator<E>

Provides an Iterator that runs depth first through a tree. For each tree node a method that returns its children as a collection is required. This can be done by

  1. Direct composition: Each member of a collection is again a collection.
  2. the method getComponents() in the interface Composition.
  3. Defining a CompositionView that contains the method calls for each class, that return the children.


Constructor Summary
DepthFirstIterator(E pObject, CompositionView<E> pCompositionView)
          Constructs a DepthFirstIterator.
DepthFirstIterator(Iterator<E> iterator, CompositionView<E> pCompositionView)
          Constructs a DepthFirstIterator.
 
Method Summary
 boolean hasNext()
           
static DepthFirstIterator<Object> newInstance(Object pObject)
          Constructs a DepthFirstIterator.
 E next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DepthFirstIterator

public DepthFirstIterator(Iterator<E> iterator,
                          CompositionView<E> pCompositionView)
Constructs a DepthFirstIterator.

Parameters:
iterator - an iterator defining the topmost level of the tree
pCompositionView - underlying composition view, must not be null.

DepthFirstIterator

public DepthFirstIterator(E pObject,
                          CompositionView<E> pCompositionView)
Constructs a DepthFirstIterator.

Parameters:
pObject - The root of the tree to be traversed
pCompositionView - underlying composition view, must not be null.
Method Detail

newInstance

public static DepthFirstIterator<Object> newInstance(Object pObject)
Constructs a DepthFirstIterator.

Parameters:
pObject - The root of the tree to be traversed

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Specified by:
next in interface Iterator<E>
Throws:
NoSuchElementException - iteration has no more elements.

remove

public void remove()
Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - depending on the collections of the base tree
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.