Class AbstractTreeIterator<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Iterator<? extends E>>, Collection<Iterator<? extends E>>, Iterator<E>, List<Iterator<? extends E>>, RandomAccess, SequencedCollection<Iterator<? extends E>>, EList<Iterator<? extends E>>, TreeIterator<E>

public abstract class AbstractTreeIterator<E> extends BasicEList<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:
  • Field Details

    • 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 Object object
      The root object for which the iteration is initiated.
    • nextPruneIterator

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

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

    • 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(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 Details

    • getChildren

      protected abstract Iterator<? extends E> getChildren(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 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 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 Iterator<E>
      Throws:
      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>