public class LoopingIterator extends java.lang.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.
Constructor and Description |
---|
LoopingIterator(java.util.Collection coll)
Constructor that wraps a collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Has the iterator any more elements.
|
java.lang.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.
|
public LoopingIterator(java.util.Collection coll)
There is no way to reset an Iterator instance without recreating it from the original source, so the Collection must be passed in.
coll
- the collection to wrapjava.lang.NullPointerException
- if the collection is nullpublic boolean hasNext()
Returns false only if the collection originally had zero elements, or
all the elements have been removed
.
hasNext
in interface java.util.Iterator
true
if there are more elementspublic java.lang.Object next()
If at the end of the collection, return the first element.
next
in interface java.util.Iterator
java.util.NoSuchElementException
- if there are no elements
at all. Use hasNext()
to avoid this error.public void remove()
This feature is only supported if the underlying collection's
iterator
method returns an implementation
that supports it.
This method can only be called after at least one next()
method call.
After a removal, the remove method may not be called again until another
next has been performed. If the reset()
is called, then remove may
not be called until next()
is called again.
remove
in interface java.util.Iterator
public void reset()
reset
in interface ResettableIterator
public int size()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"