structure
Class SinglyLinkedListIterator

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

class SinglyLinkedListIterator
extends AbstractIterator

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

Typical use:

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


Field Summary
protected  SinglyLinkedListElement current
          The reference to currently considered element within list.
protected  SinglyLinkedListElement head
          The head of list.
 
Constructor Summary
SinglyLinkedListIterator(SinglyLinkedListElement t)
          Construct an iterator that traverses list beginning at t.
 
Method Summary
 java.lang.Object get()
          Return structure's current object reference.
 boolean hasNext()
          Determine if the iteration is finished.
 java.lang.Object next()
          Return current value and increment Iterator.
 void reset()
          Reset iterator to beginning of the structure.
 
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

current

protected SinglyLinkedListElement current
The reference to currently considered element within list.


head

protected SinglyLinkedListElement head
The head of list.

Constructor Detail

SinglyLinkedListIterator

public SinglyLinkedListIterator(SinglyLinkedListElement t)
Construct an iterator that traverses list beginning at t.

Parameters:
t - The first element of list to be traversed.
Method Detail

reset

public void reset()
Reset iterator to beginning of the structure.

Specified by:
reset in class AbstractIterator

hasNext

public boolean hasNext()
Determine if the iteration is finished.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class AbstractIterator
Returns:
True if the iterator has more elements to be considered.
See Also:
AbstractIterator.hasMoreElements()

next

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

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

get

public java.lang.Object get()
Return structure's current object reference.

Specified by:
get in class AbstractIterator
Returns:
Object currently referenced.