org.apache.commons.collections.iterators
public class LoopingIterator extends Object implements ResettableIterator
The iterator will loop continuously around the provided elements, unless
there are no elements in the collection to begin with, or all the elements
have been removed
.
Concurrent modifications are not directly supported, and for most collection implementations will throw a ConcurrentModificationException.
Since: Commons Collections 3.0
Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
Constructor Summary | |
---|---|
LoopingIterator(Collection coll)
Constructor that wraps a collection.
|
Method Summary | |
---|---|
boolean | hasNext()
Has the iterator any more elements.
|
Object | next()
Returns the next object in the collection.
|
void | remove()
Removes the previously retrieved item from the underlying collection.
|
void | reset()
Resets the iterator back to the start of the collection. |
int | size()
Gets the size of the collection underlying the iterator.
|
There is no way to reset an Iterator instance without recreating it from the original source, so the Collection must be passed in.
Parameters: coll the collection to wrap
Throws: NullPointerException if the collection is null
Returns false only if the collection originally had zero elements, or
all the elements have been removed
.
Returns: true
if there are more elements
If at the end of the collection, return the first element.
Throws: NoSuchElementException if there are no elements at all. Use LoopingIterator to avoid this error.
This feature is only supported if the underlying collection's
Collection#iterator iterator
method returns an implementation
that supports it.
This method can only be called after at least one LoopingIterator method call. After a removal, the remove method may not be called again until another next has been performed. If the LoopingIterator is called, then remove may not be called until LoopingIterator is called again.
Returns: the current collection size