net.sf.molae.pipe.cube
Class AbstractCube<E,T>

java.lang.Object
  extended by net.sf.molae.pipe.cube.AbstractCube<E,T>
All Implemented Interfaces:
Cube<E,T>
Direct Known Subclasses:
CubeProxy, TableModelAsCube, VaryingCube

public abstract class AbstractCube<E,T>
extends Object
implements Cube<E,T>

Skeleton implementation of the cube interface. Only the get and set methods have to be implemented.

Since:
1.1

Constructor Summary
protected AbstractCube()
          Constructs a new AbstractCube.
protected AbstractCube(List<Collection<? extends E>> edges)
          Constructs a new AbstractCube.
 
Method Summary
protected  Map<List<E>,T> asMap()
          Returns a map representation of this cube.
 boolean equals(Object o)
          Compares the specified object with this cube for equality.
abstract  T get(List<E> location)
          Returns the element at the specified location.
protected  Collection<? extends E> getEdge(int index)
          Returns the possible index values of the specified dimension.
 List<Collection<? extends E>> getEdges()
          Returns the possible index values of each dimension.
 Cube<E,T> getProjection(int index, E pivot)
          Returns a projection of this cube.
 int hashCode()
          Returns the hash code value for this cube.
abstract  void put(List<E> location, T value)
          Sets the element at the specified location to the specified value.
static
<E,T> void
putAll(Cube<E,T> target, Cube<E,T> source)
          Copies all values from the source cube to the target cube.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractCube

protected AbstractCube(List<Collection<? extends E>> edges)
Constructs a new AbstractCube.

Parameters:
edges - the edges of this cube.

AbstractCube

protected AbstractCube()
Constructs a new AbstractCube.

Method Detail

asMap

protected Map<List<E>,T> asMap()
Returns a map representation of this cube.

Returns:
a map representation of this cube.

hashCode

public int hashCode()
Description copied from interface: Cube
Returns the hash code value for this cube. The hash code of a cube c is defined to be new CubeAsMap(c).hashCode(). This ensures that c1.equals(c2) implies that c1.hashCode()==c2.hashCode() for any two cubes c1 and c2, as required by the general contract of Object.hashCode.

Specified by:
hashCode in interface Cube<E,T>
Overrides:
hashCode in class Object
Returns:
the hash code value for this cube

equals

public boolean equals(Object o)
Description copied from interface: Cube
Compares the specified object with this cube for equality. Returns true if the given object is also a cube and the two Cubes represent the same mappings. More formally, two cubes c1 and c2 represent the same mappings if new CubeAsMap(c1).equals(new CubeAsMap(c2)). This ensures that the equals method works properly across different implementations of the Cube interface.

Specified by:
equals in interface Cube<E,T>
Overrides:
equals in class Object
Parameters:
o - object to be compared for equality with this cube
Returns:
true if the specified object is equal to this cube

toString

public String toString()
Overrides:
toString in class Object

getEdges

public List<Collection<? extends E>> getEdges()
Returns the possible index values of each dimension. Each element of the returned list is a collection that contains all possible values for the dimension corresponding to the index in the list. This implementation returns the edges property.

Specified by:
getEdges in interface Cube<E,T>
Returns:
the possible index values of each dimension.

getEdge

protected Collection<? extends E> getEdge(int index)
Returns the possible index values of the specified dimension.

Parameters:
index - index of the requested edge
Returns:
the possible index values of the specified dimension.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getEdges().size()).

get

public abstract T get(List<E> location)
Returns the element at the specified location.

Specified by:
get in interface Cube<E,T>
Parameters:
location - a list of index values that determines a position int the cube
Returns:
the element at the specified location.
Throws:
NullPointerException - specified location is null.
RuntimeException - if the location is not valid (the exact type depends on the implementation).

put

public abstract void put(List<E> location,
                         T value)
Sets the element at the specified location to the specified value.

Specified by:
put in interface Cube<E,T>
Parameters:
location - a list of index values that determines a position int the cube
value - new value of the cell at the specified location
Throws:
UnsupportedOperationException - if this cube is not modifiable.
NullPointerException - specified location is null.
RuntimeException - if the location is not valid (the exact type depends on the implementation).

getProjection

public Cube<E,T> getProjection(int index,
                               E pivot)
Returns a projection of this cube. This implementation creates a CubeProxy of this object and calls the corresponding method of the proxy.

Specified by:
getProjection in interface Cube<E,T>
Parameters:
index - the dimension that will be fixed.
pivot - the fixed value of the fixed dimension.
Returns:
a projection of this cube.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getEdges().size()).

putAll

public static <E,T> void putAll(Cube<E,T> target,
                                Cube<E,T> source)
Copies all values from the source cube to the target cube. These values will replace the values at the corresponding locations in the target cube.

Parameters:
target - cube from which the values are read
source - cube in which the values are stored
Throws:
UnsupportedOperationException - target cube is not modifiable.
RuntimeException - depending on the target cube