org.eclipse.emf.common.util
Class AbstractTreeIterator<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.eclipse.emf.common.util.BasicEList<java.util.Iterator<? extends E>>
              extended by org.eclipse.emf.common.util.AbstractTreeIterator<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.util.Iterator<? extends E>>, java.util.Collection<java.util.Iterator<? extends E>>, java.util.Iterator<E>, java.util.List<java.util.Iterator<? extends E>>, java.util.RandomAccess, EList<java.util.Iterator<? extends E>>, TreeIterator<E>
Direct Known Subclasses:
AdapterFactoryEditingDomain.DomainTreeIterator, AdapterFactoryTreeIterator, EcoreUtil.ContentTreeIterator, MappingImpl.MappingTreeIterator, ModelExporter.GenPackagesTreeIterator

public abstract class AbstractTreeIterator<E>
extends BasicEList<java.util.Iterator<? extends E>>
implements TreeIterator<E>

An extensible tree iterator implementation that iterates over an object, it's children, their children, and so on. Clients need only implement getChildren in order to implement a fully functional tree iterator.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.util.BasicEList
BasicEList.BasicIndexOutOfBoundsException, BasicEList.EIterator<E1>, BasicEList.EListIterator<E1>, BasicEList.FastCompare<E>, BasicEList.NonResolvingEIterator<E1>, BasicEList.NonResolvingEListIterator<E1>, BasicEList.UnmodifiableEList<E>
 
Field Summary
protected  boolean includeRoot
          Whether the first call to next returns the initial root object or begins with the first child of the root object.
protected  java.util.Iterator<? extends E> nextPruneIterator
          The iterator that would be cut short by a call to prune().
protected  java.util.Iterator<? extends E> nextRemoveIterator
          The iterator to which a remove() call will delegated.
protected  java.lang.Object object
          The root object for which the iteration is initiated.
 
Fields inherited from class org.eclipse.emf.common.util.BasicEList
data, size
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractTreeIterator(E object)
          Creates an instance that iterates over an object, it's children, their children, and so on.
AbstractTreeIterator(java.lang.Object object, boolean includeRoot)
          Creates and instance that iterates over an object (but only if includeRoot is true), it's children, their children, and so on.
 
Method Summary
protected abstract  java.util.Iterator<? extends E> getChildren(java.lang.Object object)
          Returns the iterator that yields the children of the object.
 boolean hasNext()
          Returns whether there are more elements.
 E next()
          Returns the next object and advances the iterator.
 void prune()
          Prunes the iterator so that it skips over all the nodes below the most recent result of calling next().
 void remove()
          Removes the last object returned by next() from the underlying tree; it's an optional operation.
 
Methods inherited from class org.eclipse.emf.common.util.BasicEList
add, add, addAll, addAll, addAllUnique, addAllUnique, addAllUnique, addAllUnique, addUnique, addUnique, assign, basicGet, basicIterator, basicList, basicListIterator, basicListIterator, canContainNull, clear, clone, contains, containsAll, data, didAdd, didChange, didClear, didMove, didRemove, didSet, equalObjects, equals, get, getDuplicates, getNonDuplicates, grow, hashCode, indexOf, isEmpty, isUnique, iterator, lastIndexOf, listIterator, listIterator, move, move, newData, remove, remove, removeAll, resolve, retainAll, set, setData, setUnique, shrink, size, toArray, toArray, toString, useEquals, validate
 
Methods inherited from class java.util.AbstractList
removeRange, subList
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
subList
 

Field Detail

includeRoot

protected boolean includeRoot
Whether the first call to next returns the initial root object or begins with the first child of the root object.


object

protected java.lang.Object object
The root object for which the iteration is initiated.


nextPruneIterator

protected java.util.Iterator<? extends E> nextPruneIterator
The iterator that would be cut short by a call to prune().


nextRemoveIterator

protected java.util.Iterator<? extends E> nextRemoveIterator
The iterator to which a remove() call will delegated.

Constructor Detail

AbstractTreeIterator

public AbstractTreeIterator(E object)
Creates an instance that iterates over an object, it's children, their children, and so on.

Parameters:
object - the root object of the tree.

AbstractTreeIterator

public AbstractTreeIterator(java.lang.Object object,
                            boolean includeRoot)

Creates and instance that iterates over an object (but only if includeRoot is true), it's children, their children, and so on.

If includeRoot is true, the object is expected to be of the type E.

Method Detail

getChildren

protected abstract java.util.Iterator<? extends E> getChildren(java.lang.Object object)
Returns the iterator that yields the children of the object.

Parameters:
object - the object for which children are required.
Returns:
the iterator that yields the children.

hasNext

public boolean hasNext()
Returns whether there are more elements.

Specified by:
hasNext in interface java.util.Iterator<E>
Returns:
whether there are more elements.

next

public E next()
Returns the next object and advances the iterator.

Specified by:
next in interface java.util.Iterator<E>
Returns:
the next object.

remove

public void remove()
Removes the last object returned by next() from the underlying tree; it's an optional operation.

Specified by:
remove in interface java.util.Iterator<E>
Throws:
java.lang.IllegalStateException - if next has not yet been called or has been called only the yield the root object, or remove has already been called after the last call to the next method.

prune

public void prune()
Prunes the iterator so that it skips over all the nodes below the most recent result of calling next().

Specified by:
prune in interface TreeIterator<E>

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.