OuterIterator

Started by chinmay.sahoo, 05-18-2016, 00:11:57

Previous topic - Next topic

chinmay.sahooTopic starter

Sometimes it is advantageous to enclose one or more iterators in another iterator, such as when you want to sequentially iterate several different iterators (which you can do with the AppendIterator, as discussed later in this chapter). For this purpose, you can use the OuterIterator interface.

The definition of the OuterIterator interface is as follows:

Quoteinterface OuterIterator extends Iterator {
function getInnerIterator();
}

This interface differs from the IteratorAggregate interface in that it extends the Iterator interface; thus, any class implementing it must also implement all the Iterator-defined methods.

The getInnerIterator() method should return the currently iterating iterator. For example,when two or more iterators are appended together and iterated one after the other, the getInnerIterator() method must return the first iterator, then the second, and so on, as the
array pointer is increased by the next() method.

This interface forms the base interface for several more specialized iterators, including AppendIterator, CachingIterator, FilterIterator, IteratorIterator, LimitIterator, and RecursiveIteratorIterator