Class AbstractIteratorDecorator<E>

java.lang.Object
com.globalmentor.collections.iterators.AbstractIteratorDecorator<E>
Type Parameters:
E - the type of elements returned by this iterator.
All Implemented Interfaces:
Enumeration<E>, Iterator<E>
Direct Known Subclasses:
IteratorDecorator, JoinIterator

public abstract class AbstractIteratorDecorator<E> extends Object implements Iterator<E>, Enumeration<E>
An abstract base implementation of an iterator that wraps an existing Iterator.
Author:
Garret Wilson
API Note:
This iterator also serves as an adapter, converting an iterator to an Enumeration.
Implementation Note:
Subclasses may override hasNext() and/or next(), and Enumeration compatibility will be maintained., This implementation specifically does not override Iterator.forEachRemaining(Consumer) to delegate to the underlying iterator's version of the method, because subclasses are allowed to change the decorated iterator during iteration. Therefore the default method version is retained, which calls hasNext() and next() repeatedly, allowing a subclass to acquire a different underlying iterator if it desires.
  • Constructor Details

    • AbstractIteratorDecorator

      public AbstractIteratorDecorator()
  • Method Details

    • getIterator

      protected abstract Iterator<E> getIterator()
      Returns:
      The iterator this class decorates.
    • hasNext

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

      public E next()
      Specified by:
      next in interface Iterator<E>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<E>
    • hasMoreElements

      public final boolean hasMoreElements()
      Specified by:
      hasMoreElements in interface Enumeration<E>
      Implementation Specification:
      This implementation delegates to hasNext().
    • nextElement

      public final E nextElement()
      Specified by:
      nextElement in interface Enumeration<E>
      Implementation Specification:
      This implementation delegates to next().