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
-
Table()
- Create a new table with no rows and no columns
-
Table(int, int)
- Create a new table with given number of rows and columns.
-
addColumn(Vector)
- Add a new column to the end of the Table.
-
addColumns(Table)
- Add a table as new columns.
-
addRow(Vector)
- Add a new row to the end of the Table.
-
addRows(Table)
- Add table "newRows" at the bottom of the Table.
-
clone()
- Clones this table.
-
columnAt(int)
- Returns the given column in the table
-
columnsAt(int, int)
- Creates a new table with the specified columns of current table
-
columnsAt(Object, int)
- Creates a new table containing all the columns that have the value key in the indicated row
-
contains(Object)
- Returns true if the specified object is in the table
-
elementAt(int, int)
- Returns the object in table at given row and column.
-
elements()
- Returns an enumeration of the non-null elements in row order.
-
fromColumnVector(Vector)
- Create a table using the vector column as the only column in the table
-
fromRowVector(Vector)
- Create a table using the vector row as the only row in the table
-
fromString(String)
- Loads a Table from a string.
-
indexOf(Object)
- Searches for the specified object, in row order.
-
insertColumnsAt(Table, int)
- Insert table "newColumns" in the Table.
-
insertRowsAt(Table, int)
- Insert table "newRows" in the Table.
-
load(InputStream)
- Loads a Table from an inputstream.
-
numberOfColumns()
- Returns the number of columns that can currently be accessed
-
numberOfRows()
- Returns the number of rows that can currently be accessed
-
removeColumnAt(int)
- Removes the indicated column from the table
-
removeColumnsAt(int, int)
- Removes the indicated columns from the table
-
removeColumnsAt(Object, int)
- Removes the indicated columns that have key in the indicated row
-
removeRowAt(int)
- Removes the indicated row from the table
-
removeRowsAt(int, int)
- Removes the indicated rows from the table
-
removeRowsAt(Object, int)
- Removes the indicated rows that have key in the indicated column
-
rowAt(int)
- Returns the given row in the table
-
rowsAt(int, int)
- Creates a new table with the specified rows of current table
-
rowsAt(Object, int)
- Returns a new table containing all the rows that have the value key in the indicated column
-
save(OutputStream, String)
- Writes ascii representation of a Table to Outputstream
-
setColumnSeparatorChar(char)
- Set character used to separate rows in String representation of a Table
-
setElementAt(Object, int, int)
- Places the object in table at given row and column
-
setRowSeparatorChar(char)
- Set character used to separate rows in String representation of a Table
-
setTokenCharacters(TokenCharacters)
- Sets TokenCharacters used to convert Table from/to strings/streams.
-
size()
- Return the number of items in the table
-
toString()
- Converts a Table to a String.
-
toString(String)
- Converts a Table to a String with given header information.
Table
public Table()
- Create a new table with no rows and no columns
Table
public Table(int initNumberOfRows,
int initNumberOfColumns)
- Create a new table with given number of rows and columns. All elements are
set to null.
fromRowVector
public static Table fromRowVector(Vector row)
- Create a table using the vector row as the only row in the table
fromColumnVector
public static Table fromColumnVector(Vector column)
- Create a table using the vector column as the only column in the table
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.
setRowSeparatorChar
public void setRowSeparatorChar(char rowSeparatorChar)
- Set character used to separate rows in String representation of a Table
setColumnSeparatorChar
public void setColumnSeparatorChar(char columnSeparatorChar)
- Set character used to separate rows in String representation of a Table
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
contains
public boolean contains(Object element)
- Returns true if the specified object is in the table
clone
public synchronized Object clone()
- Clones this table. The elements are not cloned.
- Overrides:
- clone in class Object
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
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
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
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
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
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
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
elements
public synchronized Enumeration elements()
- Returns an enumeration of the non-null elements in row order.
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
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
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
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
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
addColumns
public synchronized void addColumns(Table newColumns)
- Add a table as new columns.
- Parameters:
- newColumns - table to add
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
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
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
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
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
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
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
size
public int size()
- Return the number of items in the table
numberOfColumns
public int numberOfColumns()
- Returns the number of columns that can currently be accessed
numberOfRows
public int numberOfRows()
- Returns the number of rows that can currently be accessed
toString
public String toString()
- Converts a Table to a String.
- Overrides:
- toString in class Object
toString
public synchronized String toString(String header)
- Converts a Table to a String with given header information.
save
public synchronized void save(OutputStream out,
String header)
- Writes ascii representation of a Table to Outputstream
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
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