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
public class FlexibleTable extends Object implements MatrixTable
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
Constructors Constructor Description FlexibleTable(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColAt(int i)Adds a column at i.voidaddColAt(int i, Object label)Adds a column at i.voidaddRowAt(int i)Adds a row at i.voidaddRowAt(int i, Object label)Adds a row at i.voiddeleteCol(int i)Deletes column i.voiddeleteRow(int i)Deletes row i.booleanequals(Object obj)doubleget(int i, int j)Get the matrix entry at [i,j].ObjectgetColLabel(int i)Gets the label for column i.VectorgetColumn(int col)intgetIndexFromColLabel(Object label)Translates a column label to a column index.intgetIndexFromRowLabel(Object label)Translates a row label to a row index.VectorgetRow(int row)ObjectgetRowLabel(int i)Gets the label for row i.inthashCode()intnCols()Gets the number of columns.intnRows()Gets the number of rows.voidrenameCol(int i, Object label)Renames column i.voidrenameRow(int i, Object label)Renames row i.voidset(int i, int j, double value)Set the matrix entry at [i,j] to a value.DenseMatrixtoMatrix()Gets a copy of the flexible table in the form of a matrix.StringtoString()
-
-
-
Constructor Detail
-
FlexibleTable
public FlexibleTable(Object[] rowLabels, Object[] colLabels, double[][] cells)
Constructs a flexible table that can shrink or grow.- Parameters:
rowLabels- the row labelscolLabels- the column labelscells- the table content
-
FlexibleTable
public FlexibleTable(Object[] rowLabels, Object[] colLabels)
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
public FlexibleTable(FlexibleTable that)
Copy constructor.- Parameters:
that- anotherFlexibleTable
-
-
Method Detail
-
nRows
public int nRows()
Description copied from interface:TableGets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:TableGets the number of columns. Columns count from 1.
-
set
public void set(int i, int j, double value)Description copied from interface:MatrixAccessSet the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
setin 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:MatrixAccessGet the matrix entry at [i,j].- Specified by:
getin interfaceMatrixAccess- Parameters:
i- the row indexj- the column index- Returns:
- A[i,j]
-
getRow
public Vector getRow(int row) throws MatrixAccessException
- Throws:
MatrixAccessException
-
getColumn
public Vector getColumn(int col) throws MatrixAccessException
- Throws:
MatrixAccessException
-
getIndexFromRowLabel
public int getIndexFromRowLabel(Object label)
Translates a row label to a row index. The index counts from 1.- Parameters:
label- a row label- Returns:
- the row index
-
getIndexFromColLabel
public int getIndexFromColLabel(Object label)
Translates a column label to a column index. The index counts from 1.- Parameters:
label- a column label- Returns:
- the column index
-
getRowLabel
public Object getRowLabel(int i)
Gets the label for row i.- Parameters:
i- a row index, counting from 1- Returns:
- the label for row i
-
getColLabel
public Object getColLabel(int i)
Gets the label for column i.- Parameters:
i- a column index, counting from 1- Returns:
- the label for column i
-
renameRow
public void renameRow(int i, Object label)Renames row i.- Parameters:
i- a row index, counting from 1label- the new label
-
renameCol
public void renameCol(int i, Object label)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
public void addRowAt(int i, Object label)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
public void addColAt(int i, Object label)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
public DenseMatrix toMatrix()
Gets a copy of the flexible table in the form of a matrix.- Returns:
- a matrix representation
-
-