java.lang.Object | |
↳ | org.apache.commons.collections.iterators.LoopingListIterator |
A ListIterator that restarts when it reaches the end or when it reaches the beginning.
The iterator will loop continuously around the provided list,
unless there are no elements in the collection to begin with, or
all of the elements have been removed
.
Concurrent modifications are not directly supported, and for most collection implementations will throw a ConcurrentModificationException.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that wraps a list.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Inserts the specified element into the underlying list.
| |||||||||||
Returns whether this iterator has any more elements.
| |||||||||||
Returns whether this iterator has any more previous elements.
| |||||||||||
Returns the next object in the list.
| |||||||||||
Returns the index of the element that would be returned by a
subsequent call to
next() . | |||||||||||
Returns the previous object in the list.
| |||||||||||
Returns the index of the element that would be returned by a
subsequent call to
previous() . | |||||||||||
Removes the previously retrieved item from the underlying list.
| |||||||||||
Resets the iterator back to the start of the list.
| |||||||||||
Replaces the last element that was returned by
next() or
previous() . | |||||||||||
Gets the size of the list underlying the iterator.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Iterator
| |||||||||||
From interface
java.util.ListIterator
| |||||||||||
From interface
org.apache.commons.collections.ResettableIterator
| |||||||||||
From interface
org.apache.commons.collections.ResettableListIterator
|
Constructor that wraps a list.
There is no way to reset a ListIterator instance without recreating it from the original source, so the List must be passed in and a reference to it held.
list | the list to wrap |
---|
NullPointerException | if the list it null |
---|
Inserts the specified element into the underlying list.
The element is inserted before the next element that would be
returned by next()
, if any, and after the next element
that would be returned by previous()
, if any.
This feature is only supported if the underlying list's
listIterator()
method returns an implementation
that supports it.
obj | the element to insert |
---|
UnsupportedOperationException | if the add method is not supported by the iterator implementation of the underlying list |
---|
Returns whether this iterator has any more elements.
Returns false only if the list originally had zero elements, or
all elements have been removed
.
true
if there are more elements
Returns whether this iterator has any more previous elements.
Returns false only if the list originally had zero elements, or
all elements have been removed
.
true
if there are more elements
Returns the next object in the list.
If at the end of the list, returns the first element.
NoSuchElementException | if there are no elements in the list |
---|
Returns the index of the element that would be returned by a
subsequent call to next()
.
As would be expected, if the iterator is at the physical end of the underlying list, 0 is returned, signifying the beginning of the list.
NoSuchElementException | if there are no elements in the list |
---|
Returns the previous object in the list.
If at the beginning of the list, return the last element. Note that in this case, traversal to find that element takes linear time.
NoSuchElementException | if there are no elements in the list |
---|
Returns the index of the element that would be returned by a
subsequent call to previous()
.
As would be expected, if at the iterator is at the physical beginning of the underlying list, the list's size minus one is returned, signifying the end of the list.
NoSuchElementException | if there are no elements in the list |
---|
Removes the previously retrieved item from the underlying list.
This feature is only supported if the underlying list's
iterator
method returns an implementation
that supports it.
This method can only be called after at least one next()
or previous()
method call. After a removal, the remove
method may not be called again until another next()
or
previous()
has been performed. If the reset()
is
called, then remove may not be called until next()
or
previous()
is called again.
UnsupportedOperationException | if the remove method is not supported by the iterator implementation of the underlying list |
---|
Resets the iterator back to the start of the list.
Replaces the last element that was returned by next()
or
previous()
.
This feature is only supported if the underlying list's
listIterator()
method returns an implementation
that supports it.
obj | the element with which to replace the last element returned |
---|
UnsupportedOperationException | if the set method is not supported by the iterator implementation of the underlying list |
---|
Gets the size of the list underlying the iterator.