org.openjena.atlas.iterator
Class IteratorWithBuffer<T>

java.lang.Object
  extended by org.openjena.atlas.iterator.IteratorWithBuffer<T>
All Implemented Interfaces:
Iterator<T>

public class IteratorWithBuffer<T>
extends Object
implements Iterator<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:
PeekIterator, PushbackIterator, IteratorWithHistory

Constructor Summary
IteratorWithBuffer(Iterator<T> iter, int N)
           
 
Method Summary
 int currentSize()
          Return the current size of the lookahead.
 boolean hasNext()
           
 T next()
           
 T peek(int idx)
          Look at elements that will be returned by a subsequnet call of .next().
 void remove()
           
 void set(int idx, T item)
          Set the element to be returned by a subsequent .next().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorWithBuffer

public IteratorWithBuffer(Iterator<T> iter,
                          int N)
Method Detail

hasNext

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

next

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

remove

public void remove()
Specified by:
remove in interface Iterator<T>

peek

public T peek(int idx)
Look at elements that will be returned by a subsequnet 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 yeild enough elements). Throws IndexOutOfBoundsException if an attempt i smade 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.



Licenced under the Apache License, Version 2.0