Class ReverseListIterator
java.lang.Object
org.apache.commons.collections.iterators.ReverseListIterator
- All Implemented Interfaces:
Iterator,ListIterator,ResettableIterator,ResettableListIterator
@Deprecated(since="2021-04-30")
public class ReverseListIterator
extends Object
implements ResettableListIterator
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
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.
- Since:
- Commons Collections 3.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.Adds a new element to the list between the next and previous elements.booleanhasNext()Deprecated.Checks whether there is another element.booleanDeprecated.Checks whether there is a previous element.next()Deprecated.Gets the next element.intDeprecated.Gets the index of the next element.previous()Deprecated.Gets the previous element.intDeprecated.Gets the index of the previous element.voidremove()Deprecated.Removes the last returned element.voidreset()Deprecated.Resets the iterator back to the start (which is the end of the list as this is a reversed iterator)voidDeprecated.Replaces the last returned element.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
ReverseListIterator
Deprecated.Constructor that wraps a list.- Parameters:
list- the list to create a reversed iterator for- Throws:
NullPointerException- if the list is null
-
-
Method Details
-
hasNext
public boolean hasNext()Deprecated.Checks whether there is another element.- Specified by:
hasNextin interfaceIterator- Specified by:
hasNextin interfaceListIterator- Returns:
- true if there is another element
-
next
Deprecated.Gets the next element. The next element is the previous in the list.- Specified by:
nextin interfaceIterator- Specified by:
nextin interfaceListIterator- Returns:
- the next element in the iterator
-
nextIndex
public int nextIndex()Deprecated.Gets the index of the next element.- Specified by:
nextIndexin interfaceListIterator- Returns:
- the index of the next element in the iterator
-
hasPrevious
public boolean hasPrevious()Deprecated.Checks whether there is a previous element.- Specified by:
hasPreviousin interfaceListIterator- Returns:
- true if there is a previous element
-
previous
Deprecated.Gets the previous element. The next element is the previous in the list.- Specified by:
previousin interfaceListIterator- Returns:
- the previous element in the iterator
-
previousIndex
public int previousIndex()Deprecated.Gets the index of the previous element.- Specified by:
previousIndexin interfaceListIterator- Returns:
- the index of the previous element in the iterator
-
remove
public void remove()Deprecated.Removes the last returned element.- Specified by:
removein interfaceIterator- Specified by:
removein interfaceListIterator- Throws:
UnsupportedOperationException- if the list is unmodifiableIllegalStateException- if there is no element to remove
-
set
Deprecated.Replaces the last returned element.- Specified by:
setin interfaceListIterator- Parameters:
obj- the object to set- Throws:
UnsupportedOperationException- if the list is unmodifiableIllegalStateException- if the iterator is not in a valid state for set
-
add
Deprecated.Adds a new element to the list between the next and previous elements.- Specified by:
addin interfaceListIterator- Parameters:
obj- the object to add- Throws:
UnsupportedOperationException- if the list is unmodifiableIllegalStateException- if the iterator is not in a valid state for set
-
reset
public void reset()Deprecated.Resets the iterator back to the start (which is the end of the list as this is a reversed iterator)- Specified by:
resetin interfaceResettableIterator- Specified by:
resetin interfaceResettableListIterator
-