All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.util.Table

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

public class Table
extends Object
implements Cloneable
This class is a two dimensional table. Indexing of rows and columns starts at 0. The table is growable. Surplus rows and columns are allocated to reduce cost of growing the table. Surplus rows/columns can not be accessed until rows or columns are added. Table can be converted from/to string/streams. In string representation default column separator is ',' and default row separator is ';'. The recreated table object will only contain string representations of the original elements in the table.

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

Constructor Index

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

Method Index

 o addColumn(Vector)
Add a new column to the end of the Table.
 o addColumns(Table)
Add a table as new columns.
 o addRow(Vector)
Add a new row to the end of the Table.
 o addRows(Table)
Add table "newRows" at the bottom of the Table.
 o clone()
Clones this table.
 o columnAt(int)
Returns the given column in the table
 o columnsAt(int, int)
Creates a new table with the specified columns of current table
 o columnsAt(Object, int)
Creates a new table containing all the columns that have the value key in the indicated row
 o contains(Object)
Returns true if the specified object is in the table
 o elementAt(int, int)
Returns the object in table at given row and column.
 o elements()
Returns an enumeration of the non-null elements in row order.
 o fromColumnVector(Vector)
Create a table using the vector column as the only column in the table
 o fromRowVector(Vector)
Create a table using the vector row as the only row in the table
 o fromString(String)
Loads a Table from a string.
 o indexOf(Object)
Searches for the specified object, in row order.
 o insertColumnsAt(Table, int)
Insert table "newColumns" in the Table.
 o insertRowsAt(Table, int)
Insert table "newRows" in the Table.
 o load(InputStream)
Loads a Table from an inputstream.
 o numberOfColumns()
Returns the number of columns that can currently be accessed
 o numberOfRows()
Returns the number of rows that can currently be accessed
 o removeColumnAt(int)
Removes the indicated column from the table
 o removeColumnsAt(int, int)
Removes the indicated columns from the table
 o removeColumnsAt(Object, int)
Removes the indicated columns that have key in the indicated row
 o removeRowAt(int)
Removes the indicated row from the table
 o removeRowsAt(int, int)
Removes the indicated rows from the table
 o removeRowsAt(Object, int)
Removes the indicated rows that have key in the indicated column
 o rowAt(int)
Returns the given row in the table
 o rowsAt(int, int)
Creates a new table with the specified rows of current table
 o rowsAt(Object, int)
Returns a new table containing all the rows that have the value key in the indicated column
 o save(OutputStream, String)
Writes ascii representation of a Table to Outputstream
 o setColumnSeparatorChar(char)
Set character used to separate rows in String representation of a Table
 o setElementAt(Object, int, int)
Places the object in table at given row and column
 o setRowSeparatorChar(char)
Set character used to separate rows in String representation of a Table
 o setTokenCharacters(TokenCharacters)
Sets TokenCharacters used to convert Table from/to strings/streams.
 o size()
Return the number of items in the table
 o toString()
Converts a Table to a String.
 o toString(String)
Converts a Table to a String with given header information.

Constructors

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

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

Methods

 o fromRowVector
 public static Table fromRowVector(Vector row)
Create a table using the vector row as the only row in the table

 o fromColumnVector
 public static Table fromColumnVector(Vector column)
Create a table using the vector column as the only column in the table

 o setTokenCharacters
 public void setTokenCharacters(TokenCharacters newParseTable)
Sets TokenCharacters used to convert Table from/to strings/streams. Current values for rowSeparatorChar and columnSeparatorChar override separator settings in TokenCharacters object.

 o setRowSeparatorChar
 public void setRowSeparatorChar(char rowSeparatorChar)
Set character used to separate rows in String representation of a Table

 o setColumnSeparatorChar
 public void setColumnSeparatorChar(char columnSeparatorChar)
Set character used to separate rows in String representation of a Table

 o indexOf
 public synchronized Point indexOf(Object element)
Searches for the specified object, in row order.

Returns:
java.awt.Point x is row location, y is column location, -1 indicates object not found
 o contains
 public boolean contains(Object element)
Returns true if the specified object is in the table

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

Overrides:
clone in class Object
 o elementAt
 public synchronized Object elementAt(int row,
                                      int column) throws ArrayIndexOutOfBoundsException
Returns the object in table at given row and column.

Throws: ArrayIndexOutOfBoundsException
thrown if row or column is not a valid index
 o rowAt
 public synchronized Vector rowAt(int row) throws ArrayIndexOutOfBoundsException
Returns the given row in the table

Throws: ArrayIndexOutOfBoundsException
thrown if row is not a valid index
 o columnAt
 public synchronized Vector columnAt(int column) throws ArrayIndexOutOfBoundsException
Returns the given column in the table

Throws: ArrayIndexOutOfBoundsException
thrown if column is not a valid index
 o columnsAt
 public synchronized Table columnsAt(int startColumn,
                                     int endColumn) throws ArrayIndexOutOfBoundsException
Creates a new table with the specified columns of current table

Throws: ArrayIndexOutOfBoundsException
thrown if startColumn or endColumn is not a valid column index
 o columnsAt
 public synchronized Table columnsAt(Object key,
                                     int row) throws ArrayIndexOutOfBoundsException
Creates a new table containing all the columns that have the value key in the indicated row

Throws: ArrayIndexOutOfBoundsException
thrown if row is not a valid row 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 startRow or endRow is not a valid row index
 o rowsAt
 public synchronized Table rowsAt(Object key,
                                  int column) throws ArrayIndexOutOfBoundsException
Returns a new table containing all the rows that have the value key in the indicated column

Throws: ArrayIndexOutOfBoundsException
thrown if column is not a valid index
 o elements
 public synchronized Enumeration elements()
Returns an enumeration of the non-null elements in row order.

 o setElementAt
 public synchronized void setElementAt(Object data,
                                       int row,
                                       int column) throws ArrayIndexOutOfBoundsException
Places the object in table at given row and column

Throws: ArrayIndexOutOfBoundsException
thrown if row or column is not a valid index
 o addRow
 public synchronized void addRow(Vector newRow)
Add a new row to the end of the Table. If newRow has more elements than the table has columns, more columns are added to the table.

Parameters:
newRow - vector of item added to the new row
 o addRows
 public synchronized void addRows(Table newRows)
Add table "newRows" at the bottom of the Table. Table grows to include all elements of newRows

Parameters:
newRows - table to add to bottom
 o insertRowsAt
 public synchronized void insertRowsAt(Table newRows,
                                       int startIndex) throws ArrayIndexOutOfBoundsException
Insert table "newRows" in the Table. "newRows" is inserted at row "startIndex" of current table. The row "startIndex" prior to the insert will follow the newly added rows Table grows to include all elements of newRows

Parameters:
startIndex - the first row of newRows becomes row startIndex in current table
Throws: ArrayIndexOutOfBoundsException
thrown if startIndex is not a valid row index
 o addColumn
 public synchronized void addColumn(Vector newColumn)
Add a new column to the end of the Table. If newColumn has more elements than the table has rows, more rows are added to the table.

Parameters:
newColumn - vector of item added to the new column
 o addColumns
 public synchronized void addColumns(Table newColumns)
Add a table as new columns.

Parameters:
newColumns - table to add
 o insertColumnsAt
 public synchronized void insertColumnsAt(Table newColumns,
                                          int startIndex) throws ArrayIndexOutOfBoundsException
Insert table "newColumns" in the Table. "newColumns" is inserted at column "startIndex" of current table. The column "startIndex" prior to the insert will follow the newly added columns Table grows to include all elements of newColumns

Parameters:
startIndex - the first column of newColumns becomes column startIndex in current table
Throws: ArrayIndexOutOfBoundsException
thrown if startIndex is not a valid column index
 o removeRowAt
 public synchronized void removeRowAt(int rowIndex) throws ArrayIndexOutOfBoundsException
Removes the indicated row from the table

Throws: ArrayIndexOutOfBoundsException
thrown if rowIndex is not a valid row index
 o removeRowsAt
 public synchronized void removeRowsAt(int firstRow,
                                       int endRow) throws ArrayIndexOutOfBoundsException
Removes the indicated rows from the table

Throws: ArrayIndexOutOfBoundsException
thrown if firstRow > endRow, or either firstRow or endRow are not a valid row index
 o removeRowsAt
 public synchronized void removeRowsAt(Object key,
                                       int column) 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 column is not a valid column index
Throws: NullPointerException
thrown if key is null
 o removeColumnAt
 public synchronized void removeColumnAt(int columnIndex) throws ArrayIndexOutOfBoundsException
Removes the indicated column from the table

Throws: ArrayIndexOutOfBoundsException
thrown if columnIndex is not a valid column index
 o removeColumnsAt
 public synchronized void removeColumnsAt(int firstColumn,
                                          int endColumn) throws ArrayIndexOutOfBoundsException
Removes the indicated columns from the table

Throws: ArrayIndexOutOfBoundsException
thrown if firstColumn > endColumn, or either firstColumn or endColumn are not a valid column index
 o removeColumnsAt
 public synchronized void removeColumnsAt(Object key,
                                          int row) 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 row index
Throws: NullPointerException
thrown if key is null
 o size
 public int size()
Return the number of items in the table

 o numberOfColumns
 public int numberOfColumns()
Returns the number of columns that can currently be accessed

 o numberOfRows
 public int numberOfRows()
Returns the number of rows that can currently be accessed

 o toString
 public String toString()
Converts a Table to a String.

Overrides:
toString in class Object
 o toString
 public synchronized String toString(String header)
Converts a Table to a String with given header information.

 o save
 public synchronized void save(OutputStream out,
                               String header)
Writes ascii representation of a Table to Outputstream

 o load
 public synchronized void load(InputStream in) throws IOException
Loads a Table from an inputstream. Data in stream must be in Table format.

Throws: IOException
thrown if there is a error in reading
 o fromString
 public synchronized void fromString(String tableString) throws IOException
Loads a Table from a string. Data in stream must be in Table format.

Throws: IOException
thrown if there is a error reading the tableString format

All Packages  Class Hierarchy  This Package  Previous  Next  Index