public class ReverseListIterator extends java.lang.Object implements ResettableListIterator
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(java.util.List list)
Constructor that wraps a list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Object 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.
|
java.lang.Object |
next()
Gets the next element.
|
int |
nextIndex()
Gets the index of the next element.
|
java.lang.Object |
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(java.lang.Object obj)
Replaces the last returned element.
|
public ReverseListIterator(java.util.List list)
list
- the list to create a reversed iterator forjava.lang.NullPointerException
- if the list is nullpublic boolean hasNext()
hasNext
in interface java.util.Iterator
hasNext
in interface java.util.ListIterator
public java.lang.Object next()
next
in interface java.util.Iterator
next
in interface java.util.ListIterator
public int nextIndex()
nextIndex
in interface java.util.ListIterator
public boolean hasPrevious()
hasPrevious
in interface java.util.ListIterator
public java.lang.Object previous()
previous
in interface java.util.ListIterator
public int previousIndex()
previousIndex
in interface java.util.ListIterator
public void remove()
remove
in interface java.util.Iterator
remove
in interface java.util.ListIterator
java.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- if there is no element to removepublic void set(java.lang.Object obj)
set
in interface java.util.ListIterator
obj
- the object to setjava.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- if the iterator is not in a valid state for setpublic void add(java.lang.Object obj)
add
in interface java.util.ListIterator
obj
- the object to addjava.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- if the iterator is not in a valid state for setpublic void reset()
reset
in interface ResettableIterator
reset
in interface ResettableListIterator
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"