org.jrdf.util
Class IteratorStack<T>

java.lang.Object
  extended by org.jrdf.util.IteratorStack<T>
All Implemented Interfaces:
Iterator<T>

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

Wraps an Iterator to provide a stack interface to it's contents.

Author:
TurnerRX

Constructor Summary
IteratorStack(Iterator<T> iter)
          Creates a new stack that wraps the Iterator.
 
Method Summary
 boolean hasNext()
           
 T next()
           
 T peek()
          Returns the next item on the stack without removing it.
 T pop()
          Removes the next item from the stack and returns it.
 void push(T item)
          Pushes the item onto the stack.
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorStack

public IteratorStack(Iterator<T> iter)
Creates a new stack that wraps the Iterator.

Parameters:
iter - Iterator
Method Detail

peek

public T peek()
Returns the next item on the stack without removing it. This will either be the last item that was "pushed" onto the stack, or next item in the Iterator if the stack does not contain any "pushed" items.

Returns:
T item

pop

public T pop()
Removes the next item from the stack and returns it. This will either be the last item that was "pushed" onto the stack, or next item in the Iterator if the stack does not contain any "pushed" items.

Returns:
T item

push

public void push(T item)
Pushes the item onto the stack.

Parameters:
item - to be place on top of the stack

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()
            throws UnsupportedOperationException
Specified by:
remove in interface Iterator<T>
Throws:
UnsupportedOperationException