Class IteratorWithBuffer<T>

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

public class IteratorWithBuffer<T> extends Object implements IteratorCloseable<T>
Iterator that delays output by N slots so you can react to the output before it's yielded. See also PeekIterator (which predates this code). See also IteratorWithHistory for an iterator that remembers what it has yielded.
See Also:
  • Constructor Details

    • IteratorWithBuffer

      public IteratorWithBuffer(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>
    • peek

      public T peek(int idx)
      Look at elements that will be returned by a subsequent call of .next(). The next element is index 0, then index 1 etc. This operation is valid immediately after the constructor returns. Returns null for no such element (underlying iterator didn't yield enough elements). Throws IndexOutOfBoundsException if an attempt is made to go beyond the buffering window.
    • currentSize

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

      public void set(int idx, T item)
      Set the element to be returned by a subsequent .next(). Use with care. The original element to be returned at this position is lost.
    • close

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