public class ReverseListIterator<E> extends Object implements ResettableListIterator<E>
The first call to next()
will return the last element
from the list, and so on. The hasNext()
method works
in concert with the next()
method as expected.
However, the nextIndex()
method returns the correct
index in the list, thus it starts high and reduces as the iteration
continues. The previous methods work similarly.
Constructor and Description |
---|
ReverseListIterator(List<E> list)
Constructor that wraps a list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(E obj)
Adds a new element to the list between the next and previous elements.
|
boolean |
hasNext()
Checks whether there is another element.
|
boolean |
hasPrevious()
Checks whether there is a previous element.
|
E |
next()
Gets the next element.
|
int |
nextIndex()
Gets the index of the next element.
|
E |
previous()
Gets the previous element.
|
int |
previousIndex()
Gets the index of the previous element.
|
void |
remove()
Removes the last returned element.
|
void |
reset()
Resets the iterator back to the start (which is the
end of the list as this is a reversed iterator)
|
void |
set(E obj)
Replaces the last returned element.
|
public ReverseListIterator(List<E> list)
list
- the list to create a reversed iterator forNullPointerException
- if the list is nullpublic boolean hasNext()
public E next()
public int nextIndex()
nextIndex
in interface ListIterator<E>
public boolean hasPrevious()
hasPrevious
in interface ListIterator<E>
hasPrevious
in interface OrderedIterator<E>
public E previous()
previous
in interface ListIterator<E>
previous
in interface OrderedIterator<E>
public int previousIndex()
previousIndex
in interface ListIterator<E>
public void remove()
remove
in interface Iterator<E>
remove
in interface ListIterator<E>
UnsupportedOperationException
- if the list is unmodifiableIllegalStateException
- if there is no element to removepublic void set(E obj)
set
in interface ListIterator<E>
obj
- the object to setUnsupportedOperationException
- if the list is unmodifiableIllegalStateException
- if the iterator is not in a valid state for setpublic void add(E obj)
add
in interface ListIterator<E>
obj
- the object to addUnsupportedOperationException
- if the list is unmodifiableIllegalStateException
- if the iterator is not in a valid state for setpublic void reset()
reset
in interface ResettableIterator<E>
Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.