Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class LoopingIterator<E>

extends Object
implements ResettableIterator<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.ResettableIterator, java.util.Iterator
Imports
java.util.Collection, .Iterator, .NoSuchElementException, org.apache.commons.collections4.ResettableIterator

An Iterator that restarts when it reaches the end.

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
3.0

Field Summary

Modifier and TypeField and Description
private final Collection<? extends E>
collection

The collection to base the iterator on

private Iterator<? extends E>
iterator

The current iterator

Constructor Summary

AccessConstructor and Description
public
LoopingIterator(final Collection<? extends E>
the collection to wrap
coll
)

Constructor that wraps a collection.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if there are more elements
hasNext
()

Implements java.util.Iterator.hasNext.

Has the iterator any more elements.
public E

Returns:

the next object
next
()

Implements java.util.Iterator.next.

Returns the next object in the collection.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes the previously retrieved item from the underlying collection.
public void
reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the iterator back to the start of the collection.
public int

Returns:

the current collection size
size
()

Gets the size of the collection underlying the iterator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

collectionback to summary
private final Collection<? extends E> collection

The collection to base the iterator on

iteratorback to summary
private Iterator<? extends E> iterator

The current iterator

Constructor Detail

LoopingIteratorback to summary
public LoopingIterator(final Collection<? extends E> coll)

Constructor that wraps a collection.

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:Collection<? extends E>

the collection to wrap

Exceptions
NullPointerException:
if the collection is null

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Has the iterator any more elements.

Returns false only if the collection originally had zero elements, or all the elements have been removed.

Returns:boolean

true if there are more elements

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Returns the next object in the collection.

If at the end of the collection, return the first element.

Returns:E

the next object

Annotations
@Override
Exceptions
NoSuchElementException:
if there are no elements at all. Use hasNext to avoid this error.
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Removes the previously retrieved item from the underlying collection.

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.

Annotations
@Override
resetback to summary
public void reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the iterator back to the start of the collection.

Annotations
@Override
sizeback to summary
public int size()

Gets the size of the collection underlying the iterator.

Returns:int

the current collection size