SL-GMS Enterprise RTView Customization

com.sl.gmsjrt
Class GmsTabularData

java.lang.Object
  extended by com.sl.gmsjrt.GmsTabularData
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class GmsTabularData
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The GmsTabularData is a 2 dimensional data type. This class allows you to populate a table of data.

See Also:
Serialized Form

Field Summary
static int BOOLEAN
          java.lang.Boolean column type
static java.util.ArrayList customPatterns
          A collection of custom, user-defined patterns for parsing dates and times.
static int DATE
          date column type, stored as long
static boolean debugDateConversions
          A flag to enable the output of debugging information during date conversions.
static int DOUBLE
          java.lang.Double column type
static int FLOAT
          java.lang.Float column type
static int growthFactor
          Percent growth of arrays on overflow.
static int INTEGER
          java.lang.Integer column type
static int LONG
          java.lang.Long column type
static long NULL_DATE
          The number value used to represent an unspecified date.
static java.lang.String NULL_DATE_STRING
          The string used to represent an unspecified date.
static int STRING
          java.lang.String column type
 
Constructor Summary
GmsTabularData()
          Create a new GmsTabularData with default initial size of 10.
 
Method Summary
 void addColumn(java.lang.String name, int type)
          Add a column with the specified name and type.
 void addRow(java.lang.String rowName)
          Add a row with the specified name.
 GmsTabularData appendData(GmsTabularData newData)
          Append all of the rows from another table to this table.
 java.lang.Object clone()
          Clones the GmsTabularData and the data arrays.
 GmsTabularData cloneStructure()
          Clones the GmsTabularData column structure only.
 boolean columnContainsNumericStrings(int column)
          Find out if the specified column contains strings that are actually numbers.
 int compareRowsByColumn(int row1, int row2, int column, boolean isNumericStringColumn)
          Compare the values of the cells specified by row1 and row2 in the given column.
 void copyCellValue(int destRow, int destCol, GmsTabularData srcTable, int srcRow, int srcCol)
          Copy a value from a cell in another table to a cell in this table, converting the value to the correct type if necessary.
static void copyRowData(GmsTabularData destTable, int destRow, GmsTabularData srcTable, int srcRow, boolean columnOrderMatch, boolean keepDestRowData)
          Copy one row of data from the source table to the destination table.
static long dateStringToLong(java.lang.String dateString)
          Convert the given formatted date string into a number of milliseconds since epoch.
static long dateStringToLong2(java.lang.String dateString)
          Convert the given formatted date string into a number of milliseconds since epoch.
 boolean equals(java.lang.Object obj)
          Returns true if this table is equal to the specified table.
 boolean getBooleanCellValue(int row, int column)
          Get the boolean value of a table cell at the given row and column.
 java.lang.String getCellValue(int row, int column)
          Get the string value of a table cell at the given row and column.
 java.lang.Object getCellValueObject(int row, int col)
           
 int getColumnIndex(java.lang.String column)
          Return a column index, given the selected column name.
 int[] getColumnIndexArray(java.lang.String[] columnNames)
          Return a column index array, given an array of column names.
 java.lang.String getColumnName(int col)
           
 java.lang.String[] getColumnNames()
          Returns an array of strings containing the column names.
 int getColumnTypeCode(int col)
           
 int[] getColumnTypeCodes()
          Returns an array of ints containing the column type codes.
 long getDateCellValue(int row, int column)
          Get the long value of a table cell at the given row and column.
 double getDoubleCellValue(int row, int column)
          Get the double value of a table cell at the given row and column.
 float getFloatCellValue(int row, int column)
          Get the float value of a table cell at the given row and column.
 int getIntCellValue(int row, int column)
          Get the integer value of a table cell at the given row and column.
 long getLongCellValue(int row, int column)
          Get the long value of a table cell at the given row and column.
 int getNumColumns()
          Returns the number of columns.
 int getNumRows()
          Returns the number of rows.
 java.util.Hashtable getRowIndexHashtable(java.util.Hashtable rowHash, int[] indCols)
          Returns a hashtable of row indexes hashed by the row identifier based on the specified index columns.
 java.lang.String getRowName(int row)
           
 java.lang.String[] getRowNames()
          Returns an array of strings containing the row names.
 void insertColumnAt(java.lang.String name, int type, int index)
          Insert a column with the specified name and type at the specified index.
 GmsTabularData insertData(GmsTabularData newData, int topFlag)
          Creates a new GmsTabularData with the specified table inserted into a this GmsTabularData.
 void insertRowAt(java.lang.String rowName, int index)
          Insert a row with the specified name at the specified index.
 boolean isColumnNumeric(int column)
          Find out if the specified column contains numbers or numeric strings.
static boolean isNullDate(double msec)
          Return true if the argument value represents NULL_DATE
static boolean isNullDate(long msec)
          Return true if the argument value represents NULL_DATE
static boolean isNullDateString(java.lang.String dateString)
          Return true if the argument value represents NULL_DATE_STRING
 GmsTabularData newColumnSubset(java.lang.String[] columns)
          Create a new GmsTabularData by copying the contents of an existing one.
 GmsTabularData newRowSubset(int firstRow, int lastRow)
          Return a new table containing rows from this table, from firstRow to lastRow, inclusive.
 GmsTabularData newRowSubset(java.lang.String colStr, java.lang.String filter)
          Create a new GmsTabularData by copying the contents of an existing one.
 GmsTabularData newRowSubset(java.lang.String colStr, java.lang.String filter, int firstRow, int lastRow)
           
 void removeAllRows()
          Remove all rows in the table.
 void removeRowAt(int index)
          Remove the row at the specified index.
 void removeRowsAt(int startIndex, int count)
          Remove multiple consecutive rows.
 void setCellValue(boolean value, int row, int column)
          Set the boolean value of a table cell at the given row and column.
 void setCellValue(double value, int row, int column)
          Set the double value of a table cell at the given row and column.
 void setCellValue(float value, int row, int column)
          Set the float value of a table cell at the given row and column.
 void setCellValue(int value, int row, int column)
          Set the integer value of a table cell at the given row and column.
 void setCellValue(long value, int row, int column)
          Set the long value of a table cell at the given row and column.
 void setCellValue(java.lang.String value, int row, int column)
          Set the string value of a table cell at the given row and column.
 void setDateCellValue(long value, int row, int column)
          Set the date value of a table cell at the given row and column.
 void setDateCellValue(java.lang.String value, int row, int column)
          Set the date value of a table cell at the given row and column.
 void sortRows()
          Sorts the rows in this GmsTabularData alphabetically by row name.
 void sortRows(int column, boolean ascending)
          Sort the rows in this GmsTabularData.
 java.lang.String toString()
          Overrides default toString.
 boolean validateColumnNames(java.lang.String names)
          Accept a semicolon-separated list of names and return true if all the names are valid column names.
static boolean validateColumnNames(java.lang.String names, java.lang.String[] columns)
          Accept a semicolon-separated list of names and a reference list of column names and return true if all the names are found in the reference list.
 boolean validateFilterValues(java.lang.String names, java.lang.String values)
          Accept a semicolon-separated list of column names and a nested list of filter values in the form v1,v2;v3,v4 where each semicolon-separated set of values is associated with the corresponding column.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOOLEAN

public static final int BOOLEAN
java.lang.Boolean column type

See Also:
Constant Field Values

customPatterns

public static java.util.ArrayList customPatterns
A collection of custom, user-defined patterns for parsing dates and times.


DATE

public static final int DATE
date column type, stored as long

See Also:
Constant Field Values

debugDateConversions

public static boolean debugDateConversions
A flag to enable the output of debugging information during date conversions.


DOUBLE

public static final int DOUBLE
java.lang.Double column type

See Also:
Constant Field Values

FLOAT

public static final int FLOAT
java.lang.Float column type

See Also:
Constant Field Values

growthFactor

public static int growthFactor
Percent growth of arrays on overflow. Default is 25.


INTEGER

public static final int INTEGER
java.lang.Integer column type

See Also:
Constant Field Values

LONG

public static final int LONG
java.lang.Long column type

See Also:
Constant Field Values

NULL_DATE

public static final long NULL_DATE
The number value used to represent an unspecified date.

See Also:
Constant Field Values

NULL_DATE_STRING

public static final java.lang.String NULL_DATE_STRING
The string used to represent an unspecified date.

See Also:
Constant Field Values

STRING

public static final int STRING
java.lang.String column type

See Also:
Constant Field Values
Constructor Detail

GmsTabularData

public GmsTabularData()
Create a new GmsTabularData with default initial size of 10.

Method Detail

addColumn

public void addColumn(java.lang.String name,
                      int type)
Add a column with the specified name and type. All columns must be added before adding rows.

Parameters:
name - column name. This is used in the column header
type - column type. Valid arguments are INTEGER, LONG, DOUBLE, STRING, FLOAT, DATE and BOOLEAN.

addRow

public void addRow(java.lang.String rowName)
Add a row with the specified name. This method should not be called until all columns have been added. This method validates the data arrays. The length of each data array is validated against the current number of rows. If the arrays are too short, the existing data in each array will be copied to a new longer array. The length of the new arrays will be determined by the growthFactor variable.

The row names are used in the removeRow and mergeData methods.

Parameters:
rowName - row name. May be null or an empty string.

appendData

public GmsTabularData appendData(GmsTabularData newData)
Append all of the rows from another table to this table. The other table is not modified. The number and type of columns in both tables should match exactly. If they do not, an empty row is added to this table for each row in the other table. No checks are done for duplicate row names.

Parameters:
newData - the table whose rows are to be appended
Returns:
a reference to this table

clone

public java.lang.Object clone()
Clones the GmsTabularData and the data arrays.

Overrides:
clone in class java.lang.Object

cloneStructure

public GmsTabularData cloneStructure()
Clones the GmsTabularData column structure only.


columnContainsNumericStrings

public boolean columnContainsNumericStrings(int column)
Find out if the specified column contains strings that are actually numbers.

Parameters:
column - the column to test
Returns:
true if the column contains numeric string data

compareRowsByColumn

public int compareRowsByColumn(int row1,
                               int row2,
                               int column,
                               boolean isNumericStringColumn)
Compare the values of the cells specified by row1 and row2 in the given column. This routine will return -1 if the row1 value is less than the row2 value, 1 if the row1 value is greater than the row2 value, and 0 if the values are equal.

Parameters:
row1 - the row index for the first cell to compare
row2 - the row index for the second cell to compare
column - the column index for both cells
isNumericStringColumn - set this to true if the column contains all numeric strings and you want to compare the strings as numbers
Returns:
-1 if row1 < row2, 0 if row1 == row2, 1 if row1 > row2

copyCellValue

public void copyCellValue(int destRow,
                          int destCol,
                          GmsTabularData srcTable,
                          int srcRow,
                          int srcCol)
Copy a value from a cell in another table to a cell in this table, converting the value to the correct type if necessary.

Parameters:
destRow - The row of the cell in this table to which the value should be copied.
destCol - The column of the cell in this table to which the value should be copied.
srcTable - The table from which the value should be copied.
srcRow - The row of the cell in srcTable from which the value should be copied.
srcCol - The column of the cell in srcTable from which the value should be copied.

copyRowData

public static void copyRowData(GmsTabularData destTable,
                               int destRow,
                               GmsTabularData srcTable,
                               int srcRow,
                               boolean columnOrderMatch,
                               boolean keepDestRowData)
Copy one row of data from the source table to the destination table.

Parameters:
destTable - the destination table
destRow - the row index in the destTable. Must be a valid row index for destTable, so addRow() must be called first when using this method to copy data to a new row.
srcTable - the source table
srcRow - the row index in the srcTable
columnOrderMatch - Set this to true if both tables have the same number and type of columns. If false, then for each column in destTable this method will try to find a column in srcTable with the same name.
keepDestRowData - If false, then for each column in destTable that is not found in srcTable, set the value of that column in destRow to zero (for numeric columns) or an empty string (for string columns). If true, don't change the value of the column in destRow.

dateStringToLong

public static long dateStringToLong(java.lang.String dateString)
                             throws java.text.ParseException
Convert the given formatted date string into a number of milliseconds since epoch. Throw ParseException if string can't be converted.

Parameters:
dateString - the formatted date string
Returns:
milliseconds since epoch
Throws:
java.text.ParseException - if the specified date string is invalid.

dateStringToLong2

public static long dateStringToLong2(java.lang.String dateString)
Convert the given formatted date string into a number of milliseconds since epoch. Return NULL_DATE if string can't be converted.

Parameters:
dateString - the formatted date string
Returns:
milliseconds since epoch or NULL_DATE if invalid.

equals

public boolean equals(java.lang.Object obj)
Returns true if this table is equal to the specified table. Two tables are considered equal if: - both tables have the same number of columns - the type of each column is the same in both tables - both tables have the same number of rows - the value of each cell in the first table equals the value of the corresponding cell in the second table - each row name in the first table equals the corresponding row name in the second table

Overrides:
equals in class java.lang.Object

getBooleanCellValue

public boolean getBooleanCellValue(int row,
                                   int column)
Get the boolean value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getCellValue

public java.lang.String getCellValue(int row,
                                     int column)
Get the string value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getCellValueObject

public java.lang.Object getCellValueObject(int row,
                                           int col)

getColumnIndex

public int getColumnIndex(java.lang.String column)
Return a column index, given the selected column name. If no selected column, return -1

Parameters:
column - column name

getColumnIndexArray

public int[] getColumnIndexArray(java.lang.String[] columnNames)
Return a column index array, given an array of column names.

Parameters:
columnNames - array of column names
Returns:
An array of column indexes corresponding to the column names. The returned array will contain -1 for an element if no column exists with the name specified in the corresponding element in the columnNames array. A null is returned if columnNames is null or empty.

getColumnName

public java.lang.String getColumnName(int col)

getColumnNames

public java.lang.String[] getColumnNames()
Returns an array of strings containing the column names. This array may be larger than the actual number of columns. Do not use the size of this array to determine the number of columns. Use getNumColumns() instead.


getColumnTypeCode

public int getColumnTypeCode(int col)

getColumnTypeCodes

public int[] getColumnTypeCodes()
Returns an array of ints containing the column type codes. Each element is an integer representing the type. This array may be larger than the actual number of columns. Do not use the size of this array to determine the number of columns. Use getNumColumns() instead.


getDateCellValue

public long getDateCellValue(int row,
                             int column)
Get the long value of a table cell at the given row and column. If the column type is STRING, use dateStringToLong() to convert it to a long.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getDoubleCellValue

public double getDoubleCellValue(int row,
                                 int column)
Get the double value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getFloatCellValue

public float getFloatCellValue(int row,
                               int column)
Get the float value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getIntCellValue

public int getIntCellValue(int row,
                           int column)
Get the integer value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getLongCellValue

public long getLongCellValue(int row,
                             int column)
Get the long value of a table cell at the given row and column.

Parameters:
row - the row index
column - the column index
Returns:
the cell value

getNumColumns

public int getNumColumns()
Returns the number of columns.


getNumRows

public int getNumRows()
Returns the number of rows.


getRowIndexHashtable

public java.util.Hashtable getRowIndexHashtable(java.util.Hashtable rowHash,
                                                int[] indCols)
Returns a hashtable of row indexes hashed by the row identifier based on the specified index columns. If the rowHash is not null, it will be cleared and populated. If it is null, a new Hashtable will be created.

rowHash the Hashtable to populate. If null, create a new Hashtable. indCols and array of column indexes to use as index columns


getRowName

public java.lang.String getRowName(int row)

getRowNames

public java.lang.String[] getRowNames()
Returns an array of strings containing the row names. This array may be larger than the actual number of rows. Do not use the size of this array to determine the number of rows. Use getNumRows() instead.


insertColumnAt

public void insertColumnAt(java.lang.String name,
                           int type,
                           int index)
Insert a column with the specified name and type at the specified index.

Parameters:
name - column name. This is used in the column header
type - column type. Valid arguments are GmsTabularData.STRING, INTEGER, LONG, DOUBLE, FLOAT, DATE, BOOLEAN.
index - column index. The index at which to insert the column. Index values start at zero.

insertData

public GmsTabularData insertData(GmsTabularData newData,
                                 int topFlag)
Creates a new GmsTabularData with the specified table inserted into a this GmsTabularData.

Parameters:
newData - GmsTabularData to insert into this GmsTabularData
topFlag - if greater than 0, insert the new rows at the beginning, otherwise, insert them at the end.

insertRowAt

public void insertRowAt(java.lang.String rowName,
                        int index)
Insert a row with the specified name at the specified index.

This method validates the data arrays. The length of each data array is validated against the current number of rows. If the arrays are too short, the existing data in each array will be copied to a new longer array. The length of the new arrays will be determined by the growthFactor variable.

The row names are used in the removeRow and mergeData methods.

Parameters:
rowName - row name. May be null or an empty string.
index - The index at which to insert the new row. Index values start at zero.

isColumnNumeric

public boolean isColumnNumeric(int column)
Find out if the specified column contains numbers or numeric strings.

Parameters:
column - the column to test
Returns:
true if the column contains numeric data

isNullDate

public static boolean isNullDate(double msec)
Return true if the argument value represents NULL_DATE


isNullDate

public static boolean isNullDate(long msec)
Return true if the argument value represents NULL_DATE


isNullDateString

public static boolean isNullDateString(java.lang.String dateString)
Return true if the argument value represents NULL_DATE_STRING


newColumnSubset

public GmsTabularData newColumnSubset(java.lang.String[] columns)
Create a new GmsTabularData by copying the contents of an existing one. Select a subset of the columns to include. If the columns specified are null or exactly match the columns in this GmsTabularData, this GmsTabularData will be returned. Otherwise a new GmsTabularData is returned, but for efficiency the new GmsTabularData shares the data arrays for the specified columns with this GmsTabularData. Changes to cells in those columns will thus affect both tables. If the caller requires a table that is independent of the original table, it should call clone() on the returned table.

Parameters:
columns - array of the names of the columns in this table to be included in the returned table

newRowSubset

public GmsTabularData newRowSubset(int firstRow,
                                   int lastRow)
Return a new table containing rows from this table, from firstRow to lastRow, inclusive. All columns are copied to the new table. Note that if firstRow = 0 and lastRow = this.getNumRows() - 1, this method is equivalent to clone().

Parameters:
firstRow - index of first row to be copied. If less than zero, zero is used instead.
lastRow - index of last row to be copied. If greater than this.getNumRows() - 1, then this.getNumRows() - 1 is used instead.
Returns:
the new table

newRowSubset

public GmsTabularData newRowSubset(java.lang.String colStr,
                                   java.lang.String filter)
Create a new GmsTabularData by copying the contents of an existing one. The returned GmsTabularData will only include rows in which the contents of the specified column match the specified filter. If the specified column and filter are null or if * is specified for the filter, this GmsTabularData is returned.

Parameters:
colStr - the name(s) of the filter column(s).
filter - the filter value. This can be single value to match in a single filter column or a nested list in the form v1,v2;v3,v4 to match multiple filter values in each of multiple columns.

newRowSubset

public GmsTabularData newRowSubset(java.lang.String colStr,
                                   java.lang.String filter,
                                   int firstRow,
                                   int lastRow)

removeAllRows

public void removeAllRows()
Remove all rows in the table.


removeRowAt

public void removeRowAt(int index)
Remove the row at the specified index.

This method removes a row immediately.

Parameters:
index - The index of the row to remove. Index values start at zero.

removeRowsAt

public void removeRowsAt(int startIndex,
                         int count)
Remove multiple consecutive rows.

Parameters:
startIndex - The index of the first row to remove.
count - The number of rows to remove.

setCellValue

public void setCellValue(boolean value,
                         int row,
                         int column)
Set the boolean value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setCellValue

public void setCellValue(double value,
                         int row,
                         int column)
Set the double value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setCellValue

public void setCellValue(float value,
                         int row,
                         int column)
Set the float value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setCellValue

public void setCellValue(int value,
                         int row,
                         int column)
Set the integer value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setCellValue

public void setCellValue(long value,
                         int row,
                         int column)
Set the long value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setCellValue

public void setCellValue(java.lang.String value,
                         int row,
                         int column)
Set the string value of a table cell at the given row and column.

Parameters:
value - the value
row - the row index
column - the column index

setDateCellValue

public void setDateCellValue(long value,
                             int row,
                             int column)
Set the date value of a table cell at the given row and column.

Parameters:
value - the date value as a number of milliseconds since epoch
row - the row index
column - the column index

setDateCellValue

public void setDateCellValue(java.lang.String value,
                             int row,
                             int column)
Set the date value of a table cell at the given row and column.

Parameters:
value - the date value as a formatted string
row - the row index
column - the column index

sortRows

public void sortRows()
Sorts the rows in this GmsTabularData alphabetically by row name.


sortRows

public void sortRows(int column,
                     boolean ascending)
Sort the rows in this GmsTabularData.

Parameters:
column - The index of the column to use for sorting. Column index values start at zero. If -1 is specified, the row names are used.
ascending - If true, sort in ascending order, else in descending order.


toString

public java.lang.String toString()
Overrides default toString.

Overrides:
toString in class java.lang.Object

validateColumnNames

public boolean validateColumnNames(java.lang.String names)
Accept a semicolon-separated list of names and return true if all the names are valid column names.

Parameters:
names - a single column name or semicolon-separated list
Returns:
true if all the names are valid column names, else false

validateColumnNames

public static boolean validateColumnNames(java.lang.String names,
                                          java.lang.String[] columns)
Accept a semicolon-separated list of names and a reference list of column names and return true if all the names are found in the reference list.

Parameters:
names - a single column name or semicolon-separated list
columns - a list of column names to use as reference
Returns:
true if all the names are found in the reference list, else false

validateFilterValues

public boolean validateFilterValues(java.lang.String names,
                                    java.lang.String values)
Accept a semicolon-separated list of column names and a nested list of filter values in the form v1,v2;v3,v4 where each semicolon-separated set of values is associated with the corresponding column. Return true only if: (1) all the column names are valid, (2) there are the same number of column names and filter value sets, and (3) in each filter value set, the values can be converted to the type of the corresponding column.

Parameters:
names - a single column name or semicolon-separated list
values - a nested list of filter value sets corresponding to the column names
Returns:
true if all the above conditions are met, else false

SL-GMS Enterprise RTView Customization

Copyright 2009 Sherrill-Lubinski Corporation, 240 Tamal Vista Blvd
Corte Madera, CA 94925, U.S.A. All Rights Reserved