⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.iterators

Class LoopingIterator

java.lang.Object
|
+--org.apache.commons.collections.iterators.LoopingIterator

All Implemented Interfaces:
ResettableIterator


public class LoopingIterator
extends java.lang.Object
implements 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 remove removed.

Concurrent modifications are not directly supported, and for most collection implementations will throw a ConcurrentModificationException.

Since:
Commons Collections 3.0
Authors:
Stephen Colebourne

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.

Constructor Details

LoopingIterator

public LoopingIterator(Collection 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 - the collection to wrap
Throws:
- if the collection is null

Method Details

hasNext

public boolean hasNext()

Has the iterator any more elements.

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

Returns:
true if there are more elements

next

public Object next()

Returns the next object in the collection.

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

Throws:
- if there are no elements at all.

remove

public void remove()


reset

public void reset()

Resets the iterator back to the start of the collection.


size

public int size()

Gets the size of the collection underlying the iterator.

Returns:
the current collection size