net.sf.molae.pipe.cube
Class CartesianCollection<E>

java.lang.Object
  extended by java.util.AbstractCollection<List<E>>
      extended by net.sf.molae.pipe.cube.CartesianCollection<E>
All Implemented Interfaces:
Iterable<List<E>>, Collection<List<E>>

public final class CartesianCollection<E>
extends AbstractCollection<List<E>>

The cartesian product of collections.


Constructor Summary
CartesianCollection(List<Collection<? extends E>> factors)
          Constructs a cartesian product from the specified factors.
 
Method Summary
 boolean contains(Object o)
          Returns true if this collection contains the specified element.
 boolean equals(Object o)
          Compares the specified object with this collection for equality.
 List<Collection<? extends E>> getFactors()
          Returns the factors of this cartesian collection.
 int hashCode()
          Returns the hash code value for this collection.
 Iterator<List<E>> iterator()
          Returns a lexicographical iterator over the elements in this collection.
 int size()
          Returns the number of elements in this collection.
 String toString()
          Returns a suitable representation of the factor list.
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CartesianCollection

public CartesianCollection(List<Collection<? extends E>> factors)
Constructs a cartesian product from the specified factors.

Parameters:
factors - list of the factors of this cartesian product.
Throws:
NullPointerException - if the specified list is null or one of the elements in the factor list is null.
ClassCastException - if any factor is not a Collection.
Method Detail

getFactors

public List<Collection<? extends E>> getFactors()
Returns the factors of this cartesian collection.

Returns:
the factors of this cartesian collection.

equals

public boolean equals(Object o)
Compares the specified object with this collection for equality. Two cartesian collections are considered equal if they have the same dimension and all factor lists are equal.

Specified by:
equals in interface Collection<List<E>>
Overrides:
equals in class Object
Parameters:
o - the reference object with which to compare.
Returns:
true if the specified Object is equal to this collection.

hashCode

public int hashCode()
Returns the hash code value for this collection. The hash code of a cartesian collection is defined to be the product of the hash codes of all factors.

Specified by:
hashCode in interface Collection<List<E>>
Overrides:
hashCode in class Object
Returns:
the hash code value for this collection

toString

public String toString()
Returns a suitable representation of the factor list.

Overrides:
toString in class AbstractCollection<List<E>>
Returns:
a suitable representation of the factor list

iterator

public Iterator<List<E>> iterator()
Returns a lexicographical iterator over the elements in this collection.

Specified by:
iterator in interface Iterable<List<E>>
Specified by:
iterator in interface Collection<List<E>>
Specified by:
iterator in class AbstractCollection<List<E>>
Returns:
an iterator over the elements in this collection

size

public int size()
Returns the number of elements in this collection.

Specified by:
size in interface Collection<List<E>>
Specified by:
size in class AbstractCollection<List<E>>
Returns:
the number of elements in this collection

contains

public boolean contains(Object o)
Returns true if this collection contains the specified element. This is the case, iff for each element of the specified collection the corresponding factor collection contains the element.

Specified by:
contains in interface Collection<List<E>>
Overrides:
contains in class AbstractCollection<List<E>>
Parameters:
o - expected to be a collection
Returns:
true if this collection contains the specified element.