Class LazyIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<T>, IteratorCloseable<T>, Closeable, ClosableIterator<T>, ExtendedIterator<T>

    public abstract class LazyIterator<T>
    extends NiceIterator<T>
    An ExtendedIterator that is created lazily. This is useful when constructing an iterator is expensive and you'd prefer to delay doing it until certain it's actually needed. For example, if you have iterator1.andThen(iterator2) you could implement iterator2 as a LazyIterator. The sequence to be defined is defined by the subclass's definition of create(). That is called exactly once on the first attempt to iterate (i.e. use one of the hasNext, next, remove, removeNext operations, maybe indirectly via toList).
    • Constructor Detail

      • LazyIterator

        public LazyIterator()
        An ExtendedIterator that is created lazily. This constructor has very low overhead - the real work is delayed until the first attempt to use the iterator.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Description copied from class: NiceIterator
        default hasNext: no elements, return false.
        Specified by:
        hasNext in interface java.util.Iterator<T>
        Overrides:
        hasNext in class NiceIterator<T>
      • next

        public T next()
        Description copied from class: NiceIterator
        default next: throw an exception.
        Specified by:
        next in interface java.util.Iterator<T>
        Overrides:
        next in class NiceIterator<T>
      • remove

        public void remove()
        Description copied from class: NiceIterator
        default remove: we have no elements, so we can't remove any.
        Specified by:
        remove in interface java.util.Iterator<T>
        Overrides:
        remove in class NiceIterator<T>
      • create

        public abstract ExtendedIterator<T> create()
        The subclass must define this to return the ExtendedIterator to invoke. This method will be called at most once, on the first attempt to use the iterator. From then on, all calls to this will be passed through to the returned Iterator.
        Returns:
        The parent iterator defining the sequence.