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

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

public class IteratorWithHistory<T>
extends java.lang.Object
implements java.util.Iterator<T>

Remembers the last N yields. See also IteratorWithBuffer, for an iterator that looks ahead to what it wil yield.

See Also:
IteratorWithBuffer, PeekIterator, PushbackIterator

Constructor Summary
IteratorWithHistory(java.util.Iterator<T> iter, int N)
           
 
Method Summary
 int currentSize()
          Return the current size of the histiory.
 T getPrevious(int idx)
          return the previous i'th element returned by next().
 boolean hasNext()
           
 T next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorWithHistory

public IteratorWithHistory(java.util.Iterator<T> iter,
                           int N)
Method Detail

hasNext

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

next

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

remove

public void remove()
Specified by:
remove in interface java.util.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:
java.lang.IndexOutOfBoundsException - if index is negative.

currentSize

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



Copyright ? 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP Copyright ? 2010 Talis Systems Ltd. Copyright ? 2010, 2011 Epimorphics Ltd.