Class 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 Detail

      • FlexibleTable

        public FlexibleTable​(Object[] rowLabels,
                             Object[] colLabels,
                             double[][] cells)
        Constructs a flexible table that can shrink or grow.
        Parameters:
        rowLabels - the row labels
        colLabels - the column labels
        cells - 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 labels
        colLabels - the column labels
      • FlexibleTable

        public FlexibleTable​(int nRows,
                             int nCols)
        Constructs a table using default labeling.
        Parameters:
        nRows - number of rows
        nCols - number of columns
      • FlexibleTable

        public FlexibleTable​(FlexibleTable that)
        Copy constructor.
        Parameters:
        that - another FlexibleTable
    • Method Detail

      • nRows

        public int nRows()
        Description copied from interface: Table
        Gets the number of rows. Rows count from 1.
        Specified by:
        nRows in interface Table
        Returns:
        the number of rows
      • nCols

        public int nCols()
        Description copied from interface: Table
        Gets the number of columns. Columns count from 1.
        Specified by:
        nCols in interface Table
        Returns:
        the number of columns
      • 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 interface MatrixAccess
        Parameters:
        i - the row index
        j - the column index
        value - 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 interface MatrixAccess
        Parameters:
        i - the row index
        j - the column index
        Returns:
        A[i,j]
      • 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 1
        label - the new label
      • renameCol

        public void renameCol​(int i,
                              Object label)
        Renames column i.
        Parameters:
        i - a column index, counting from 1
        label - 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 1
        label - 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 1
        label - 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object