|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections.iterators.ReverseListIterator
public class ReverseListIterator
Iterates backwards through a List, starting with the last element and continuing to the first. This is useful for looping around a list in reverse order without needing to actually reverse the list.
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 Summary | |
|---|---|
ReverseListIterator(java.util.List list)
Constructor that wraps a list. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ReverseListIterator(java.util.List list)
list - the list to create a reversed iterator for
java.lang.NullPointerException - if the list is null| Method Detail |
|---|
public boolean hasNext()
hasNext in interface java.util.IteratorhasNext in interface java.util.ListIteratorpublic java.lang.Object next()
next in interface java.util.Iteratornext in interface java.util.ListIteratorpublic int nextIndex()
nextIndex in interface java.util.ListIteratorpublic boolean hasPrevious()
hasPrevious in interface java.util.ListIteratorpublic java.lang.Object previous()
previous in interface java.util.ListIteratorpublic int previousIndex()
previousIndex in interface java.util.ListIteratorpublic void remove()
remove in interface java.util.Iteratorremove in interface java.util.ListIteratorjava.lang.UnsupportedOperationException - if the list is unmodifiable
java.lang.IllegalStateException - if there is no element to removepublic void set(java.lang.Object obj)
set in interface java.util.ListIteratorobj - the object to set
java.lang.UnsupportedOperationException - if the list is unmodifiable
java.lang.IllegalStateException - if the iterator is not in a valid state for setpublic void add(java.lang.Object obj)
add in interface java.util.ListIteratorobj - the object to add
java.lang.UnsupportedOperationException - if the list is unmodifiable
java.lang.IllegalStateException - if the iterator is not in a valid state for setpublic void reset()
reset in interface ResettableIteratorreset in interface ResettableListIterator
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||