All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.util.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.

Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
SimpleTokenizer, Stringizer, TokenCharacters, Table

Constructor Index

 o LabeledTable()
Create a new LabeledTable with no rows and no columns
 o LabeledTable(int, int)
Create a new LabeledTable with given number of rows and columns.
 o LabeledTable(Table)
Create a LabeledTable from a table

Method Index

 o clone()
Clones this labledTable.
 o columnAt(Object)
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
 o columnsAt(int, int)
Creates a new labeledTable with the specified columns of current labeledTable Rows labels of current labeledTable are copied to new LabeledTable
 o columnsAt(Object, Object)
Creates a new LabeledTable containing all the columns that have the value key in the indicated row.
 o elementAt(int, Object)
Returns the object in table at given row and column.
 o elementAt(Object, int)
Returns the object in table at given row and column.
 o elementAt(Object, Object)
Returns the object in table at given row and column.
 o insertColumnsAt(Table, Object)
Insert table "newColumns" in the Table.
 o insertRowsAt(Table, Object)
Insert table "newRows" in the Table.
 o removeColumnAt(Object)
Removes the indicated column from the table
 o removeColumnsAt(Object, Object)
Removes the indicated columns that have key in the indicated row
 o removeRowAt(Object)
Removes the indicated row from the table
 o removeRowsAt(Object, Object)
Removes the indicated rows that have key in the indicated column
 o rowAt(Object)
Returns the column in the table indicated by the label Returns null if column label is not found
 o rowsAt(int, int)
Creates a new table with the specified rows of current table
 o rowsAt(Object, Object)
Returns a new table containing all the rows that have the value key in the indicated column
 o setElementAt(Object, int, Object)
Places the object in table at given row and column
 o setElementAt(Object, Object, int)
Places the object in table at given row and column
 o setElementAt(Object, Object, Object)
Places the object in table at given row and column

Constructors

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

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

 o LabeledTable
 public LabeledTable(Table contents)
Create a LabeledTable from a table

Methods

 o clone
 public synchronized Object clone()
Clones this labledTable. The elements are not cloned.

Overrides:
clone in class Table
 o elementAt
 public synchronized Object elementAt(int row,
                                      Object columnLabel) throws 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: ArrayIndexOutOfBoundsException
thrown if row or columnLabel is not a valid index
 o elementAt
 public synchronized Object elementAt(Object rowLabel,
                                      Object columnLabel) throws 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: ArrayIndexOutOfBoundsException
thrown if rowlabel or columnLabel is not a valid index
 o elementAt
 public synchronized Object elementAt(Object rowLabel,
                                      int column) throws 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: ArrayIndexOutOfBoundsException
thrown if rowlabel or column is not a valid index
 o columnAt
 public synchronized LabeledTable columnAt(Object columnLabel) throws 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: ArrayIndexOutOfBoundsException
thrown if is not a valid index
 o columnsAt
 public synchronized LabeledTable columnsAt(Object key,
                                            Object rowLabel) throws 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: ArrayIndexOutOfBoundsException
thrown if rowlabel is not a valid index
 o columnsAt
 public synchronized Table columnsAt(int startColumn,
                                     int endColumn) throws 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: ArrayIndexOutOfBoundsException
thrown if startColumn or endColumn is not a valid index
Overrides:
columnsAt in class Table
 o insertColumnsAt
 public synchronized void insertColumnsAt(Table newColumns,
                                          Object startColumnLabel) throws 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: ArrayIndexOutOfBoundsException
thrown ifstartColumnLabel is not a valid index
 o removeColumnAt
 public synchronized void removeColumnAt(Object columnLabel) throws ArrayIndexOutOfBoundsException
Removes the indicated column from the table

Throws: ArrayIndexOutOfBoundsException
thrown if columnLabel is not a valid index
 o removeColumnsAt
 public synchronized void removeColumnsAt(Object key,
                                          Object rowLabel) throws ArrayIndexOutOfBoundsException, 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: ArrayIndexOutOfBoundsException
thrown if row is not a valid index
Throws: NullPointerException
thrown if key is null
 o insertRowsAt
 public synchronized void insertRowsAt(Table newRows,
                                       Object rowLabel) throws 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: ArrayIndexOutOfBoundsException
thrown if rowlabel is not a valid index
 o removeRowAt
 public synchronized void removeRowAt(Object rowLabel) throws ArrayIndexOutOfBoundsException
Removes the indicated row from the table

Throws: ArrayIndexOutOfBoundsException
thrown if rowlabel is not a valid index
 o removeRowsAt
 public synchronized void removeRowsAt(Object key,
                                       Object columnLabel) throws ArrayIndexOutOfBoundsException, 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: ArrayIndexOutOfBoundsException
thrown if columnLabel is not a valid index
Throws: NullPointerException
thrown if key is null
 o rowAt
 public synchronized LabeledTable rowAt(Object rowLabel) throws ArrayIndexOutOfBoundsException
Returns the column in the table indicated by the label Returns null if column label is not found

Throws: ArrayIndexOutOfBoundsException
thrown if rowLabel is not a valid index
 o rowsAt
 public synchronized Table rowsAt(int startRow,
                                  int endRow) throws ArrayIndexOutOfBoundsException
Creates a new table with the specified rows of current table

Throws: ArrayIndexOutOfBoundsException
thrown if row or column is not a valid index
Overrides:
rowsAt in class Table
 o rowsAt
 public synchronized LabeledTable rowsAt(Object key,
                                         Object columnLabel) throws ArrayIndexOutOfBoundsException
Returns a new table containing all the rows that have the value key in the indicated column

Throws: ArrayIndexOutOfBoundsException
thrown if columnLabel is not a valid index
 o setElementAt
 public synchronized void setElementAt(Object data,
                                       Object rowLabel,
                                       int column) throws ArrayIndexOutOfBoundsException
Places the object in table at given row and column

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

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

Throws: ArrayIndexOutOfBoundsException
thrown if rowLabel or columnLabel is not a valid index

All Packages  Class Hierarchy  This Package  Previous  Next  Index