tango.util.collection.iterator.InterleavingIterator

class InterleavingIterator(T) : Iterator!(T) #
InterleavingIterators allow you to combine the elements of two different enumerations as if they were one enumeration before they are seen by their `consumers'. This sometimes allows you to avoid having to use a Collection object to temporarily combine two sets of Collection elements() that need to be collected together for common processing.

The elements are revealed (via get()) in a purely interleaved fashion, alternating between the first and second enumerations unless one of them has been exhausted, in which case all remaining elements of the other are revealed until it too is exhausted.

InterleavingIterators work as wrappers around other Iterators. To build one, you need two existing Iterators. For example, if you want to process together the elements of two Collections a and b, you could write something of the form:

 Iterator items = InterleavingIterator(a.elements(), b.elements());
 while (items.more()) 
  doSomethingWith(items.get());
 

Author:

Doug Lea @version 0.93

For an introduction to this package see Overview .

Iterator!(T) fst_ [private] #
The first source; nulled out once it is exhausted
Iterator!(T) snd_ [private] #
The second source; nulled out once it is exhausted
Iterator!(T) current_ [private] #
The source currently being used
this(Iterator!(T) fst, Iterator!(T) snd) [public] #
Make an enumeration interleaving elements from fst and snd
bool more() [public, final] #
Implements tango.util.collection.model.Iterator.more
T get() [public, final] #
Implements tango.util.collection.model.Iterator.get.
void flip() [private, final] #
Alternate sources