Class AbstractIteratorDecorator<E>

  • Type Parameters:
    E - the type of elements returned by this iterator.
    All Implemented Interfaces:
    java.util.Enumeration<E>, java.util.Iterator<E>
    Direct Known Subclasses:
    IteratorDecorator, JoinIterator

    public abstract class AbstractIteratorDecorator<E>
    extends java.lang.Object
    implements java.util.Iterator<E>, java.util.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 Detail

      • AbstractIteratorDecorator

        public AbstractIteratorDecorator()
    • Method Detail

      • getIterator

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

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

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

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

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

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