|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.collections.iterators.IteratorChain
An IteratorChain is an Iterator that wraps one or more Iterators. When any method from the Iterator interface is called, the IteratorChain will proxy to a single underlying Iterator. The IteratorChain will invoke the Iterators in sequence until all Iterators are exhausted completely.
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.
Field Summary | |
protected Iterator |
currentIterator
|
protected int |
currentIteratorIndex
|
protected boolean |
isLocked
|
protected List |
iteratorChain
|
protected Iterator |
lastUsedIterator
|
Constructor Summary | |
IteratorChain()
Construct an IteratorChain with no Iterators. |
|
IteratorChain(Collection iterators)
Constructs a new IteratorChain over the collection
of iterators. |
|
IteratorChain(Iterator iterator)
Construct an IteratorChain with a single Iterator. |
|
IteratorChain(Iterator[] iterators)
Constructs a new IteratorChain over the array
of iterators. |
|
IteratorChain(Iterator a,
Iterator b)
Constructs a new IteratorChain over the two
given iterators. |
Method Summary | |
void |
addIterator(Iterator iterator)
Add an Iterator to the end of the chain |
List |
getIterators()
Get the list of Iterators (unmodifiable) |
boolean |
hasNext()
Return true if any Iterator in the IteratorChain has a remaining element. |
boolean |
isLocked()
Determine if modifications can still be made to the IteratorChain. |
Object |
next()
Returns the next Object of the current Iterator |
void |
remove()
Removes from the underlying collection the last element returned by the Iterator. |
void |
setIterator(int index,
Iterator iterator)
Set the Iterator at the given index |
int |
size()
Number of Iterators in the current IteratorChain. |
protected void |
updateCurrentIterator()
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected final List iteratorChain
protected int currentIteratorIndex
protected Iterator currentIterator
protected Iterator lastUsedIterator
protected boolean isLocked
Constructor Detail |
public IteratorChain()
public IteratorChain(Iterator iterator)
iterator
- first Iterator in the IteratorChainpublic IteratorChain(Iterator a, Iterator b)
IteratorChain
over the two
given iterators.a
- the first child iteratorb
- the second child iteratorpublic IteratorChain(Iterator[] iterators)
IteratorChain
over the array
of iterators.iterators
- the array of iteratorspublic IteratorChain(Collection iterators)
IteratorChain
over the collection
of iterators.iterators
- the collection of iteratorsMethod Detail |
public void addIterator(Iterator iterator)
iterator
- Iterator to addpublic void setIterator(int index, Iterator iterator) throws IndexOutOfBoundsException
index
- index of the Iterator to replaceiterator
- Iterator to place at the given indexpublic List getIterators()
public int size()
public boolean isLocked()
protected void updateCurrentIterator()
public boolean hasNext() throws UnsupportedOperationException
public Object next() throws NoSuchElementException, UnsupportedOperationException
public void remove() throws UnsupportedOperationException, IllegalStateException
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |