sdsu.util
Class LabeledTable

java.lang.Object
  |
  +--sdsu.util.Table
        |
        +--sdsu.util.LabeledTable

public class LabeledTable
extends Table

This class is a two dimensional table that permits indexing via labels. Labels are taken from the first row and column. If the contents of LabeledTable example is:

NamePayDepartment
Joe$100.00Math
Sally$500.00Physics


then example.elementAt( "Sally", "Pay") returns $500.00. If row (column) labels contain duplicates, only the first instance is accessed by label indexing. When creating subtables (via rowAt, rowsAt, columnAt columnsAt) labels from original table are copied to subtable. While changing individual elements via labels is supported, adding additional rows and columns via labels is not yet supported. Use addRow and addColumn from Table superclass.

Version:
0.8 1 March 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
SimpleTokenizer, Stringizer, TokenCharacters, Table, Serialized Form

Constructor Summary
LabeledTable()
          Create a new LabeledTable with no rows and no columns
LabeledTable(int initNumberOfRows, int initNumberOfColumns)
          Create a new LabeledTable with given number of rows and columns.
LabeledTable(Table contents)
          Create a LabeledTable from a table
 
Method Summary
 java.lang.Object clone()
          Clones this labledTable.
 LabeledTable columnAt(java.lang.Object columnLabel)
          Returns the column in the table indicated by the label Returns null if column label is not found Rows labels of current labeledTable are copied to new LabeledTable
 Table columnsAt(int startColumn, int endColumn)
          Creates a new labeledTable with the specified columns of current labeledTable Rows labels of current labeledTable are copied to new LabeledTable
 LabeledTable columnsAt(java.lang.Object key, java.lang.Object rowLabel)
          Creates a new LabeledTable containing all the columns that have the value key in the indicated row.
 java.lang.Object elementAt(int row, java.lang.Object columnLabel)
          Returns the object in table at given row and column.
 java.lang.Object elementAt(java.lang.Object rowLabel, int column)
          Returns the object in table at given row and column.
 java.lang.Object elementAt(java.lang.Object rowLabel, java.lang.Object columnLabel)
          Returns the object in table at given row and column.
 void insertColumnsAt(Table newColumns, java.lang.Object startColumnLabel)
          Insert table "newColumns" in the Table.
 void insertRowsAt(Table newRows, java.lang.Object rowLabel)
          Insert table "newRows" in the Table.
 void removeColumnAt(java.lang.Object columnLabel)
          Removes the indicated column from the table
 void removeColumnsAt(java.lang.Object key, java.lang.Object rowLabel)
          Removes the indicated columns that have key in the indicated row
 void removeRowAt(java.lang.Object rowLabel)
          Removes the indicated row from the table
 void removeRowsAt(java.lang.Object key, java.lang.Object columnLabel)
          Removes the indicated rows that have key in the indicated column
 LabeledTable rowAt(java.lang.Object rowLabel)
          Returns the column in the table indicated by the label Returns null if column label is not found
 Table rowsAt(int startRow, int endRow)
          Creates a new table with the specified rows of current table
 LabeledTable rowsAt(java.lang.Object key, java.lang.Object columnLabel)
          Returns a new table containing all the rows that have the value key in the indicated column
 void setElementAt(java.lang.Object data, int row, java.lang.Object columnLabel)
          Places the object in table at given row and column
 void setElementAt(java.lang.Object data, java.lang.Object rowLabel, int column)
          Places the object in table at given row and column
 void setElementAt(java.lang.Object data, java.lang.Object rowLabel, java.lang.Object columnLabel)
          Places the object in table at given row and column
 
Methods inherited from class sdsu.util.Table
addColumn, addColumns, addRow, addRows, columnAt, columnsAt, contains, elementAt, elements, fromColumnVector, fromRowVector, fromString, getMetaData, indexOf, insertColumnsAt, insertRowsAt, load, load, numberOfColumns, numberOfRows, removeColumnAt, removeColumnsAt, removeColumnsAt, removeRowAt, removeRowsAt, removeRowsAt, rowAt, rowsAt, save, setColumnSeparatorChar, setElementAt, setMetaData, setRowSeparatorChar, setTokenCharacters, size, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LabeledTable

public LabeledTable()
Create a new LabeledTable with no rows and no columns

LabeledTable

public LabeledTable(int initNumberOfRows,
                    int initNumberOfColumns)
Create a new LabeledTable with given number of rows and columns. All elements are set to null.

LabeledTable

public LabeledTable(Table contents)
Create a LabeledTable from a table
Method Detail

clone

public java.lang.Object clone()
Clones this labledTable. The elements are not cloned.
Overrides:
clone in class Table

elementAt

public java.lang.Object elementAt(int row,
                                  java.lang.Object columnLabel)
                           throws java.lang.ArrayIndexOutOfBoundsException
Returns the object in table at given row and column. Column is indicated by label object. Returns null if column label is not found
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if row or columnLabel is not a valid index

elementAt

public java.lang.Object elementAt(java.lang.Object rowLabel,
                                  java.lang.Object columnLabel)
                           throws java.lang.ArrayIndexOutOfBoundsException
Returns the object in table at given row and column. row is indicated by label object. Returns null if row label is not found
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowlabel or columnLabel is not a valid index

elementAt

public java.lang.Object elementAt(java.lang.Object rowLabel,
                                  int column)
                           throws java.lang.ArrayIndexOutOfBoundsException
Returns the object in table at given row and column. row is indicated by label object. Returns null if row label is not found
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowlabel or column is not a valid index

columnAt

public LabeledTable columnAt(java.lang.Object columnLabel)
                      throws java.lang.ArrayIndexOutOfBoundsException
Returns the column in the table indicated by the label Returns null if column label is not found Rows labels of current labeledTable are copied to new LabeledTable
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if is not a valid index

columnsAt

public LabeledTable columnsAt(java.lang.Object key,
                              java.lang.Object rowLabel)
                       throws java.lang.ArrayIndexOutOfBoundsException
Creates a new LabeledTable containing all the columns that have the value key in the indicated row. Rows labels of current labeledTable are copied to new LabeledTable
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowlabel is not a valid index

columnsAt

public Table columnsAt(int startColumn,
                       int endColumn)
                throws java.lang.ArrayIndexOutOfBoundsException
Creates a new labeledTable with the specified columns of current labeledTable Rows labels of current labeledTable are copied to new LabeledTable
Returns:
a labeledTable, inheritance forces to declare return type as table
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if startColumn or endColumn is not a valid index
Overrides:
columnsAt in class Table

insertColumnsAt

public void insertColumnsAt(Table newColumns,
                            java.lang.Object startColumnLabel)
                     throws java.lang.ArrayIndexOutOfBoundsException
Insert table "newColumns" in the Table. "newColumns" is inserted at column "startColumnLabel" of current table. The column "startIndex" prior to the insert will follow the newly added columns Table grows to include all elements of newColumns
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown ifstartColumnLabel is not a valid index

removeColumnAt

public void removeColumnAt(java.lang.Object columnLabel)
                    throws java.lang.ArrayIndexOutOfBoundsException
Removes the indicated column from the table
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if columnLabel is not a valid index

removeColumnsAt

public void removeColumnsAt(java.lang.Object key,
                            java.lang.Object rowLabel)
                     throws java.lang.ArrayIndexOutOfBoundsException,
                            java.lang.NullPointerException
Removes the indicated columns that have key in the indicated row
Parameters:
key - the key to be searched for
row - row in table to search for the key
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if row is not a valid index
java.lang.NullPointerException - thrown if key is null

insertRowsAt

public void insertRowsAt(Table newRows,
                         java.lang.Object rowLabel)
                  throws java.lang.ArrayIndexOutOfBoundsException
Insert table "newRows" in the Table. "newRows" is inserted at row "startRowLabel" of current table. The row "startIndex" prior to the insert will follow the newly added rows Table grows to include all elements of newRows
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowlabel is not a valid index

removeRowAt

public void removeRowAt(java.lang.Object rowLabel)
                 throws java.lang.ArrayIndexOutOfBoundsException
Removes the indicated row from the table
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowlabel is not a valid index

removeRowsAt

public void removeRowsAt(java.lang.Object key,
                         java.lang.Object columnLabel)
                  throws java.lang.ArrayIndexOutOfBoundsException,
                         java.lang.NullPointerException
Removes the indicated rows that have key in the indicated column
Parameters:
key - the key to be searched for
column - column in table to search for the key
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if columnLabel is not a valid index
java.lang.NullPointerException - thrown if key is null

rowAt

public LabeledTable rowAt(java.lang.Object rowLabel)
                   throws java.lang.ArrayIndexOutOfBoundsException
Returns the column in the table indicated by the label Returns null if column label is not found
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowLabel is not a valid index

rowsAt

public Table rowsAt(int startRow,
                    int endRow)
             throws java.lang.ArrayIndexOutOfBoundsException
Creates a new table with the specified rows of current table
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if row or column is not a valid index
Overrides:
rowsAt in class Table

rowsAt

public LabeledTable rowsAt(java.lang.Object key,
                           java.lang.Object columnLabel)
                    throws java.lang.ArrayIndexOutOfBoundsException
Returns a new table containing all the rows that have the value key in the indicated column
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if columnLabel is not a valid index

setElementAt

public void setElementAt(java.lang.Object data,
                         java.lang.Object rowLabel,
                         int column)
                  throws java.lang.ArrayIndexOutOfBoundsException
Places the object in table at given row and column
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowLabel or column is not a valid index

setElementAt

public void setElementAt(java.lang.Object data,
                         int row,
                         java.lang.Object columnLabel)
                  throws java.lang.ArrayIndexOutOfBoundsException
Places the object in table at given row and column
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if row or columnLabel is not a valid index

setElementAt

public void setElementAt(java.lang.Object data,
                         java.lang.Object rowLabel,
                         java.lang.Object columnLabel)
                  throws java.lang.ArrayIndexOutOfBoundsException
Places the object in table at given row and column
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown if rowLabel or columnLabel is not a valid index