edu.colorado.nodes
Class Lister<E>

java.lang.Object
  extended by edu.colorado.nodes.Lister<E>
All Implemented Interfaces:
java.util.Iterator<E>

public class Lister<E>
extends java.lang.Object
implements java.util.Iterator<E>

A Lister implements Java's Iterator<E> interface for a linked list made from Node<E> nodes. Note that this implementation of an Iterator<E> does not support the remove method. Any activation of remove results in an UnsupportedOperationException.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/nodes/Lister.java

See Also:
Node

Constructor Summary
Lister(Node<E> head)
          Initialize a Lister with a specified linked list.
 
Method Summary
 boolean hasNext()
          Determine whether there are any more elements in this Lister.
 E next()
          Retrieve the next element of this Lister.
 void remove()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lister

public Lister(Node<E> head)
Initialize a Lister with a specified linked list.

Parameters:
head - a head reference for a linked list of objects
Postcondition:
Subsequent activations of next will return the elements from this linked list, one after another. If the linked list changes in any way before all the elements have been returned, then the subsequent behavior of this Lister is unspecified.
Method Detail

hasNext

public boolean hasNext()
Determine whether there are any more elements in this Lister.

Specified by:
hasNext in interface java.util.Iterator<E>
Parameters:
- - none
Returns:
true if there are more elements in this Lister; false otherwise.

next

public E next()
Retrieve the next element of this Lister.

Specified by:
next in interface java.util.Iterator<E>
Parameters:
- - none a bag whose contents will be added to this bag
Precondition:
hasMoreElements() must be true.
Returns:
The return value is the next element of this Lister. Note that each element is only returned once, and then the Lister automatically advances to the next element.
Throws:
java.util.NoSuchElementException - Indicates that hasMoreElements() is false.

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<E>