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

java.lang.Object
  extended by org.decisiondeck.xmcda_oo.utils.matrix.FloatMatrix<RowType,ColumnType>
All Implemented Interfaces:
IFloatMatrix<RowType,ColumnType>, IRdFloatMatrix<RowType,ColumnType>
Direct Known Subclasses:
EvaluationMatrix

public class FloatMatrix<RowType,ColumnType>
extends Object
implements IFloatMatrix<RowType,ColumnType>, IRdFloatMatrix<RowType,ColumnType>


Constructor Summary
FloatMatrix()
           
FloatMatrix(ConstrainedMatrix<RowType,ColumnType> mat)
           
FloatMatrix(FloatMatrix<RowType,ColumnType> matrix)
          Copy constructor, by reference.
 
Method Summary
 boolean approxEquals(IRdFloatMatrix<RowType,ColumnType> m2, double precision)
          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>
FloatMatrix<RowT,ColumnT>
copy(IRdFloatMatrix<RowT,ColumnT> matrix)
          Creates a new matrix containing the same values as the one given.
 boolean equals(Object obj)
          Two matrix are equal iff they are the same type and contain the same values at the same positions.
 IZeroToOneMatrix<RowType,ColumnType> getAsFuzzy()
          Produces a fuzzy matrix view of this matrix.
 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 composed by the given row and column, or 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 isFuzzy()
          Tells whether this matrix may be converted to a fuzzy matrix.
 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)
          Remove 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

FloatMatrix

public FloatMatrix()

FloatMatrix

public FloatMatrix(FloatMatrix<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, and conversely.

Parameters:
matrix - not null.

FloatMatrix

public FloatMatrix(ConstrainedMatrix<RowType,ColumnType> mat)
Method Detail

copy

public static <RowT,ColumnT> FloatMatrix<RowT,ColumnT> copy(IRdFloatMatrix<RowT,ColumnT> matrix)
Creates a new matrix containing the same values as the one given.

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. Not null.

approxEquals

public boolean approxEquals(IRdFloatMatrix<RowType,ColumnType> m2,
                            double precision)
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.
precision - 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: IRdFloatMatrix
Returns the value at the position composed by the given row and column, or null if there is none.

Specified by:
getEntry in interface IRdFloatMatrix<RowType,ColumnType>
Parameters:
row - not null.
column - not null.
Returns:
the double value at that position, 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: IFloatMatrix
Puts a value in this matrix at the position specified by the given row and column.

Specified by:
put in interface IFloatMatrix<RowType,ColumnType>
Parameters:
row - not null.
column - not null.
value - any double.

remove

public Double remove(RowType row,
                     ColumnType column)
Description copied from interface: IFloatMatrix
Remove 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 IFloatMatrix<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

getAsFuzzy

public IZeroToOneMatrix<RowType,ColumnType> getAsFuzzy()
Description copied from interface: IFloatMatrix
Produces a fuzzy matrix view of this matrix. Note that if that call returns a fuzzy view, this matrix may not be used any more afterwards to put non-fuzzy values as this would break the underlying fuzzy matrix's contract.

Specified by:
getAsFuzzy in interface IFloatMatrix<RowType,ColumnType>
Returns:
a fuzzy matrix containing the same values as this matrix, and reflecting changes in this matrix, or null if this matrix cannot be converted to a fuzzy matrix.

isFuzzy

public boolean isFuzzy()
Description copied from interface: IFloatMatrix
Tells whether this matrix may be converted to a fuzzy matrix.

Specified by:
isFuzzy in interface IFloatMatrix<RowType,ColumnType>
Returns:
true iff all the values contained in this matrix are between zero and one.


Copyright © 2011. All Rights Reserved.