Class Table

java.lang.Object
  |
  +--SimpleTable
        |
        +--Table
Direct Known Subclasses:
ConfigTable, GipoTable, MaHPquantTable, MaInfoTable, SamplesTable

class Table
extends SimpleTable

This class creates a table object with no data or data read from a tab-delimited file. It extens 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 FileIO.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: 2003/04/08 13:25:08 $ $Revision: 1.11 $
Author:
P. Lemkin (NCI), G. Thornwall (SAIC), NCI-Frederick, Frederick, MD
See Also:
MAExplorer Home, ConfigTable, GipoTable, MaHPquantTable, SamplesTable

Field Summary
(package private)  int bufSize
          size of input buffer when read file
(package private)  boolean fileOKflag
          File exists and was able to be read
private  FileIO fio
          link to global instance of FileIO
(package private)  MAExplorer mae
          link to global instance of MAExplorer
 
Fields inherited from class SimpleTable
fileName, msg, tCols, tData, tFields, title, tRows
 
Constructor Summary
(package private) Table(MAExplorer mae, int nRows, int nCols, java.lang.String title, java.lang.String msg)
          Table() - constructor for creating empty table of (nRows,nCols).
(package private) Table(MAExplorer mae, java.lang.String fileName, java.lang.String msg)
          Table() - constructor for creating table from file
(package private) Table(MAExplorer mae, java.lang.String fileName, java.lang.String msg, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          Table() - constructor for creating table from file
(package private) Table(SimpleTable st)
          Table() - constructor for creating table from a SimpleTable
 
Method Summary
(package private)  Table copyTable(SimpleTable st)
          copyTable() - copy SimpleTable data to this Table.
private  boolean createFileTable(MAExplorer mae, java.lang.String fileName, java.lang.String msg, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          createFileTable() - create table from file on this Table.
(package private)  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 msg, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          getData() - read the data and store it in the table.
(package private)  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)
(package private)  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[].
(package private)  SimpleTable insertTblInULHCtable(int nRows, int nCols, java.lang.String nTitle)
          insertTblInULHCtable() - insert table into U.L.H.C.
(package private)  int lookupFieldIdxAndRemapFieldName(java.lang.String maeTbl, java.lang.String maeField)
          lookupFieldIdxAndRemapFieldName() - lookup field idx and remap name if need to.
(package private)  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, java.lang.String msg)
          readTable() - read a tab-delimited table from FILE/URL.
private  boolean storeDataBufParser(java.lang.String rawData, java.lang.String msg, java.lang.String[] overideFieldNames, boolean dontReadHeaderLineFlag)
          storeDataBufParser() - Put data into Table tData[r][c] and tFields[c], given a String from the whole file.
 
Methods inherited from class SimpleTable
freeTable, getTableRowFieldByRowIdx, getTableRowFieldIdxByRowIdx, lookupFieldIdx, setFieldData, setRowData, trimWhitespace
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

mae

MAExplorer mae
link to global instance of MAExplorer

fio

private FileIO fio
link to global instance of FileIO

fileOKflag

boolean fileOKflag
File exists and was able to be read

bufSize

int bufSize
size of input buffer when read file
Constructor Detail

Table

Table(MAExplorer mae,
      java.lang.String fileName,
      java.lang.String msg)
Table() - constructor for creating table from file
Parameters:
mae - is MAExplorer instance
fileName - is file name to read into Table instance
msg - is the loading message
See Also:
FileIO.logMsgln(java.lang.String), MAExplorer.logDRYROTerr(java.lang.String), MAExplorer.percentDone(), Util.showMsg(java.lang.String), getData(java.lang.String, java.lang.String, java.lang.String[], boolean), storeDataBufParser(java.lang.String, java.lang.String, java.lang.String[], boolean)

Table

Table(MAExplorer mae,
      java.lang.String fileName,
      java.lang.String msg,
      java.lang.String[] overideFieldNames,
      boolean dontReadHeaderLineFlag)
Table() - constructor for creating table from file
Parameters:
mae - is MAExplorer instance
fileName - is file name to read into Table instance
msg - is the loading message
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(MAExplorer, java.lang.String, java.lang.String, java.lang.String[], boolean)

Table

Table(MAExplorer mae,
      int nRows,
      int nCols,
      java.lang.String title,
      java.lang.String msg)
Table() - constructor for creating empty table of (nRows,nCols). The fileName is set to "*NONE*".
Parameters:
mae - is MAExplorer instance
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
msg - is the loading message

Table

Table(SimpleTable st)
Table() - constructor for creating table from a SimpleTable
Parameters:
st - is a Simple table instance.
See Also:
copyTable(SimpleTable)
Method Detail

createFileTable

private boolean createFileTable(MAExplorer mae,
                                java.lang.String fileName,
                                java.lang.String msg,
                                java.lang.String[] overideFieldNames,
                                boolean dontReadHeaderLineFlag)
createFileTable() - create table from file on this Table.
Parameters:
mae - is MAExplorer instance
fileName - is file name to read into Table instance
msg - is the loading message if not null
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
See Also:
FileIO.logMsgln(java.lang.String), MAExplorer.logDRYROTerr(java.lang.String), MAExplorer.percentDone(), Util.showMsg(java.lang.String), getData(java.lang.String, java.lang.String, java.lang.String[], boolean), storeDataBufParser(java.lang.String, java.lang.String, java.lang.String[], boolean)

getData

private boolean getData(java.lang.String fileName,
                        java.lang.String msg,
                        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
msg - is the loading message
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:
FileIO.logMsgln(java.lang.String), MAExplorer.percentDone(), Util.showMsg(java.lang.String), readTable(java.lang.String, java.lang.String), storeDataBufParser(java.lang.String, java.lang.String, java.lang.String[], boolean)

lookupFieldIdxAndRemapFieldName

int lookupFieldIdxAndRemapFieldName(java.lang.String maeTbl,
                                    java.lang.String maeField)
lookupFieldIdxAndRemapFieldName() - lookup field idx and remap name if need to.
Parameters:
maeTbl - is table to lookup
maeField - to find
Returns:
index if found, -1 if failed.
See Also:
ConfigTable.mapUsrFieldToMaeField(java.lang.String, java.lang.String), SimpleTable.lookupFieldIdx(java.lang.String)

getArrayOfTabDelimitedTokens

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 msg,
                                   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
msg - is the converting msg
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
See Also:
MAExplorer.logDRYROTerr(java.lang.String), Util.showMsg(java.lang.String)

readTable

private java.lang.String readTable(java.lang.String fileName,
                                   java.lang.String msg)
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
msg - is the converting msg
Returns:
raw data string if succeed, else null
See Also:
FileIO.readData(java.lang.String, java.lang.String), Util.showMsg(java.lang.String)

getTableRowsSubset

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

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

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

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

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