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 {@link #nextIterator(int)} which has to be overridden bysub-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 {@link Iterator#hasNext()} method returns false,{@link #nextIterator(int)} will be called to obtain another iterator, and so onuntil {@link #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.
@since 4.0
@version $Id: LazyIteratorChain.java 1482073 2013-05-13 20:09:40Z tn $