Class ReverseListIterator
- java.lang.Object
-
- org.apache.commons.collections.iterators.ReverseListIterator
-
- All Implemented Interfaces:
java.util.Iterator
,java.util.ListIterator
,ResettableIterator
,ResettableListIterator
@Deprecated(since="2021-04-30") public class ReverseListIterator extends java.lang.Object implements ResettableListIterator
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.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. ThehasNext()
method works in concert with thenext()
method as expected. However, thenextIndex()
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 Constructor Description ReverseListIterator(java.util.List list)
Deprecated.Constructor that wraps a list.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(java.lang.Object obj)
Deprecated.Adds a new element to the list between the next and previous elements.boolean
hasNext()
Deprecated.Checks whether there is another element.boolean
hasPrevious()
Deprecated.Checks whether there is a previous element.java.lang.Object
next()
Deprecated.Gets the next element.int
nextIndex()
Deprecated.Gets the index of the next element.java.lang.Object
previous()
Deprecated.Gets the previous element.int
previousIndex()
Deprecated.Gets the index of the previous element.void
remove()
Deprecated.Removes the last returned element.void
reset()
Deprecated.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)
Deprecated.Replaces the last returned element.
-
-
-
Method Detail
-
hasNext
public boolean hasNext()
Deprecated.Checks whether there is another element.- Specified by:
hasNext
in interfacejava.util.Iterator
- Specified by:
hasNext
in interfacejava.util.ListIterator
- Returns:
- true if there is another element
-
next
public java.lang.Object next()
Deprecated.Gets the next element. The next element is the previous in the list.- Specified by:
next
in interfacejava.util.Iterator
- Specified by:
next
in interfacejava.util.ListIterator
- Returns:
- the next element in the iterator
-
nextIndex
public int nextIndex()
Deprecated.Gets the index of the next element.- Specified by:
nextIndex
in interfacejava.util.ListIterator
- Returns:
- the index of the next element in the iterator
-
hasPrevious
public boolean hasPrevious()
Deprecated.Checks whether there is a previous element.- Specified by:
hasPrevious
in interfacejava.util.ListIterator
- Returns:
- true if there is a previous element
-
previous
public java.lang.Object previous()
Deprecated.Gets the previous element. The next element is the previous in the list.- Specified by:
previous
in interfacejava.util.ListIterator
- Returns:
- the previous element in the iterator
-
previousIndex
public int previousIndex()
Deprecated.Gets the index of the previous element.- Specified by:
previousIndex
in interfacejava.util.ListIterator
- Returns:
- the index of the previous element in the iterator
-
remove
public void remove()
Deprecated.Removes the last returned element.- Specified by:
remove
in interfacejava.util.Iterator
- Specified by:
remove
in interfacejava.util.ListIterator
- Throws:
java.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- if there is no element to remove
-
set
public void set(java.lang.Object obj)
Deprecated.Replaces the last returned element.- Specified by:
set
in interfacejava.util.ListIterator
- Parameters:
obj
- the object to set- Throws:
java.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- if the iterator is not in a valid state for set
-
add
public void add(java.lang.Object obj)
Deprecated.Adds a new element to the list between the next and previous elements.- Specified by:
add
in interfacejava.util.ListIterator
- Parameters:
obj
- the object to add- Throws:
java.lang.UnsupportedOperationException
- if the list is unmodifiablejava.lang.IllegalStateException
- 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:
reset
in interfaceResettableIterator
- Specified by:
reset
in interfaceResettableListIterator
-
-