Class SimpleTable

java.lang.Object
  |
  +--SimpleTable

public class SimpleTable
extends java.lang.Object

The SimpleTable class creates an empty table of size tRows and tCols. It is up to the caller to populate the table. It contains several methods for accessing data in the table.

List of access methods
 SimpleTable() - constructor for creating empty table
 SimpleTable() - constructor for creating a table popupated with fields and data
 freeTable() - free Table tData[][] and tFields so can garbage collect it
 trimWhitespace() - trim Table tData[][] and tFields[] data
 setFieldData() - set new field[] list for table
 setRowData() - set new row data[] for specific row in the table
 lookupFieldIdx() - lookup column index of field if exists
 getTableRowFieldByRowIdx() - get field in row by Table row index
 getTableRowFieldIdxByRowIdx() - get data by field idx with row index

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/03/10 19:26:09 $ $Revision: 1.6 $
Author:
P. Lemkin (NCI), G. Thornwall (SAIC), NCI-Frederick, Frederick, MD
See Also:
MAExplorer Home, Table

Field Summary
 java.lang.String fileName
          Optional file name associated with table
 java.lang.String msg
          Optional message associated with table
 int tCols
          # of columns/row in the table
 java.lang.String[][] tData
          row vectors of data [0:tRows-1][0:tCols-1]
 java.lang.String[] tFields
          names of table fields
 java.lang.String title
          Optional title of table
 int tRows
          # of rows/Table
 
Constructor Summary
SimpleTable()
          SimpleTable() - constructor for creating empty table.
SimpleTable(java.lang.String title, java.lang.String msg, java.lang.String fileName, int tRows, int tCols)
           
SimpleTable(java.lang.String title, java.lang.String msg, 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.
 
Method Summary
 void freeTable()
          freeTable() - free Table tData[][] and tFields so can garbage collect it Also zero tRows, tCols
 java.lang.String getTableRowFieldByRowIdx(int idx, java.lang.String fieldName)
          getTableRowFieldByRowIdx() - get field in row by Table row index
 java.lang.String getTableRowFieldIdxByRowIdx(int rowIdx, int fieldIdx)
          getTableRowFieldIdxByRowIdx() - get data by field idx with row index
 int lookupFieldIdx(java.lang.String fieldName)
          lookupFieldIdx() - lookup column index of field if exists.
 boolean setFieldData(java.lang.String[] newFields, int nNewFields)
          setFieldData() - set new field[] list for table
 boolean setRowData(java.lang.String[] newRowData, int nFields, int rowNbr)
          setRowData() - set new row data[] for specific row in the table
 void trimWhitespace()
          trimWhitespace() - trim Table tData[][] and tFields[] data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tCols

public int tCols
# of columns/row in the table

tRows

public int tRows
# of rows/Table

tFields

public java.lang.String[] tFields
names of table fields

tData

public java.lang.String[][] tData
row vectors of data [0:tRows-1][0:tCols-1]

title

public java.lang.String title
Optional title of table

msg

public java.lang.String msg
Optional message associated with table

fileName

public java.lang.String fileName
Optional file name associated with table
Constructor Detail

SimpleTable

public SimpleTable()
SimpleTable() - constructor for creating empty table.

SimpleTable

public SimpleTable(java.lang.String title,
                   java.lang.String msg,
                   java.lang.String fileName,
                   int tRows,
                   int tCols)

SimpleTable

public SimpleTable(java.lang.String title,
                   java.lang.String msg,
                   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
msg - opt. message assoc. w/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
Method Detail

freeTable

public void freeTable()
freeTable() - free Table tData[][] and tFields so can garbage collect it Also zero tRows, tCols

trimWhitespace

public void trimWhitespace()
trimWhitespace() - trim Table tData[][] and tFields[] data. This removes leading and trailing white space.

setFieldData

public boolean setFieldData(java.lang.String[] newFields,
                            int nNewFields)
setFieldData() - set new field[] list for table
Parameters:
newFields - is list of new fields
Returns:
nNewFields is # of new fields to use

setRowData

public boolean setRowData(java.lang.String[] newRowData,
                          int nFields,
                          int rowNbr)
setRowData() - set new row data[] for specific row in the table
Parameters:
newRowData - is list of new data for row rowNbr
rowNbr - is the row to change
Returns:
nFields is # of new fields to use

lookupFieldIdx

public int lookupFieldIdx(java.lang.String fieldName)
lookupFieldIdx() - lookup column index of field if exists.
Parameters:
fieldName - to lookup
Returns:
index if found, else if it does not exist return -1

getTableRowFieldByRowIdx

public java.lang.String getTableRowFieldByRowIdx(int idx,
                                                 java.lang.String fieldName)
getTableRowFieldByRowIdx() - get field in row by Table row index
Parameters:
idx - is field (i.e. column) to use
fieldName - to lookup
Returns:
field if found, else null
See Also:
lookupFieldIdx(java.lang.String)

getTableRowFieldIdxByRowIdx

public java.lang.String getTableRowFieldIdxByRowIdx(int rowIdx,
                                                    int fieldIdx)
getTableRowFieldIdxByRowIdx() - get data by field idx with row index
Parameters:
rowIdx - is field (i.e. column) to use
fieldIdx - of field to to lookup
Returns:
data if found, else null