Class LazyIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<T>

    public abstract class LazyIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    An unmodifiable iterator which computes the next element to return only when it is requested.

    This class is inspired by com.google.common.collect.AbstractIterator in Google Guava, which was written by the Google Guava Authors, in particular by Kevin Bourrillion.

    • Constructor Detail

      • LazyIterator

        public LazyIterator()
    • Method Detail

      • remove

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

        public final boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
      • tryToComputeNext

        boolean tryToComputeNext()
      • next

        public final T next()
        Specified by:
        next in interface java.util.Iterator<T>
      • endOfData

        protected final T endOfData()
        Returns:
        a dummy value which if returned by the computeNext() method, signals that there are no more elements to return
      • computeNext

        protected abstract T computeNext()
        Returns:
        The next element which the iterator should return, or the result of calling endOfData() if there are no more elements to return