common
Class AddedTupleIterator

java.lang.Object
  extended by common.AddedTupleIterator
All Implemented Interfaces:
java.util.Iterator

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

Class for iterating over tuples that are added to the Cartesian product A_1 x A_2 x ... x A_n when the original collections A_1, ..., A_n are augmented with additional collections B_1, ..., B_n. In mathematical notation (with "u" for the union symbol), the iteration is over:

((A_1 u B_1) x ... x (A_n u B_n)) - (A_1 x ... x A_n)
We assume that A_i and B_i are disjoint.

The trick is to partition the "added" tuples according to the index where we first encounter an added element. The set of tuples where the first added element occurs at index i is the Cartesian product:

A_1 x ... x A_{i-1} x B_i x (A_{i+1} u B_{i+1}) x ... x (A_n u B_n)
So overall, we just need to iterate over the (disjoint) union of such Cartesian products for i = 1 to n.


Constructor Summary
AddedTupleIterator(java.util.List orig, java.util.List added)
          Creates a new iterator over tuples that are added to the Cartesian product when the collections in orig are augmented with the corresponding collections in added.
 
Method Summary
 boolean hasNext()
           
 java.lang.Object next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddedTupleIterator

public AddedTupleIterator(java.util.List orig,
                          java.util.List added)
Creates a new iterator over tuples that are added to the Cartesian product when the collections in orig are augmented with the corresponding collections in added.

Parameters:
orig - List of Collection
added - List of Collection
Throws:
java.lang.IllegalArgumentException - if orig and added have different sizes
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

remove

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