java.lang.Object | |
↳ | org.apache.commons.collections.iterators.IteratorChain |
An IteratorChain is an Iterator that wraps a number of Iterators.
This class makes multiple iterators look like one to the caller When any method from the Iterator interface is called, the IteratorChain will delegate to a single underlying Iterator. The IteratorChain will invoke the Iterators in sequence until all Iterators are exhausted.
Under many circumstances, linking Iterators together in this manner is more efficient (and convenient) than reading out the contents of each Iterator into a List and creating a new Iterator.
Calling a method that adds new Iteratorafter a method in the Iterator interface has been called will result in an UnsupportedOperationException. Subclasses should take care to not alter the underlying List of Iterators.
NOTE: As from version 3.0, the IteratorChain may contain no iterators. In this case the class will function as an empty iterator.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
currentIterator | The current iterator | ||||||||||
currentIteratorIndex | The index of the current iterator | ||||||||||
isLocked | ComparatorChain is "locked" after the first time compare(Object,Object) is called | ||||||||||
iteratorChain | The chain of iterators | ||||||||||
lastUsedIterator | The "last used" Iterator is the Iterator upon which next() or hasNext() was most recently called used for the remove() operation only |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct an IteratorChain with no Iterators.
| |||||||||||
Construct an IteratorChain with a single Iterator.
| |||||||||||
Constructs a new
IteratorChain over the two
given iterators. | |||||||||||
Constructs a new
IteratorChain over the array
of iterators. | |||||||||||
Constructs a new
IteratorChain over the collection
of iterators. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add an Iterator to the end of the chain
| |||||||||||
Get the list of Iterators (unmodifiable)
| |||||||||||
Return true if any Iterator in the IteratorChain has a remaining element.
| |||||||||||
Determine if modifications can still be made to the IteratorChain.
| |||||||||||
Returns the next Object of the current Iterator
| |||||||||||
Removes from the underlying collection the last element
returned by the Iterator.
| |||||||||||
Set the Iterator at the given index
| |||||||||||
Number of Iterators in the current IteratorChain.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Updates the current iterator field to ensure that the current Iterator
is not exhausted
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Iterator
|
The index of the current iterator
ComparatorChain is "locked" after the first time compare(Object,Object) is called
The "last used" Iterator is the Iterator upon which next() or hasNext() was most recently called used for the remove() operation only
Construct an IteratorChain with no Iterators.
You will normally use addIterator(Iterator)
to add
some iterators after using this constructor.
Construct an IteratorChain with a single Iterator.
iterator | first Iterator in the IteratorChain |
---|
NullPointerException | if the iterator is null |
---|
Constructs a new IteratorChain
over the two
given iterators.
a | the first child iterator |
---|---|
b | the second child iterator |
NullPointerException | if either iterator is null |
---|
Constructs a new IteratorChain
over the array
of iterators.
iterators | the array of iterators |
---|
NullPointerException | if iterators array is or contains null |
---|
Constructs a new IteratorChain
over the collection
of iterators.
iterators | the collection of iterators |
---|
NullPointerException | if iterators collection is or contains null |
---|---|
ClassCastException | if iterators collection doesn't contain an iterator |
Add an Iterator to the end of the chain
iterator | Iterator to add |
---|
IllegalStateException | if I've already started iterating |
---|---|
NullPointerException | if the iterator is null |
Get the list of Iterators (unmodifiable)
Return true if any Iterator in the IteratorChain has a remaining element.
Determine if modifications can still be made to the IteratorChain. IteratorChains cannot be modified once they have executed a method from the Iterator interface.
Returns the next Object of the current Iterator
NoSuchElementException | if all the Iterators are exhausted |
---|
Removes from the underlying collection the last element returned by the Iterator. As with next() and hasNext(), this method calls remove() on the underlying Iterator. Therefore, this method may throw an UnsupportedOperationException if the underlying Iterator does not support this method.
UnsupportedOperationException | if the remove operator is not supported by the underlying Iterator |
---|---|
IllegalStateException | if the next method has not yet been called, or the remove method has already been called after the last call to the next method. |
Set the Iterator at the given index
index | index of the Iterator to replace |
---|---|
iterator | Iterator to place at the given index |
IndexOutOfBoundsException | if index < 0 or index > size() |
---|---|
IllegalStateException | if I've already started iterating |
NullPointerException | if the iterator is null |
Number of Iterators in the current IteratorChain.
Updates the current iterator field to ensure that the current Iterator is not exhausted