org.apache.commons.collections.iterators
public class LoopingListIterator extends Object implements ResettableListIterator
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.
Since: Commons Collections 3.2
Version: $Revision: 405920 $ $Date: 2006-05-12 23:48:04 +0100 (Fri, 12 May 2006) $
Constructor Summary | |
---|---|
LoopingListIterator(List list)
Constructor that wraps a list.
|
Method Summary | |
---|---|
void | add(Object obj)
Inserts the specified element into the underlying list.
|
boolean | hasNext()
Returns whether this iterator has any more elements.
|
boolean | hasPrevious()
Returns whether this iterator has any more previous elements.
|
Object | next()
Returns the next object in the list.
|
int | nextIndex()
Returns the index of the element that would be returned by a
subsequent call to LoopingListIterator.
|
Object | previous()
Returns the previous object in the list.
|
int | previousIndex()
Returns the index of the element that would be returned by a
subsequent call to LoopingListIterator.
|
void | remove()
Removes the previously retrieved item from the underlying list.
|
void | reset()
Resets the iterator back to the start of the list. |
void | set(Object obj)
Replaces the last element that was returned by LoopingListIterator or
LoopingListIterator.
|
int | size()
Gets the size of the list underlying the iterator.
|
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.
Parameters: list the list to wrap
Throws: NullPointerException if the list it null
The element is inserted before the next element that would be returned by LoopingListIterator, if any, and after the next element that would be returned by LoopingListIterator, if any.
This feature is only supported if the underlying list's List#listIterator method returns an implementation that supports it.
Parameters: obj the element to insert
Throws: UnsupportedOperationException if the add method is not supported by the iterator implementation of the underlying list
Returns false only if the list originally had zero elements, or
all elements have been removed
.
Returns: true
if there are more elements
Returns false only if the list originally had zero elements, or
all elements have been removed
.
Returns: true
if there are more elements
If at the end of the list, returns the first element.
Returns: the object after the last element returned
Throws: NoSuchElementException if there are no elements in the list
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.
Returns: the index of the element that would be returned if next() were called
Throws: NoSuchElementException if there are no elements 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.
Returns: the object before the last element returned
Throws: NoSuchElementException if there are no elements in the list
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.
Returns: the index of the element that would be returned if previous() were called
Throws: NoSuchElementException if there are no elements in the list
This feature is only supported if the underlying list's
List#iterator iterator
method returns an implementation
that supports it.
This method can only be called after at least one LoopingListIterator or LoopingListIterator method call. After a removal, the remove method may not be called again until another LoopingListIterator or LoopingListIterator has been performed. If the LoopingListIterator is called, then remove may not be called until LoopingListIterator or LoopingListIterator is called again.
Throws: UnsupportedOperationException if the remove method is not supported by the iterator implementation of the underlying list
This feature is only supported if the underlying list's List#listIterator method returns an implementation that supports it.
Parameters: obj the element with which to replace the last element returned
Throws: UnsupportedOperationException if the set method is not supported by the iterator implementation of the underlying list
Returns: the current list size