public class Lister<E>
extends java.lang.Object
implements java.util.Iterator<E>
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 Node
Constructor and Description |
---|
Lister(Node<E> head)
Initialize a Lister with a specified linked list.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Determine whether there are any more elements in this Lister.
|
E |
next()
Retrieve the next element of this
Lister . |
void |
remove() |
public Lister(Node<E> head)
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.public boolean hasNext()
hasNext
in interface java.util.Iterator<E>
true
if there are more elements in this
Lister
; false
otherwise.public E next()
Lister
.
a bag whose contents will be added to this bag
Precondition:
hasMoreElements()
must be true
.next
in interface java.util.Iterator<E>
Lister
.
Note that each element is only returned once, and then the
Lister
automatically advances to the next element.java.util.NoSuchElementException
- Indicates that hasMoreElements()
is false
.public void remove()
remove
in interface java.util.Iterator<E>