|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections4.iterators.LazyIteratorChain<E>
public abstract class LazyIteratorChain<E>
An LazyIteratorChain is an Iterator that wraps a number of Iterators in a lazy manner.
This class makes multiple iterators look like one to the caller. When any method from the Iterator interface is called, the LazyIteratorChain will delegate to a single underlying Iterator. The LazyIteratorChain will invoke the Iterators in sequence until all Iterators are exhausted.
The Iterators are provided by nextIterator(int)
which has to be overridden by
sub-classes and allows to lazily create the Iterators as they are accessed:
return new LazyIteratorChain<String>() { protected Iterator<String> nextIterator(int count) { return count == 1 ? Arrays.asList("foo", "bar").iterator() : null; } };
Once the inner Iterator's Iterator.hasNext()
method returns false,
nextIterator(int)
will be called to obtain another iterator, and so on
until nextIterator(int)
returns null, indicating that the chain is exhausted.
NOTE: The LazyIteratorChain may contain no iterators. In this case the class will function as an empty iterator.
Constructor Summary | |
---|---|
LazyIteratorChain()
|
Method Summary | |
---|---|
boolean |
hasNext()
Return true if any Iterator in the chain has a remaining element. |
E |
next()
Returns the next element of the current Iterator |
protected abstract Iterator<? extends E> |
nextIterator(int count)
Gets the next iterator after the previous one has been exhausted. |
void |
remove()
Removes from the underlying collection the last element returned by the Iterator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LazyIteratorChain()
Method Detail |
---|
protected abstract Iterator<? extends E> nextIterator(int count)
This method MUST return null when there are no more iterators.
count
- the number of time this method has been called (starts with 1)
public boolean hasNext()
hasNext
in interface Iterator<E>
public E next()
next
in interface Iterator<E>
NoSuchElementException
- if all the Iterators are exhaustedpublic void remove()
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.
remove
in interface Iterator<E>
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |