public class SingletonListIterator<E> extends java.lang.Object implements ResettableListIterator<E>
SingletonIterator is an ListIterator over a single
object instance.| Modifier and Type | Field and Description |
|---|---|
private boolean |
beforeFirst |
private boolean |
nextCalled |
private E |
object |
private boolean |
removed |
| Constructor and Description |
|---|
SingletonListIterator(E object)
Constructs a new
SingletonListIterator. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(E obj)
Add always throws
UnsupportedOperationException. |
boolean |
hasNext()
Is another object available from the iterator?
|
boolean |
hasPrevious()
Is a previous object available from the iterator?
|
E |
next()
Get the next object from the iterator.
|
int |
nextIndex()
Returns the index of the element that would be returned by a subsequent
call to next.
|
E |
previous()
Get the previous object from the iterator.
|
int |
previousIndex()
Returns the index of the element that would be returned by a subsequent
call to previous.
|
void |
remove()
Remove the object from this iterator.
|
void |
reset()
Reset the iterator back to the start.
|
void |
set(E obj)
Set sets the value of the singleton.
|
private boolean beforeFirst
private boolean nextCalled
private boolean removed
private E object
public SingletonListIterator(E object)
SingletonListIterator.object - the single object to return from the iteratorpublic boolean hasNext()
This returns true if the single object hasn't been returned yet.
public boolean hasPrevious()
This returns true if the single object has been returned.
hasPrevious in interface java.util.ListIterator<E>hasPrevious in interface OrderedIterator<E>public int nextIndex()
nextIndex in interface java.util.ListIterator<E>public int previousIndex()
previousIndex in interface java.util.ListIterator<E>public E next()
This returns the single object if it hasn't been returned yet.
public E previous()
This returns the single object if it has been returned.
previous in interface java.util.ListIterator<E>previous in interface OrderedIterator<E>java.util.NoSuchElementException - if the single object has not already
been returnedpublic void remove()
public void add(E obj)
UnsupportedOperationException.add in interface java.util.ListIterator<E>obj - the object to addjava.lang.UnsupportedOperationException - alwayspublic void set(E obj)
set in interface java.util.ListIterator<E>obj - the object to setjava.lang.IllegalStateException - if next has not been called
or the object has been removedpublic void reset()
reset in interface ResettableIterator<E>