SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.datastructure
Class FlexibleTable

java.lang.Object
  extended by com.numericalmethod.suanshu.datastructure.FlexibleTable
All Implemented Interfaces:
Table, MatrixAccess, MatrixTable
Direct Known Subclasses:
JordanExchange, SimplexTable

public class FlexibleTable
extends java.lang.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
FlexibleTable(FlexibleTable that)
          Copy constructor.
FlexibleTable(int nRows, int nCols)
          Construct a table using default labeling.
FlexibleTable(java.lang.Object[] rowLabels, java.lang.Object[] colLabels)
          Construct a table by row and column labels, initializing the content to 0.
FlexibleTable(java.lang.Object[] rowLabels, java.lang.Object[] colLabels, double[][] cells)
          Construct a flexible table that can shrink or grow.
 
Method Summary
 void addColAt(int i)
          Add a column at i.
 void addColAt(int i, java.lang.Object label)
          Add a column at i.
 void addRowAt(int i)
          Add a row at i.
 void addRowAt(int i, java.lang.Object label)
          Add a row at i.
 void deleteCol(int i)
          Delete column i.
 void deleteRow(int i)
          Delete row i.
 boolean equals(java.lang.Object obj)
           
 double get(int i, int j)
          Get the matrix entry at [i,j].
 java.lang.Object getColLabel(int i)
          Get the label for column i.
 Vector getColumn(int col)
           
 int getIndexFromColLabel(java.lang.Object label)
          Translate a column label to a column index.
 int getIndexFromRowLabel(java.lang.Object label)
          Translate a row label to a row index.
 Vector getRow(int row)
           
 java.lang.Object getRowLabel(int i)
          Get the label for row i.
 int hashCode()
           
 int nCols()
          Get the number of columns.
 int nRows()
          Get the number of rows.
 void renameCol(int i, java.lang.Object label)
          Rename column i.
 void renameRow(int i, java.lang.Object label)
          Rename row i.
 void set(int i, int j, double value)
          Set the matrix entry at [i,j] to a value.
 DenseMatrix toMatrix()
          Get a copy of the flexible table in the form of a matrix.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FlexibleTable

public FlexibleTable(java.lang.Object[] rowLabels,
                     java.lang.Object[] colLabels,
                     double[][] cells)
Construct a flexible table that can shrink or grow.

Parameters:
rowLabels - the row labels
colLabels - the column labels
cells - the table content

FlexibleTable

public FlexibleTable(java.lang.Object[] rowLabels,
                     java.lang.Object[] colLabels)
Construct 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)
Construct 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
Get 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
Get 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]

getRow

public Vector getRow(int row)
              throws MatrixAccessException
Throws:
MatrixAccessException

getColumn

public Vector getColumn(int col)
                 throws MatrixAccessException
Throws:
MatrixAccessException

getIndexFromRowLabel

public int getIndexFromRowLabel(java.lang.Object label)
Translate 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(java.lang.Object label)
Translate a column label to a column index. The index counts from 1.

Parameters:
label - a column label
Returns:
the column index

getRowLabel

public java.lang.Object getRowLabel(int i)
Get the label for row i.

Parameters:
i - a row index, counting from 1
Returns:
the label for row i

getColLabel

public java.lang.Object getColLabel(int i)
Get 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,
                      java.lang.Object label)
Rename row i.

Parameters:
i - a row index, counting from 1
label - the new label

renameCol

public void renameCol(int i,
                      java.lang.Object label)
Rename column i.

Parameters:
i - a column index, counting from 1
label - the new label

deleteRow

public void deleteRow(int i)
Delete row i.

Parameters:
i - a row index, counting from 1

deleteCol

public void deleteCol(int i)
Delete column i.

Parameters:
i - a column index, counting from 1

addRowAt

public void addRowAt(int i,
                     java.lang.Object label)
Add a row at i.

Parameters:
i - the row index, counting from 1
label - the row label

addRowAt

public void addRowAt(int i)
Add a row at i.

Parameters:
i - the row index, counting from 1

addColAt

public void addColAt(int i,
                     java.lang.Object label)
Add a column at i.

Parameters:
i - the column index, counting from 1
label - the column label

addColAt

public void addColAt(int i)
Add a column at i.

Parameters:
i - the column index, counting from 1

toMatrix

public DenseMatrix toMatrix()
Get a copy of the flexible table in the form of a matrix.

Returns:
a matrix representation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2012 Numerical Method Inc. Ltd. All Rights Reserved.