Class AbstractIterator<T>

  • Type Parameters:
    T - the type of elements returned by this iterator
    All Implemented Interfaces:
    Iterator<T>

    public abstract class AbstractIterator<T>
    extends Object
    implements Iterator<T>
    An abstract base class for implementing iterators with custom logic. Subclasses should implement computeNext() to provide elements and must call endOfData() to signal no more element.

    The iteration ends when endOfData() is called from computeNext().

    • Constructor Detail

      • AbstractIterator

        protected AbstractIterator()
    • Method Detail

      • computeNext

        protected abstract T computeNext()
        Computes the next element in the iteration. Subclasses must implement this method and call endOfData() when no more elements are available.
        Returns:
        the next element, or endOfData() if iteration is over
      • endOfData

        protected final T endOfData()
        Signals that the iteration has no more elements. Should be called from computeNext() to end iteration.
        Returns:
        null, indicating end of data
      • hasNext

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

        public T next()
        Specified by:
        next in interface Iterator<T>