common
Class CartesianProduct

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<java.util.List<?>>
          extended by common.CartesianProduct
All Implemented Interfaces:
java.lang.Iterable<java.util.List<?>>, java.util.Collection<java.util.List<?>>, java.util.List<java.util.List<?>>

public class CartesianProduct
extends java.util.AbstractList<java.util.List<?>>

An implicit representation of the Cartesian product of a list of lists. The tuples in the Cartesian product are ordered lexicographically. When you iterate over tuples, the last element changes fastest and the first element changes slowest.

Unlike TupleIterator, this class supports accessing arbitrary tuples by their index (with the get method), and computing the index for a given tuple (with indexOf).


Field Summary
protected  java.util.List[] dims
           
protected  int[] indexMultipliers
           
protected  int size
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
CartesianProduct(java.util.List<? extends java.util.List<?>> dimList)
          Creates an implicit representation of the Cartesian product of the given lists.
 
Method Summary
 java.util.List<?> get(int index)
           
 int indexOf(java.lang.Object o)
           
 java.util.Iterator<java.util.List<?>> iterator()
           
 java.util.ListIterator<java.util.List<?>> listIterator()
           
 java.util.ListIterator<java.util.List<?>> listIterator(int index)
           
static void main(java.lang.String[] args)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, lastIndexOf, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

dims

protected java.util.List[] dims

indexMultipliers

protected int[] indexMultipliers

size

protected int size
Constructor Detail

CartesianProduct

public CartesianProduct(java.util.List<? extends java.util.List<?>> dimList)
Creates an implicit representation of the Cartesian product of the given lists.

Method Detail

size

public int size()
Specified by:
size in interface java.util.Collection<java.util.List<?>>
Specified by:
size in interface java.util.List<java.util.List<?>>
Specified by:
size in class java.util.AbstractCollection<java.util.List<?>>

iterator

public java.util.Iterator<java.util.List<?>> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.util.List<?>>
Specified by:
iterator in interface java.util.Collection<java.util.List<?>>
Specified by:
iterator in interface java.util.List<java.util.List<?>>
Overrides:
iterator in class java.util.AbstractList<java.util.List<?>>

listIterator

public java.util.ListIterator<java.util.List<?>> listIterator()
Specified by:
listIterator in interface java.util.List<java.util.List<?>>
Overrides:
listIterator in class java.util.AbstractList<java.util.List<?>>

listIterator

public java.util.ListIterator<java.util.List<?>> listIterator(int index)
Specified by:
listIterator in interface java.util.List<java.util.List<?>>
Overrides:
listIterator in class java.util.AbstractList<java.util.List<?>>

get

public java.util.List<?> get(int index)
Specified by:
get in interface java.util.List<java.util.List<?>>
Specified by:
get in class java.util.AbstractList<java.util.List<?>>

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<java.util.List<?>>
Overrides:
indexOf in class java.util.AbstractList<java.util.List<?>>

main

public static void main(java.lang.String[] args)