Package org.apache.jena.atlas.iterator
Class IteratorWithBuffer<T>
- java.lang.Object
-
- org.apache.jena.atlas.iterator.IteratorWithBuffer<T>
-
- All Implemented Interfaces:
java.util.Iterator<T>
public class IteratorWithBuffer<T> extends java.lang.Object implements java.util.Iterator<T>Iterator that delays output by N slots so you can react to the output before it's yielded. See alsoPeekIterator(which predates this code). See alsoIteratorWithHistoryfor an iterator that remembers what it has yielded.- See Also:
PeekIterator,PushbackIterator,IteratorWithHistory
-
-
Constructor Summary
Constructors Constructor Description IteratorWithBuffer(java.util.Iterator<T> iter, int N)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcurrentSize()Return the current size of the lookahead.booleanhasNext()Tnext()Tpeek(int idx)Look at elements that will be returned by a subsequent call of .next().voidset(int idx, T item)Set the element to be returned by a subsequent .next().
-
-
-
Constructor Detail
-
IteratorWithBuffer
public IteratorWithBuffer(java.util.Iterator<T> iter, int N)
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.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.
-
-