Package dev.nm.misc.datastructure
Class FlexibleTable
java.lang.Object
dev.nm.misc.datastructure.FlexibleTable
- All Implemented Interfaces:
MatrixAccess
,MatrixTable
,Table
- Direct Known Subclasses:
SimplexTable
This is a 2D table that can shrink or grow by row or by column. The labels to the rows and
columns are for printing and debugging. The access to the table is by indices. All indices count
from 1. Translation between labels and indices are provided.
-
Constructor Summary
ConstructorsConstructorDescriptionFlexibleTable
(int nRows, int nCols) Constructs a table using default labeling.FlexibleTable
(FlexibleTable that) Copy constructor.FlexibleTable
(Object[] rowLabels, Object[] colLabels) Constructs a table by row and column labels, initializing the content to 0.FlexibleTable
(Object[] rowLabels, Object[] colLabels, double[][] cells) Constructs a flexible table that can shrink or grow. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addColAt
(int i) Adds a column at i.void
Adds a column at i.void
addRowAt
(int i) Adds a row at i.void
Adds a row at i.void
deleteCol
(int i) Deletes column i.void
deleteRow
(int i) Deletes row i.boolean
double
get
(int i, int j) Get the matrix entry at [i,j].getColLabel
(int i) Gets the label for column i.getColumn
(int col) int
getIndexFromColLabel
(Object label) Translates a column label to a column index.int
getIndexFromRowLabel
(Object label) Translates a row label to a row index.getRow
(int row) getRowLabel
(int i) Gets the label for row i.int
hashCode()
int
nCols()
Gets the number of columns.int
nRows()
Gets the number of rows.void
Renames column i.void
Renames row i.void
set
(int i, int j, double value) Set the matrix entry at [i,j] to a value.toMatrix()
Gets a copy of the flexible table in the form of a matrix.toString()
-
Constructor Details
-
FlexibleTable
Constructs a flexible table that can shrink or grow.- Parameters:
rowLabels
- the row labelscolLabels
- the column labelscells
- the table content
-
FlexibleTable
Constructs a table by row and column labels, initializing the content to 0.- Parameters:
rowLabels
- the row labelscolLabels
- the column labels
-
FlexibleTable
public FlexibleTable(int nRows, int nCols) Constructs a table using default labeling.- Parameters:
nRows
- number of rowsnCols
- number of columns
-
FlexibleTable
Copy constructor.- Parameters:
that
- anotherFlexibleTable
-
-
Method Details
-
nRows
public int nRows()Description copied from interface:Table
Gets the number of rows. Rows count from 1. -
nCols
public int nCols()Description copied from interface:Table
Gets the number of columns. Columns count from 1. -
set
public void set(int i, int j, double value) Description copied from interface:MatrixAccess
Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
set
in interfaceMatrixAccess
- Parameters:
i
- the row indexj
- the column indexvalue
- the value to set A[i,j] to
-
get
public double get(int i, int j) Description copied from interface:MatrixAccess
Get the matrix entry at [i,j].- Specified by:
get
in interfaceMatrixAccess
- Parameters:
i
- the row indexj
- the column index- Returns:
- A[i,j]
-
getRow
- Throws:
MatrixAccessException
-
getColumn
- Throws:
MatrixAccessException
-
getIndexFromRowLabel
Translates a row label to a row index. The index counts from 1.- Parameters:
label
- a row label- Returns:
- the row index
-
getIndexFromColLabel
Translates a column label to a column index. The index counts from 1.- Parameters:
label
- a column label- Returns:
- the column index
-
getRowLabel
Gets the label for row i.- Parameters:
i
- a row index, counting from 1- Returns:
- the label for row i
-
getColLabel
Gets the label for column i.- Parameters:
i
- a column index, counting from 1- Returns:
- the label for column i
-
renameRow
Renames row i.- Parameters:
i
- a row index, counting from 1label
- the new label
-
renameCol
Renames column i.- Parameters:
i
- a column index, counting from 1label
- the new label
-
deleteRow
public void deleteRow(int i) Deletes row i.- Parameters:
i
- a row index, counting from 1
-
deleteCol
public void deleteCol(int i) Deletes column i.- Parameters:
i
- a column index, counting from 1
-
addRowAt
Adds a row at i.- Parameters:
i
- the row index, counting from 1label
- the row label
-
addRowAt
public void addRowAt(int i) Adds a row at i.- Parameters:
i
- the row index, counting from 1
-
addColAt
Adds a column at i.- Parameters:
i
- the column index, counting from 1label
- the column label
-
addColAt
public void addColAt(int i) Adds a column at i.- Parameters:
i
- the column index, counting from 1
-
toMatrix
Gets a copy of the flexible table in the form of a matrix.- Returns:
- a matrix representation
-
toString
-
equals
-
hashCode
public int hashCode()
-