cucumber.io
Class FlatteningIterator

java.lang.Object
  extended by cucumber.io.FlatteningIterator
All Implemented Interfaces:
java.util.Iterator

public class FlatteningIterator
extends java.lang.Object
implements java.util.Iterator

An iterator that 'flattens out' collections, iterators, arrays, etc.

That is it will iterate out their contents in order, descending into any iterators, iterables or arrays provided to it.

An example (not valid Java for brevity - some type declarations are ommitted):

new FlattingIterator({1, 2, 3}, {{1, 2}, {3}}, new ArrayList({1, 2, 3}))

Will iterate through the sequence 1, 2, 3, 1, 2, 3, 1, 2, 3.

Note that this implements a non-generic version of the Iterator interface so may be cast appropriately - it's very hard to give this class an appropriate generic type.

Author:
david

Constructor Summary
FlatteningIterator(java.lang.Object... objects)
           
 
Method Summary
 boolean hasNext()
          Returns if there are any objects left to iterate over.
 java.lang.Object next()
          Returns the next element in our iteration, throwing a NoSuchElementException if none is found.
 void push(java.util.Iterator<?> iterator)
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlatteningIterator

public FlatteningIterator(java.lang.Object... objects)
Method Detail

push

public void push(java.util.Iterator<?> iterator)

remove

public void remove()
Specified by:
remove in interface java.util.Iterator

next

public java.lang.Object next()
Returns the next element in our iteration, throwing a NoSuchElementException if none is found.

Specified by:
next in interface java.util.Iterator

hasNext

public boolean hasNext()
Returns if there are any objects left to iterate over. This method can change the internal state of the object when it is called, but repeated calls to it will not have any additional side effects.

Specified by:
hasNext in interface java.util.Iterator