Class IteratorWithHistory<T>

java.lang.Object
org.apache.jena.atlas.iterator.IteratorWithHistory<T>
All Implemented Interfaces:
Iterator<T>, IteratorCloseable<T>, Closeable

public class IteratorWithHistory<T> extends Object implements IteratorCloseable<T>
Remembers the last N yields. See also IteratorWithBuffer, for an iterator that looks ahead to what it will yield. History is retained at the end of iterator. "Close" releases the history.
See Also:
  • Constructor Details

    • IteratorWithHistory

      public IteratorWithHistory(Iterator<T> iter, int N)
  • Method Details

    • hasNext

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

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

      public T getPrevious(int idx)
      return the previous i'th element returned by next(). 0 means last call of next. History is retained after the end of iteration.
      Returns:
      Element or null for no such element (that is for haven't yielded that many elements).
      Throws:
      IndexOutOfBoundsException - if index is negative.
    • currentSize

      public int currentSize()
      Return the current size of the history. This can be used to tell the difference between an iterator returning null and an iterator that is just short.
    • close

      public void close()
      Specified by:
      close in interface Closeable