structure
Class CircularListIterator

java.lang.Object
  |
  +--structure.AbstractIterator
        |
        +--structure.CircularListIterator
All Implemented Interfaces:
java.util.Enumeration, java.util.Iterator

class CircularListIterator
extends AbstractIterator

An iterator for traversing the elements of a circular list. The iterator traverses the list beginning at the head, and heads toward tail.

Typical use:

      List l = new CircularList();
      // ...list gets built up...
      Iterator li = l.iterator();
      while (li.hasNext())
      {
          System.out.println(li.get());
          li.next();
      }
      li.reset();
      while (li.hasNext())
      { .... }
 


Field Summary
protected  SinglyLinkedListElement current
          The current value of the iterator.
protected  SinglyLinkedListElement tail
          The tail of the traversed list.
 
Constructor Summary
CircularListIterator(SinglyLinkedListElement t)
          Constructs an iterator over circular list whose tail is t
 
Method Summary
 java.lang.Object get()
          Determine the current value of iterator.
 boolean hasNext()
          Determine if there are unconsidered elements.
 java.lang.Object next()
          Return the current value and increment iterator.
 void reset()
          Resets iterator to consider the head of the list.
 
Methods inherited from class structure.AbstractIterator
hasMoreElements, nextElement, remove, value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tail

protected SinglyLinkedListElement tail
The tail of the traversed list.


current

protected SinglyLinkedListElement current
The current value of the iterator.

Constructor Detail

CircularListIterator

public CircularListIterator(SinglyLinkedListElement t)
Constructs an iterator over circular list whose tail is t

Parameters:
t - The tail of the list to be traversed.
Method Detail

reset

public void reset()
Resets iterator to consider the head of the list.

Specified by:
reset in class AbstractIterator

hasNext

public boolean hasNext()
Determine if there are unconsidered elements.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class AbstractIterator
Returns:
True iff some element has not been considered.
See Also:
AbstractIterator.hasMoreElements()

next

public java.lang.Object next()
Return the current value and increment iterator.

Specified by:
next in interface java.util.Iterator
Specified by:
next in class AbstractIterator
Returns:
The current value before incrementing.
See Also:
AbstractIterator.hasMoreElements(), AbstractIterator.value()

get

public java.lang.Object get()
Determine the current value of iterator.

Specified by:
get in class AbstractIterator
Returns:
The current value of the iterator.