spiffy.core.util
Class PushBackIterator<T>

java.lang.Object
  extended by spiffy.core.util.PushBackIterator<T>
All Implemented Interfaces:
Iterator<T>

public class PushBackIterator<T>
extends Object
implements Iterator<T>

The PushBackIterator enables you to iterate and push back elements should you find that "you have come to far". You can push elements back in the iterator which then will be re-visited upon the subsequent call to next()

Author:
Kasper B. Graversen

Constructor Summary
PushBackIterator(Iterator<T> iterator)
           
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 T next()
          Returns the next element in the iteration.
 void pushBack()
          Push back the last fetched element
 void remove()
          Operation currently not supported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushBackIterator

public PushBackIterator(Iterator<T> iterator)
Parameters:
iterator - the iterator to wrap in order to get the push back functionality.
Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Specified by:
hasNext in interface Iterator<T>
Returns:
true if the iterator has more elements.

next

public T next()
Returns the next element in the iteration. Calling this method repeatedly until the hasNext() method returns false will return each element in the underlying collection exactly once.

Specified by:
next in interface Iterator<T>
Returns:
the next element in the iteration.

pushBack

public void pushBack()
Push back the last fetched element


remove

public void remove()
Operation currently not supported

Specified by:
remove in interface Iterator<T>