Class LazyIterator<T>

java.lang.Object
org.apache.jena.util.iterator.NiceIterator<T>
org.apache.jena.util.iterator.LazyIterator<T>
All Implemented Interfaces:
Iterator<T>, org.apache.jena.atlas.iterator.IteratorCloseable<T>, org.apache.jena.atlas.lib.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 Details

    • 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 Details

    • hasNext

      public boolean hasNext()
      Description copied from class: NiceIterator
      default hasNext: no elements, return false.
      Specified by:
      hasNext in interface 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 Iterator<T>
      Overrides:
      next in class NiceIterator<T>
    • forEachRemaining

      public void forEachRemaining(Consumer<? super T> action)
    • 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 Iterator<T>
      Overrides:
      remove in class NiceIterator<T>
    • close

      public void close()
      Description copied from class: NiceIterator
      default close: don't need to do anything.
      Specified by:
      close in interface ClosableIterator<T>
      Specified by:
      close in interface org.apache.jena.atlas.lib.Closeable
      Overrides:
      close 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.