Class 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 will yield.
    See Also:
    IteratorWithBuffer, PeekIterator, PushbackIterator
    • Constructor Summary

      Constructors 
      Constructor Description
      IteratorWithHistory​(java.util.Iterator<T> iter, int N)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int currentSize()
      Return the current size of the history.
      T getPrevious​(int idx)
      return the previous i'th element returned by next().
      boolean hasNext()  
      T next()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • 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>
      • 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 history. This can be used to tell the difference between an iterator returning null and an iterator that is just short.