O2Plib.table
Class Table

java.lang.Object
  extended by O2Plib.table.SimpleTable
      extended by O2Plib.table.Table

public class Table
extends SimpleTable

Class Table creates a table object with no data or data read from a tab-delimited file. It extends SimpleTable. In turn, Table is the base class for other Table object extensions. Note: I/O is not done in this class but rather in AccFileIO.java.

This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The MAExplorer Mozilla and Legal files are available on http://maexplorer.sourceforge.net/.

Version:
$Date: 2005/10/21 16:33:51 $ $Revision: 1.16 $
Author:
P. Lemkin (NCI), G. Thornwall (SAIC), NCI-Frederick, Frederick, MD
See Also:
MAExplorer Home, ConfigTable, GipoTable, MaHPquantTable, SamplesTable

Field Summary
 int bufSize
          size of input buffer when read file
 boolean errFlag
          Error message Flag
 java.lang.String errMsg
          Error message string if not null
 boolean fileOKflag
          File exists and was able to be read
static Table[] tblList
          List of all Tables's [0:tblListSize-1].
static int tblListSize
          size of the tableList.
 
Fields inherited from class O2Plib.table.SimpleTable
dbugFlag, fullFileName, name, tCols, tData, tFields, tHelp, title, tRows, tType
 
Constructor Summary
Table()
          Table() - constructor for creating table from file.
Table(int nRows, int nCols, java.lang.String title)
          Table() - constructor for creating empty table of (nRows,nCols).
Table(SimpleTable st)
          Table() - constructor for creating table from a SimpleTable Errors are in (errMsg, errFlag).
Table(java.lang.String fileName)
          Table() - constructor for creating table from file.
Table(java.lang.String fileName, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          Table() - constructor for creating table from file.
Table(java.lang.String title, java.lang.String fileName, int tRows, int tCols, java.lang.String[] tFields, java.lang.String[][] tData)
          SimpleTable() - constructor for creating a table popupated with fields and data.
Table(java.lang.String title, java.lang.String fileName, java.lang.String[] tFields, int tRows, int tCols)
          Table() - constructor for creating empty table.
Table(java.lang.String title, java.lang.String fileName, java.lang.String type, boolean add2TblListFlag)
          Table() - constructor for creating empty table.
 
Method Summary
 boolean addTableToTableList()
          addTableToTableList() - add Table to tblList.
static void clearTableList()
          clearTableList() - clear the table List of all instances.
 Table copyTable(SimpleTable st)
          copyTable() - copy SimpleTable data to this Table.
private  boolean createFileTable(java.lang.String fileName, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          createFileTable() - create table from file on this Table.
 java.lang.String[] getArrayOfTabDelimitedTokens(java.lang.String line, int nCols)
          getArrayOfTabDelimitedTokens() - get array of tab-delim tokens from table.
private  boolean getData(java.lang.String fileName, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          getData() - read the data and store it in the table.
 SimpleTable getTableRowsSubset(SimpleTable t, java.lang.String key, java.lang.String fieldName, java.lang.String newTitle)
          getTableRowsSubset() - make new table subset of table by (field,key)
 SimpleTable getTableRowsSubset(Table t, java.lang.String[] fieldList, java.lang.String[] newFieldList, java.lang.String[] urlPrefix, java.lang.String[] urlSuffix, int nFields, java.lang.String newTitle)
          getTableRowsSubset() - make new table of specified fields by fieldList[] and in the order in which they appear in the fieldList[].
 SimpleTable insertTblInULHCtable(int nRows, int nCols, java.lang.String nTitle)
          insertTblInULHCtable() - insert table into U.L.H.C.
static Table lookupTableByName(java.lang.String tableName)
          lookupTableByName() - lookup the table by name
static int lookupTableListIdxByTableName(java.lang.String tableName)
          lookupTableListIdxByTableName() - lookup TableList[] index by Table name if the name is in the table list.
 java.lang.String makeTabDelimReport(java.lang.String title)
          makeTabDelimReport() - make tab-delimited string report string from this Table
private  java.lang.String readTable(java.lang.String fileName)
          readTable() - read a tab-delimited table from FILE/URL.
 boolean rmvTableFromTableList()
          rmvTableFromTableList() - remove Table from tblList
private  boolean storeDataBufParser(java.lang.String rawData, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          storeDataBufParser() - Put data into Table tData[r][c] and tFields[c], given a String from the whole file.
 boolean writeTableDelim(java.lang.String fileName, java.lang.String delim)
          writeTableDelim() - Write the table as a delimited character or string file.
 boolean writeTableXML(java.lang.String fileName, java.lang.String topObj, java.lang.String dateStr, java.lang.String dbName, java.lang.String entryObj)
          writeTableXML() - Write the table as an XML file.
 boolean writeTableXML(java.lang.String fileName, java.lang.String topObj, java.lang.String dateStr, java.lang.String dbName, java.lang.String entryObj, java.lang.String dtdFile)
          writeTableXML() - Write the table as an XML file
 
Methods inherited from class O2Plib.table.SimpleTable
addColumnsToTable, addColumnToTable, appendRowToTable, cvtTblToDelimData, cvtTblToHTML, cvtTblToXML, cvtTblToXML, deleteRowsFromTable, freeTable, getFieldIdxRowDatum, getFieldRowDatum, getListOfRowsDataByFieldNameValuePairs, getListOfRowsIdxByFieldNameValuePairs, getRowData, getRowDataByFieldNameValue, lookupFieldIdx, lookupFieldPrefixIdx, lookupRowByFieldNameValue, lookupRowByFieldNameValuePairs, removeRowFromTable, replaceColumnData, replaceColumnData, replaceColumnData, replaceColumnData, setFieldData, setFieldIdxRowDatum, setFieldRowDatum, setHelpData, setRowData, trimWhitespace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tblList

public static Table[] tblList
List of all Tables's [0:tblListSize-1]. The tables can be searched by matching the table name.


tblListSize

public static int tblListSize
size of the tableList.


fileOKflag

public boolean fileOKflag
File exists and was able to be read


bufSize

public int bufSize
size of input buffer when read file


errMsg

public java.lang.String errMsg
Error message string if not null


errFlag

public boolean errFlag
Error message Flag

Constructor Detail

Table

public Table()
Table() - constructor for creating table from file. Errors are in (errMsg, errFlag).

Parameters:
fileName - is file name to read into Table instance

Table

public Table(java.lang.String fileName)
Table() - constructor for creating table from file. Errors are in (errMsg, errFlag).

Parameters:
fileName - is file name to read into Table instance

Table

public Table(java.lang.String fileName,
             java.lang.String[] overideFieldNames,
             boolean dontReadHeaderLineFlag)
Table() - constructor for creating table from file. Errors are in (errMsg, errFlag).

Parameters:
fileName - is file name to read into Table instance
overideFieldNames - is array of names to use for the file names if not null, else use the names from the first line in the file.
dontReadHeaderLineFlag - if using the overideFieldNames[] data, don't read the header line (treat it as data) and use the rest of the fields
See Also:
createFileTable(java.lang.String, java.lang.String[], boolean)

Table

public Table(int nRows,
             int nCols,
             java.lang.String title)
Table() - constructor for creating empty table of (nRows,nCols). The fileName is set to "*NONE*". Errors are in (errMsg, errFlag).

Parameters:
nRows - is the size of table to create
nCols - is the size of table to create
fileName - is file name to read into Table instance

Table

public Table(java.lang.String title,
             java.lang.String fileName,
             java.lang.String type,
             boolean add2TblListFlag)
Table() - constructor for creating empty table. Errors are in (errMsg, errFlag).

Parameters:
title - opt. title of the table
fileName - opt. file name assoc. w/table
type - of the table
add2TblListFlag - to tblList[] if true

Table

public Table(java.lang.String title,
             java.lang.String fileName,
             java.lang.String[] tFields,
             int tRows,
             int tCols)
Table() - constructor for creating empty table. The table is similar to a spreadsheet of size (tRows,tCols). If tCols > 0, then tFields[] is allocated. If tCols > 0 AND tRows> 0, then tData[] is allocated.

Parameters:
title - opt. title of the table
fileName - opt. file name assoc. w/table
tFields - is list of field names [0:tCols-1]
tRows - # of rows in table
tCols - # of Field columns in table.

Table

public Table(java.lang.String title,
             java.lang.String fileName,
             int tRows,
             int tCols,
             java.lang.String[] tFields,
             java.lang.String[][] tData)
SimpleTable() - constructor for creating a table popupated with fields and data. The table is similar to a spreadsheet of size (tRows,tCols). If tCols > 0, then tFields[] is allocated. If tCols > 0 AND tRows> 0, then tFields[] is allocated.

Parameters:
title - opt. title of the table
fileName - opt. file name assoc. w/table
tRows - # of rows in table
tCols - # of Field columns in table.
tFields - field names of the table
tData - rows of data

Table

public Table(SimpleTable st)
Table() - constructor for creating table from a SimpleTable Errors are in (errMsg, errFlag).

Parameters:
st - is a Simple table instance.
See Also:
copyTable(O2Plib.table.SimpleTable)
Method Detail

createFileTable

private boolean createFileTable(java.lang.String fileName,
                                java.lang.String[] overideFieldNames,
                                boolean dontReadHeaderLineFlag)
createFileTable() - create table from file on this Table.

Parameters:
fileName - is file name to read into Table instance
overideFieldNames - is array of names to use for the file names if not null, else use the names from the first line in the file.
dontReadHeaderLineFlag - if using the overideFieldNames[] data, don't read the header line (treat it as data) and use the rest of the fields
Returns:
true if succeed, errors in (errMsg, errFlag)
See Also:
getData(java.lang.String, java.lang.String[], boolean), storeDataBufParser(java.lang.String, java.lang.String[], boolean)

getData

private boolean getData(java.lang.String fileName,
                        java.lang.String[] overideFieldNames,
                        boolean dontReadHeaderLineFlag)
getData() - read the data and store it in the table.

Parameters:
fileName - is file name to read into Table instance
overideFieldNames - is array of names to use for the file names if not null, else use the names from the first line in the file.
dontReadHeaderLineFlag - if using the overideFieldNames[] data, don't read the header line (treat it as data) and use the rest of the fields
Returns:
true if can read the table from the file
See Also:
readTable(java.lang.String), storeDataBufParser(java.lang.String, java.lang.String[], boolean)

getArrayOfTabDelimitedTokens

public java.lang.String[] getArrayOfTabDelimitedTokens(java.lang.String line,
                                                       int nCols)
getArrayOfTabDelimitedTokens() - get array of tab-delim tokens from table. The number of expected columns is specified and if there is no more data, it will leave those cells null.

Parameters:
line - of tokens to parse
nCols - is the # of tokens to parse (may be less than actual #)
Returns:
array of data or null line if is empty

storeDataBufParser

private boolean storeDataBufParser(java.lang.String rawData,
                                   java.lang.String[] overideFieldNames,
                                   boolean dontReadHeaderLineFlag)
storeDataBufParser() - Put data into Table tData[r][c] and tFields[c], given a String from the whole file. where tData[0:tRow-1][0:tCol-1] and tFields[0:tRow-1]

Parameters:
rawData - is data to be parsed into a Table
overideFieldNames - is array of names to use for the file names if not null, else use the names from the first line in the file.
dontReadHeaderLineFlag - if using the overideFieldNames[] data, don't read the header line (treat it as data) and use the rest of the fields
Returns:
true if store data correctly

readTable

private java.lang.String readTable(java.lang.String fileName)
readTable() - read a tab-delimited table from FILE/URL. This file consisting of the field names in the first row followed by data fields.

Parameters:
fileName - is file name to read
Returns:
raw data string if succeed, else null

getTableRowsSubset

public SimpleTable getTableRowsSubset(SimpleTable t,
                                      java.lang.String key,
                                      java.lang.String fieldName,
                                      java.lang.String newTitle)
getTableRowsSubset() - make new table subset of table by (field,key)

Parameters:
t - is the instance of a SimpleTable to subset
key - is the values to look for
fieldName - is the column field name to check
newTitle - is the new table title
Returns:
new SimpleTable or null if failed.
See Also:
SimpleTable.lookupFieldIdx(java.lang.String), Table

getTableRowsSubset

public SimpleTable getTableRowsSubset(Table t,
                                      java.lang.String[] fieldList,
                                      java.lang.String[] newFieldList,
                                      java.lang.String[] urlPrefix,
                                      java.lang.String[] urlSuffix,
                                      int nFields,
                                      java.lang.String newTitle)
getTableRowsSubset() - make new table of specified fields by fieldList[] and in the order in which they appear in the fieldList[]. If an newFieldList[] entry is not null, then use a new field name. If a urlPrefix[] (urlSuffix[]) entry is not null, then prepend (append) it to the data item. This is how we generate clickable URLs by attaching the URL base address and possible suffix. Note: only add the URL links if the data for that cell is not "".

Parameters:
t - is the instance of a SimpleTable to subset
fieldList - is list of fields to use
newFieldList[] - is names of new fields entries are not null
urlPrefix - is URL entry prefixes for URL fields if not null
urlSuffix - is URL entry suffixes if entry not null
nFields - is # of new fields
newTitle - is the new table title
Returns:
new SimpleTable or null if failed.
See Also:
SimpleTable, SimpleTable.lookupFieldIdx(java.lang.String)

makeTabDelimReport

public java.lang.String makeTabDelimReport(java.lang.String title)
makeTabDelimReport() - make tab-delimited string report string from this Table

Parameters:
title - to put at top of the string report
Returns:
string report

insertTblInULHCtable

public SimpleTable insertTblInULHCtable(int nRows,
                                        int nCols,
                                        java.lang.String nTitle)
insertTblInULHCtable() - insert table into U.L.H.C. of new larger table Where this.tRows<=nRows, this.tCols<=nCols. Fill all null entries with "".

Parameters:
nRows - is the number of rows in the table
nCols - is the number of columns in the table
nTitle - is the new title
Returns:
old table if (this.tRows>=nRows && this.tCols>=nCols else return new table if successful, else null.
See Also:
SimpleTable

copyTable

public Table copyTable(SimpleTable st)
copyTable() - copy SimpleTable data to this Table. This handles potential casting problems.

Parameters:
st - is SimpleTable to copy into a Table
Returns:
instance of new Table derived from st

clearTableList

public static void clearTableList()
clearTableList() - clear the table List of all instances. The list may be searched by matching the instance names.


addTableToTableList

public boolean addTableToTableList()
addTableToTableList() - add Table to tblList. If a list with the same name is in the table, replace that entry with the new table.

Parameters:
tbl - is Table to add to list
Returns:
true if succeed

rmvTableFromTableList

public boolean rmvTableFromTableList()
rmvTableFromTableList() - remove Table from tblList

Parameters:
tbl - is Table to remove from the list
Returns:
true if succeed

lookupTableByName

public static Table lookupTableByName(java.lang.String tableName)
lookupTableByName() - lookup the table by name

Parameters:
tableName - to search for
Returns:
Table if found, else null.

lookupTableListIdxByTableName

public static int lookupTableListIdxByTableName(java.lang.String tableName)
lookupTableListIdxByTableName() - lookup TableList[] index by Table name if the name is in the table list.

Parameters:
tableName - to search for
Returns:
index where found in TableList, else return -1.

writeTableDelim

public boolean writeTableDelim(java.lang.String fileName,
                               java.lang.String delim)
writeTableDelim() - Write the table as a delimited character or string file. Delimiters could be "," or "\t", or some string.

Parameters:
fileName - is the full path name of the output file
delim - is the delimiter string (or character)
Returns:
true if succeed

writeTableXML

public boolean writeTableXML(java.lang.String fileName,
                             java.lang.String topObj,
                             java.lang.String dateStr,
                             java.lang.String dbName,
                             java.lang.String entryObj,
                             java.lang.String dtdFile)
writeTableXML() - Write the table as an XML file

Parameters:
fileName - is the full path name of the output file
topObj - is the name of the top level object
dateStr - is the date created if not null
dbName - is the name of the database if not null
entryObj - is the name of a row entry object
dtdFile - is the DTD file (if not null, insert the DTD if it exists)
Returns:
true if succeed

writeTableXML

public boolean writeTableXML(java.lang.String fileName,
                             java.lang.String topObj,
                             java.lang.String dateStr,
                             java.lang.String dbName,
                             java.lang.String entryObj)
writeTableXML() - Write the table as an XML file. Do Not write the DTD.

Parameters:
fileName - is the full path name of the output file
topObj - is the name of the top level object
dateStr - is the date created if not null
dbName - is the name of the database if not null
entryObj - is the name of a row entry object
Returns:
true if succeed