com.wm.util
Class Table

java.lang.Object
  extended by com.wm.util.Table
All Implemented Interfaces:
Codable

public final class Table
extends java.lang.Object
implements Codable

This class provides a table data structure as a more efficient alternative to using Values arrays. It can be coded to XML and readily converted to and from Values arrays but deals with data in terms of rows and columns.


Field Summary
 java.lang.String[] cols
           
 java.lang.String name
           
 java.util.Vector rows
           
 java.lang.String[] sizes
           
 
Constructor Summary
Table()
          Empty constructor.
Table(java.lang.String[] cols)
          Initializes a table object with column names.
Table(java.lang.String name, java.lang.String[] cols)
          Initializes a table object with a name and column names.
Table(java.lang.String name, java.lang.String[] cols, java.lang.String[] sizes)
          Initializes a table object with a name, a set of column names and the corresponding sizes of each column.
 
Method Summary
 void addRow(java.lang.Object[] o)
          Adds a row to this table.
 void addRow(Values v)
          Converts a Values object into a row and adds it to this table.
 void appendRows(Values[] v)
          Converts a Values[] into rows and appends the rows to this table.
 void deleteRow(int idx)
          Deletes the row at the specified index from this table.
 java.lang.String[] getColumnNames()
          Gets the column names of this table.
 IData getIData()
          Converts this table into an IData object.
 Values getRow(int idx)
          Gets the row at the given index as a Values object.
 int getRowCount()
          Returns the current number of rows in this table.
 java.lang.Object getValue(java.lang.String key)
          Implements the Codable interface.
 java.lang.String[] getValueKeys()
          Implements the Codable interface
 Values[] getValues()
          Retrieves all rows of this table and returns them as a Values[], where each element in the array corresponds to a row in this table.
 void insertRow(int idx, Values v)
          Converts a Values object into a row and inserts it at the given index this table.
 void setIData(IData id)
          Initializes this Table object from an IData object.
 void setRows(Values[] v)
          Converts a Values[] into rows that are appended to this table.
 void setValue(java.lang.String key, java.lang.Object value)
          Implements the Codable interface.
 java.lang.String toString()
          Retrieves the table schema and content as a string for display purposes.
 Values toValues()
          Converts this table into a Values object.
 void updateRow(int idx, Values v)
          Replaces a row at the given index with elements defined in a Values object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name

cols

public java.lang.String[] cols

sizes

public java.lang.String[] sizes

rows

public java.util.Vector rows
Constructor Detail

Table

public Table()
Empty constructor. If this constructor is used, the columns must be set before attempting to use the newly created table.


Table

public Table(java.lang.String[] cols)
Initializes a table object with column names.

Parameters:
cols - column names of the new table object.

Table

public Table(java.lang.String name,
             java.lang.String[] cols)
Initializes a table object with a name and column names.

Parameters:
name - name of the new table object.
cols - column names of the new table object.

Table

public Table(java.lang.String name,
             java.lang.String[] cols,
             java.lang.String[] sizes)
Initializes a table object with a name, a set of column names and the corresponding sizes of each column.

Parameters:
name - name of the new table object.
cols - column names of the new table object.
sizes - size of each column for the new table object.
Method Detail

addRow

public void addRow(Values v)
Converts a Values object into a row and adds it to this table.

Parameters:
v - Values object to add as a row of data.

addRow

public void addRow(java.lang.Object[] o)
Adds a row to this table. Each element in the Object[] passed in expected to exactly match the column ordering of this table.

Parameters:
o - array of Objects to be added.

deleteRow

public void deleteRow(int idx)
Deletes the row at the specified index from this table.

Parameters:
idx - index of row to remove.

updateRow

public void updateRow(int idx,
                      Values v)
Replaces a row at the given index with elements defined in a Values object.

Parameters:
idx - index of row to be replaced.
v - new row values.

insertRow

public void insertRow(int idx,
                      Values v)
Converts a Values object into a row and inserts it at the given index this table.

Parameters:
idx - index to insert new row.
v - row values to insert.

getColumnNames

public java.lang.String[] getColumnNames()
Gets the column names of this table.

Returns:
array of Strings representing column names.

getRow

public Values getRow(int idx)
Gets the row at the given index as a Values object. The resulting Values object contains keys correlating to each column. in this table.

Parameters:
idx - index of row to retrieve.
Returns:
Values object representation of the row.

getValues

public Values[] getValues()
Retrieves all rows of this table and returns them as a Values[], where each element in the array corresponds to a row in this table.

Returns:
array of Values objects.

toValues

public Values toValues()
Converts this table into a Values object. The resulting Values object contains the following keys:
   name - name of the table as String
   data - table content as Values[]
   cols - column names as String[]
   sizes - table size array as String[]
 

Returns:
Values object representation of this table.

appendRows

public void appendRows(Values[] v)
Converts a Values[] into rows and appends the rows to this table.

Parameters:
v - array of Values objects to add to this table.

setRows

public void setRows(Values[] v)
Converts a Values[] into rows that are appended to this table.

Parameters:
v - array of Values objects to add to this table.
See Also:
appendRows(Values[])

getRowCount

public int getRowCount()
Returns the current number of rows in this table.

Returns:
number of rows.

toString

public java.lang.String toString()
Retrieves the table schema and content as a string for display purposes.

Overrides:
toString in class java.lang.Object
Returns:
string representation of this table.

getIData

public IData getIData()
Converts this table into an IData object. The resulting IData object contains the following keys:
   name - name of the table as String
   data - table content as Values[]
   cols - column names as String[]
   sizes - table size array as String[]
 

Returns:
IData object representation of this table.

setIData

public void setIData(IData id)
Initializes this Table object from an IData object.

Parameters:
id - IData object from which this Table will be initialized. The IData must contain the following keys:
  name - name of the table as String
  data - table content as Values[] (if generated by 6.0.1)
  rows - table contents as a Vector of Object[]'s. (all other releases)
  cols - column names as String[]
  sizes - table size array as String[]
 

getValue

public java.lang.Object getValue(java.lang.String key)
Implements the Codable interface. Valid key values are:

Specified by:
getValue in interface Codable
Parameters:
key - name of value to retrieve.
Returns:
object value of the corresponding key. s
See Also:
Codable.getValue(java.lang.String)

setValue

public void setValue(java.lang.String key,
                     java.lang.Object value)
Implements the Codable interface. Valid key values are:

Specified by:
setValue in interface Codable
Parameters:
key - name of value to set.
value - object value to set.
See Also:
Codable.setValue(java.lang.String, java.lang.Object)

getValueKeys

public java.lang.String[] getValueKeys()
Implements the Codable interface

Specified by:
getValueKeys in interface Codable
Returns:
array of Strings representing valid keys.
See Also:
setValue(java.lang.String, java.lang.Object), Codable.getValueKeys()