edu.rice.cs.plt.iter
Class CartesianIterator<T1,T2,R>

java.lang.Object
  extended by edu.rice.cs.plt.iter.ReadOnlyIterator<R>
      extended by edu.rice.cs.plt.iter.CartesianIterator<T1,T2,R>
All Implemented Interfaces:
Composite, Iterator<R>

public class CartesianIterator<T1,T2,R>
extends ReadOnlyIterator<R>
implements Composite

Enumerates the elements of a cartesian (or cross) product. For each element in the iterator left, the result of a lambda combiner, applied to that element and each of the elements of the iterable right, is produced. Since iteration of right occurs in an "inner loop," right must be finite (at least for most interesting results...), and is an Iterable rather than an Iterator. The combiner function is used, rather than simply producing Pairs, in order to provide a greater degree of flexibility. Iterator.remove() is not supported.


Constructor Summary
CartesianIterator(Iterator<? extends T1> left, Iterable<? extends T2> right, Lambda2<? super T1,? super T2,? extends R> combiner)
           
 
Method Summary
 int compositeHeight()
          Get the maximum path length from this node to a leaf.
 int compositeSize()
          Get the number of nodes in the tree rooted at this node.
 boolean hasNext()
           
static
<T1,T2,R> CartesianIterator<T1,T2,R>
make(Iterator<? extends T1> left, Iterable<? extends T2> right, Lambda2<? super T1,? super T2,? extends R> combiner)
          Call the constructor (allows the type arguments to be inferred)
 R next()
           
 
Methods inherited from class edu.rice.cs.plt.iter.ReadOnlyIterator
remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CartesianIterator

public CartesianIterator(Iterator<? extends T1> left,
                         Iterable<? extends T2> right,
                         Lambda2<? super T1,? super T2,? extends R> combiner)
Method Detail

compositeHeight

public int compositeHeight()
Description copied from interface: Composite
Get the maximum path length from this node to a leaf.

Specified by:
compositeHeight in interface Composite

compositeSize

public int compositeSize()
Description copied from interface: Composite
Get the number of nodes in the tree rooted at this node. Always 1 or greater.

Specified by:
compositeSize in interface Composite

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<R>

next

public R next()
Specified by:
next in interface Iterator<R>

make

public static <T1,T2,R> CartesianIterator<T1,T2,R> make(Iterator<? extends T1> left,
                                                        Iterable<? extends T2> right,
                                                        Lambda2<? super T1,? super T2,? extends R> combiner)
Call the constructor (allows the type arguments to be inferred)