public class MatrixComponent extends ICEObject implements Component
The MatrixComponent class is a realization of the Component interface that provides the functionality necessary to encapsulate a two dimensional array of double values, mimicking a mathematical matrix. It provides functionality to dynamically resize the matrix by allowing clients to add both rows and columns. MatrixComponent can exist in two 'flavors', a square matrix which is restricted to having dimensions NxN, or a non-square matrix which can have dimensions MxN, where M,N are not necessarily equal. MatrixComponent also provides functionality to indicate that the matrix elements must conform to a certain set of allowed values. MatrixComponent can take an AllowedValueType when constructed to indicate that the elements of the matrix must either be an element of a desired set of elements, or the matrix elements must exist within a given range of values.
iComponentVisitor
iComponentListener
Constructor and Description |
---|
MatrixComponent()
The default nullary constructor.
|
MatrixComponent(boolean isSquare)
The Constructor, takes a boolean argument to indicate whether this matrix
should be a square matrix or a non-square matrix.
|
MatrixComponent(boolean isSquare,
AllowedValueType allowedValueType)
The Constructor, takes a boolean argument to indicate whether this matrix
should be a square matrix or a non-square matrix.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(IComponentVisitor visitor)
(non-Javadoc)
|
int |
addColumn()
Add a new column to this MatrixComponent.
|
int |
addRow()
Add a new row to this MatrixComponent.
|
java.lang.Object |
clone()
This operation provides a deep copy of the MatrixComponent.
|
void |
copy(MatrixComponent otherMatrixComponent)
This operation performs a deep copy of the attributes of another
MatrixComponent into the current MatrixComponent.
|
boolean |
deleteColumn()
Remove a column from this MatrixComponent.
|
boolean |
deleteRow()
Remove a row from this MatrixComponent.
|
boolean |
equals(MatrixComponent otherMatrixComponent)
This operation is used to check equality between the MatrixComponent and
another MatrixComponent.
|
java.util.ArrayList<java.lang.Double> |
getAllowedValues()
Returns a list of allowed value types if discrete or continuous.
|
AllowedValueType |
getAllowedValueType()
Returns the ICE's AllowedValueType.
|
java.util.ArrayList<java.lang.Double> |
getColumn(int index)
Get a column of values at the given index.
|
java.lang.Double |
getElementValue(int rowIndex,
int colIndex)
Return the double valued matrix element at index i,j.
|
java.util.ArrayList<java.lang.Double> |
getRow(int index)
Return a row of values at the given index.
|
int |
hashCode()
This operation returns the hashcode value of the MatrixComponent.
|
boolean |
isResizable()
Returns true if the matrix can be resized.
|
boolean |
isSquare()
Returns true if this is a MatrixComponent representing a square matrix.
|
int |
numberOfColumns()
This operation returns the number of columns that are stored in the
matrix.
|
int |
numberOfRows()
This operation returns the number of rows that are stored in the matrix.
|
void |
setAllowedValues(java.util.ArrayList<java.lang.Double> values)
If this MatrixComponent's valueType attribute is anything other than
Undefined, use this method to indicate a list of matrix element allowed
values.
|
boolean |
setElementValue(int rowIndex,
int colIndex,
java.lang.Double value)
Set the value of the individual matrix element at index i,j.
|
void |
setResizable(boolean resizable)
Sets the matrix to be resized or not.
|
void |
update(java.lang.String updatedKey,
java.lang.String newValue)
(non-Javadoc)
|
copy, equals, getDescription, getId, getName, register, setDescription, setId, setName, unregister
getClass, notify, notifyAll, toString, wait, wait, wait
register, unregister
equals, getDescription, getId, getName, setDescription, setId, setName
public MatrixComponent(boolean isSquare, AllowedValueType allowedValueType)
The Constructor, takes a boolean argument to indicate whether this matrix should be a square matrix or a non-square matrix. This constructor also takes an argument to indicate whether the elements of this matrix must conform to a given set of allowed values. If this constructor is used, users must call the setAllowedValues method to indicate either the set the elements must be, or the range they must lie in.
isSquare
- Determines if a MatrixComponent will be square.
allowedValueType
- The allowed value type for MatrixComponent.
public MatrixComponent()
The default nullary constructor.
public MatrixComponent(boolean isSquare)
The Constructor, takes a boolean argument to indicate whether this matrix should be a square matrix or a non-square matrix.
isSquare
- Determines if a MatrixComponent is square.
public boolean isSquare()
Returns true if this is a MatrixComponent representing a square matrix.
A boolean for determining if a matrix is square or not.
public int addRow()
Add a new row to this MatrixComponent. If this Matrix is square, also add a column through the resizeSquareMatrix private method. The resultant row is by default a row of zeros or the first element of the allowedValues array if the valueType is Discrete. Allowed values must be set if the type is not undefined for this operation to work.
A value returned representing the row number that was added.
public boolean deleteRow()
Remove a row from this MatrixComponent. If this matrix is square, also call deletes column. Returns true if successful, false otherwise. Allowed values must be set if the type is not undefined for this operation to work.
A number that represents the index of the row deleted.
public int numberOfRows()
This operation returns the number of rows that are stored in the matrix.
The number of rows.
public int numberOfColumns()
This operation returns the number of columns that are stored in the matrix.
The number of columns.
public void copy(MatrixComponent otherMatrixComponent)
This operation performs a deep copy of the attributes of another MatrixComponent into the current MatrixComponent.
otherMatrixComponent
- The TableComponent from which information should be copied.
public java.lang.Object clone()
This operation provides a deep copy of the MatrixComponent.
clone
in interface Identifiable
clone
in class ICEObject
A clone of the TableComponent.
public boolean equals(MatrixComponent otherMatrixComponent)
This operation is used to check equality between the MatrixComponent and another MatrixComponent. It returns true if the MatrixComponents are equal and false if they are not.
otherMatrixComponent
- The TableComponent that should be checked for equality.
True if the TableComponents are equal, false if not
public int hashCode()
This operation returns the hashcode value of the MatrixComponent.
hashCode
in interface Identifiable
hashCode
in class ICEObject
The hashcode
Identifiable.hashCode()
public int addColumn()
Add a new column to this MatrixComponent. If this Matrix is square, it will also add a row through the resizeSquareMatrix private method. The resultant column is by default a row of zeros or the first element of the allowedValues array if the valueType is Discrete. Allowed values must be set if the type is not undefined for this operation to work.
A value returned representing the column number that was added.
public boolean deleteColumn()
Remove a column from this MatrixComponent. Returns true if successful, false otherwise. Allowed values must be set if the type is not undefined for this operation to work.
A number that represents the index of the column deleted.
public boolean setElementValue(int rowIndex, int colIndex, java.lang.Double value)
Set the value of the individual matrix element at index i,j. Returns true if successful, false if String value was not valid or the index was out of range.
rowIndex
- The row Index.
colIndex
- The column index.
value
- The value to be set.
Returns true if operation was successful. False otherwise.
public java.lang.Double getElementValue(int rowIndex, int colIndex)
Return the double valued matrix element at index i,j. Returns null if invalid index.
rowIndex
- The row index.
colIndex
- The column index.
The value at rowIndex, colIndex.
public void setAllowedValues(java.util.ArrayList<java.lang.Double> values)
If this MatrixComponent's valueType attribute is anything other than Undefined, use this method to indicate a list of matrix element allowed values. Useful for matrices that must have elements that adhere to a certain set of values, such as an adjacency matrix (ones and zeros). Values must be valid for this operation to pass.
values
- The allowed values to be set.
public java.util.ArrayList<java.lang.Double> getRow(int index)
Return a row of values at the given index.
index
- The index of the row.
An arraylist of a row at index.
public java.util.ArrayList<java.lang.Double> getColumn(int index)
Get a column of values at the given index.
index
- The column index.
An arraylist of columns.
public boolean isResizable()
Returns true if the matrix can be resized. False otherwise.
A boolean to determine resizable attribute.
public void setResizable(boolean resizable)
Sets the matrix to be resized or not.
resizable
- An attribute to set resizable. Default true.
public AllowedValueType getAllowedValueType()
Returns the ICE's AllowedValueType. If this is not set, returns null.
An ArrayList of doubles.
public java.util.ArrayList<java.lang.Double> getAllowedValues()
Returns a list of allowed value types if discrete or continuous. If undefined or not set, returns null.
An AllowedValueType.
public void update(java.lang.String updatedKey, java.lang.String newValue)
ICEObject
update
in interface IUpdateable
update
in class ICEObject
updatedKey
- A unique key that describes the value that to be updated.
newValue
- The updated value of the key.
IUpdateable.update(String updatedKey, String newValue)
public void accept(IComponentVisitor visitor)
accept
in interface Component
visitor
- The visitor
Component.accept(IComponentVisitor visitor)