org.decisiondeck.xmcda_oo.utils.matrix
Class FuzzyMatrix<RowType,ColumnType>

java.lang.Object
  extended by org.decisiondeck.xmcda_oo.utils.matrix.FuzzyMatrix<RowType,ColumnType>
All Implemented Interfaces:
IRdFloatMatrix<RowType,ColumnType>, IRdZeroToOneMatrix<RowType,ColumnType>, IZeroToOneMatrix<RowType,ColumnType>
Direct Known Subclasses:
AltFuzzyMatrix

public class FuzzyMatrix<RowType,ColumnType>
extends Object
implements IZeroToOneMatrix<RowType,ColumnType>, IRdFloatMatrix<RowType,ColumnType>


Constructor Summary
FuzzyMatrix()
           
FuzzyMatrix(ConstrainedMatrix<RowType,ColumnType> matrix)
          Copy constructor, by reference.
FuzzyMatrix(FuzzyMatrix<RowType,ColumnType> matrix)
          Copy constructor, by reference.
 
Method Summary
 boolean approxEquals(IRdFloatMatrix<RowType,ColumnType> m2, double imprecision)
          Two matrix are "approximately equal" to a given degree of precision iff they contain values for the same mappings and the value they contain for each mapping are not more different than the given allowed imprecision.
static
<RowT,ColumnT>
FuzzyMatrix<RowT,ColumnT>
copyAndConvert(IRdFloatMatrix<RowT,ColumnT> matrix)
          Creates a new matrix containing the same values as the one given, if it is possible.
 boolean equals(Object obj)
          Two matrix are equal iff they are the same type and contain the same values at the same positions.
 Set<ColumnType> getColumns()
          Returns a read-only view of the columns existing in this matrix.
 Double getEntry(RowType row, ColumnType column)
          Returns the value at the position specified by the given row and column, of null if there is none.
 Set<RowType> getRows()
          Returns a view of the rows existing in this matrix.
 int getValueCount()
           Gets the number of values in this matrix.
 int hashCode()
           
 boolean isComplete()
           A matrix is complete iff it contains a value for every possible position (row, column) where row and column are rows and columns existing in this matrix (i.e. corresponding to at least one value).
 boolean isEmpty()
          Checks whether this matrix contains no value.
 boolean isValid(double value)
           
 void put(RowType row, ColumnType column, double value)
          Puts a value in this matrix at the position specified by the given row and column.
 Double remove(RowType row, ColumnType column)
          Removes the value in this matrix at the position specified by the given row and column.
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FuzzyMatrix

public FuzzyMatrix()

FuzzyMatrix

public FuzzyMatrix(FuzzyMatrix<RowType,ColumnType> matrix)
Copy constructor, by reference. This matrix will reflect the values inside the given matrix. Modifying this matrix will modify the given matrix as well.

Parameters:
matrix - not null.

FuzzyMatrix

public FuzzyMatrix(ConstrainedMatrix<RowType,ColumnType> matrix)
Copy constructor, by reference. This matrix will reflect the values inside the given matrix. Modifying this matrix will modify the given matrix as well.

Parameters:
matrix - not null.
Method Detail

copyAndConvert

public static <RowT,ColumnT> FuzzyMatrix<RowT,ColumnT> copyAndConvert(IRdFloatMatrix<RowT,ColumnT> matrix)
Creates a new matrix containing the same values as the one given, if it is possible. This method may be used to convert a matrix from a type to an other.

Type Parameters:
RowT - the type of row for the matrix to create and the matrix to convert from.
ColumnT - the type of column for the matrix to create and the matrix to convert from.
Parameters:
matrix - the matrix to copy the values from. Not null (but may be empty).
Returns:
a new matrix containing the values of the given matrix, or null if this is not possible (that case happens iff the given matrix contains at least one non-fuzzy value).

approxEquals

public boolean approxEquals(IRdFloatMatrix<RowType,ColumnType> m2,
                            double imprecision)
Description copied from interface: IRdFloatMatrix
Two matrix are "approximately equal" to a given degree of precision iff they contain values for the same mappings and the value they contain for each mapping are not more different than the given allowed imprecision.

Specified by:
approxEquals in interface IRdFloatMatrix<RowType,ColumnType>
Parameters:
m2 - the matrix to which to compare this object for approximate equality. If null, this method returns false.
imprecision - the maximal imprecision allowed.
Returns:
true iff the given matrix is approximately equal to this one.

equals

public boolean equals(Object obj)
Description copied from interface: IRdFloatMatrix
Two matrix are equal iff they are the same type and contain the same values at the same positions. Note that the values are compared exactly, thus a very small difference in one value will cause two matrixes to be unequal. See IRdFloatMatrix.approxEquals(IRdFloatMatrix, double) if this can be a problem.

Specified by:
equals in interface IRdFloatMatrix<RowType,ColumnType>
Overrides:
equals in class Object
Parameters:
obj - the object to compare. May be null.
Returns:
true iff the given object is equal to this matrix.
See Also:
Object.equals(java.lang.Object)

getColumns

public Set<ColumnType> getColumns()
Description copied from interface: IRdFloatMatrix
Returns a read-only view of the columns existing in this matrix. The returned set "read through" to the matrix, thus modifications of this matrix are reflected in the returned set.

Specified by:
getColumns in interface IRdFloatMatrix<RowType,ColumnType>
Returns:
the objects such that at least one value exists in this matrix at a position having the object as column. Not null. Empty iff this matrix is empty.

getEntry

public Double getEntry(RowType row,
                       ColumnType column)
Description copied from interface: IRdZeroToOneMatrix
Returns the value at the position specified by the given row and column, of null if there is none.

Specified by:
getEntry in interface IRdFloatMatrix<RowType,ColumnType>
Specified by:
getEntry in interface IRdZeroToOneMatrix<RowType,ColumnType>
Parameters:
row - not null.
column - not null.
Returns:
the double value at that position (between zero and one inclusive), or null.

getRows

public Set<RowType> getRows()
Description copied from interface: IRdFloatMatrix
Returns a view of the rows existing in this matrix. The returned set "read through" to the matrix, thus modifications of this matrix are reflected in the returned set. The view may be read-only (some objects may also support objects removal from the returned set).

Specified by:
getRows in interface IRdFloatMatrix<RowType,ColumnType>
Returns:
the objects such that at least one value exists in this matrix at a position having the object as row. Not null. Empty iff this matrix is empty.

getValueCount

public int getValueCount()
Description copied from interface: IRdFloatMatrix

Gets the number of values in this matrix.

Note that the word "size" is not used here because the size of the matrix could be understood as meaning its row count times its column count, which is the same as its value count only if it is complete.

Specified by:
getValueCount in interface IRdFloatMatrix<RowType,ColumnType>
Returns:
the count of values.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isComplete

public boolean isComplete()
Description copied from interface: IRdFloatMatrix

A matrix is complete iff it contains a value for every possible position (row, column) where row and column are rows and columns existing in this matrix (i.e. corresponding to at least one value). An empty matrix is complete.

Specified by:
isComplete in interface IRdFloatMatrix<RowType,ColumnType>
Returns:
true iff this matrix is complete.

isEmpty

public boolean isEmpty()
Description copied from interface: IRdFloatMatrix
Checks whether this matrix contains no value.

Specified by:
isEmpty in interface IRdFloatMatrix<RowType,ColumnType>
Returns:
true iff the matrix contains no value.

put

public void put(RowType row,
                ColumnType column,
                double value)
Description copied from interface: IZeroToOneMatrix
Puts a value in this matrix at the position specified by the given row and column.

Specified by:
put in interface IZeroToOneMatrix<RowType,ColumnType>
Parameters:
row - not null.
column - not null.
value - between zero and one (inclusive).

remove

public Double remove(RowType row,
                     ColumnType column)
Description copied from interface: IZeroToOneMatrix
Removes the value in this matrix at the position specified by the given row and column. If there was no value at that position, this method has no effect.

Specified by:
remove in interface IZeroToOneMatrix<RowType,ColumnType>
Parameters:
row - not null.
column - not null.
Returns:
the value which was previously at the given position. Returns null iff there was no value at that position (and, hence, nothing was removed).

toString

public String toString()
Overrides:
toString in class Object

isValid

public boolean isValid(double value)
Specified by:
isValid in interface IZeroToOneMatrix<RowType,ColumnType>


Copyright © 2011. All Rights Reserved.