structure
Class DoublyLinkedListIterator

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

public class DoublyLinkedListIterator
extends AbstractIterator

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

      List l = new DoublyLinkedList();
      // ...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  DoublyLinkedListElement current
          Reference to the current node in the list.
protected  DoublyLinkedListElement head
          Reference to head of the list.
protected  DoublyLinkedListElement tail
          Sign of the end of the list.
 
Constructor Summary
DoublyLinkedListIterator(DoublyLinkedListElement h)
          Construct an iterator over a doubly linked list hanging from head.
DoublyLinkedListIterator(DoublyLinkedListElement headDummy, DoublyLinkedListElement tailDummy)
           
 
Method Summary
 java.lang.Object get()
          Get reference to value that is current.
 boolean hasNext()
          Determine if there are more elements to be considered.
 java.lang.Object next()
          Returns reference to the current element, then increments iterator.
 void reset()
          Reset the iterator to 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

head

protected DoublyLinkedListElement head
Reference to head of the list.


tail

protected DoublyLinkedListElement tail
Sign of the end of the list.


current

protected DoublyLinkedListElement current
Reference to the current node in the list.

Constructor Detail

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement h)
Construct an iterator over a doubly linked list hanging from head.

Parameters:
h - The head of the list to be traversed.

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement headDummy,
                                DoublyLinkedListElement tailDummy)
Method Detail

reset

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

Specified by:
reset in class AbstractIterator

hasNext

public boolean hasNext()
Determine if there are more elements to be considered.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class AbstractIterator
Returns:
True iff there are more elements to be considered.
See Also:
AbstractIterator.hasMoreElements()

next

public java.lang.Object next()
Returns reference to the current element, then increments iterator.

Specified by:
next in interface java.util.Iterator
Specified by:
next in class AbstractIterator
Returns:
Reference to element that was current before increment.
See Also:
AbstractIterator.hasMoreElements(), AbstractIterator.value()

get

public java.lang.Object get()
Get reference to value that is current.

Specified by:
get in class AbstractIterator
Returns:
A reference to the value that is current.