|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object FileIO FileTable
public class FileTable
This class reads tab-delimited data from files into a Table and can write data to files. The term Table (upper case 'T') denotes the FileTable data structure. The class also parses tab-delimited data with or without a header (1 to n-lines of header) from a file into a Table (tRows,tCols,tHdrRows,tPreface,tHeader,tFields,tData).
If there are multiple header lines, it uses the last header line as the tFields[] data. You can optionally check for duplicate files and ignore them otherwise it is a parsing error.
You can optionally search the input file for a blank line after which the actually header appears. You can also specify a keyword in the header line to denote where the Table starts. You can remove blank lines at the end of the file to shorten the table length. It can be used to create an empty table (not associated with a file).
List of Methods FileTable() - Constructor, set some defaults. FileTable(tableName) - Constructor, set some defaults. FileTable(tableName, rows, cols) - Constructor, set some defaults. clearTable() - set to empty table. Generally called from Constructor cloneTable() - clone the current Table. Copy data by value. setNbrTableHdrLines() - number of lines of the Table header. setHasTableHeaderFlag() - set Has Table Header Flag. setDuplicateFieldsFlag() - set duplicate fields Flag. setHasEmptyLineBeforeTableFlag() - set look for empty line(s) BEFORE table setRmvTrailingBlankLinesFlag() - remove trailing blank lines in the Table setRmvTrailingEmptyColumnsFlag() - set remove empty trailing columns flag. setStartTableAtColStr() - start Table at string known to be in header. setColNameIndexMapKeys() - set column names keys for ftIdxMap index-map. setUseOnlyLastHeaderLineFlag() - set use only last header line flag readTableRowFromFile() - random access read row r tokens from indexed file. readLineRowFromFile() - random access read row r data from indexed file. checkForBadTable() - verify that it is a well formed table checkForBadTableHeader() - verify that is a well formed tField Table parseTableFromString() - convert tab-delim string to Table structure. readAndParseTableIndexMap() - read tab-delim file to Table Index-Map. readAndParseTableAll() - read & convert tab-delim file to Table & ftIdxMap. readAndParseTable() - read & convert tab-delim file to Table structure. readAndParseTableFields() - read tab-delim file to tFields Table structure. readAndParseTableFieldsAndIndexMap - read tab-delim file tFields & ftIdxMap readAndParseTableData() - read & convert tab-delim file to Table structure. computeFileLineTermSize() - compute a file's line terminator size. cvtTableToTabDelimStr() - convert table to tab delimited string rmvTrailingBlankLinesFromTable() - remove Table trailing blank lines. deleteTableColumnByName() - delete a column from the Table. deleteTableColumnByColIdx() - delete a column from table by column index lookupFieldIdx() - lookup column index of field if exists. lookupRowFromColumnData() - lookup row index from column data if exists. lookupCol2DataFromCol1DataRow() - lookup col2 data from row w/col1 data match appendRowToTable() - append row of data to table. removeRowFromTable() - remove row of data from table. deleteRowsFromTable() - delete rows from the Table and resize the Table. deleteTrailingEmptyColumnsFromTable() - removes empty trailing columns mapHeaderColNames() - map tField & tHeaders old to new names in map list. setFieldsToTable() - set the Fields list to the Table and set tCols. setHeadersToTable() - set the Headers list to the Table and set tHdrRows. addEmptyColumnToExistingTable() - add empty column to existing Table. addColumnToTable() - add a new column to Table with specified field name. replaceColumnData() - replace data in a column in the Table. setColumnDataByValue() - set all data in a column in Table to a value. getColumnData() - lookup the column name and then return all column data. reorderRowsBySortIndex() - reorder the entire table rows by the sortIdx. reorderColumnsInTable() - reorder Table tFields & tData by column index joinTableToCurrentTable() - join another Table ftJoin to current Table. trimTableEnclWhitespace() - trim (clean) enclosing white space in Table. trimArrayEnclWhitespace() - trim (clean) enclosing white space in a 1D array. sortTableRowsByField() - sort table rows by field. limitMaxRows() - keep max nbr rows in front of the Table. limitMaxRowsSortedByField() - sort Table by field, then keep max nbr rows
This code is available at the HTMLtools project on SourceForge at http://htmltools.sourceforge.org/ under the "Common Public License Version 1.0" http://www.opensource.org/licenses/cpl1.0.php.
It was derived and refactored from the open source MAExplorer (http://maexplorer.sourceforge.org/), and Open2Dprot (http://Open2Dprot.sourceforge.net/) Table modules.
$Date: 2009/11/23 11:45:56 $ $Revision: 1.37 $
Copyright 2008, 2009 by Peter Lemkin
E-Mail: lemkin@users.sourceforge.net
http://lemkingroup.com/
Field Summary | |
---|---|
int |
bufSize
size of input buffer |
java.lang.String[] |
colNameIndexMap
List of column names to be used in the left side of the ftIdxMap Table if it is built. |
java.lang.String |
fileName
file to read or write I/O |
int |
firstDataRowCharIdx
Char index of input buffer first row with table data (Table Fields or Data if no Fields). |
int |
firstDataRowLineNbr
Line number of the first row with table data (Table Fields or Data if no Fields) |
FileTable |
ftIdxMap
FileTable index map where save the {colNames, "StartByte", "EndByte") The colNames is a list with arbitrary names that can not be either "StartByte" or "EndByte". |
boolean |
hasEmptyLineBeforeTableFlag
Set to true to look for empty line(s) BEFORE the table data |
boolean |
hasTableHeaderRowFlag
Set to true (default) if has table header). |
boolean |
ignoreDuplicateFieldsFlag
Set to true if has table may have duplicate fields. |
long[] |
lineEndDataBytePtr
Index-map byte pointers of the start of data lines synced with tData rows. |
long[] |
lineEndHeaderBytePtr
Index-map byte pointers of the start of header lines synced with tHeader rows. |
long[] |
lineStartDataBytePtr
Index-map byte pointers of the start of data lines synced with tData rows. |
long[] |
lineStartHeaderBytePtr
Index-map byte pointers of the start of header lines synced with tHeader rows. |
int |
nbrTableHdrLines
Number of lines of the Table header "-hdr:{nbr of lines in header}" switches. |
boolean |
needToSortTableAgainFlag
[HACK] If the table is sorted by sortTableRowsByField for numeric values with the useAbsValueFlag set true, and both + and - changes were found, it will set the needToSortTableAgainFlag so the calling program can resort one more time if it wants to keep the data in numeric order. |
int |
nUnmodifiedFieldNames
Size of unmodifiedFieldNames[], the list of unmodified tField[] names. |
boolean |
rmvTrailingBlankLinesFlag
Set to true if remove trailing blank lines from the table |
boolean |
rmvTrailingEmptyColumnsFlag
Set to true to remove empty trailing columns defined as columns in a Table with a header as null column names. |
java.lang.String |
startTblColStr
Set to string known to be in header. |
int |
tCols
number of columns/row in the table. |
java.lang.String[][] |
tData
row data cell vectors [0:tRows-1][0:tCols-1] |
java.lang.String[][] |
tDataFull
This is the (sorted) full table data BEFORE the length of the table was limited using limitMaxRowsXXX() methods. |
java.lang.String[] |
tFields
names of table fields. |
int |
tHdrRows
number of header rows (default is 1) |
java.lang.String[][] |
tHeader
names of table headers of size [0:tHdrRows-1][0:tCols-1]. |
java.lang.String |
tName
Table name if any |
java.lang.String |
tPreface
Table preface if any. |
int |
tRows
number of rows. |
java.lang.String[] |
unmodifiedFieldNames
List of unmodified tField names, if not null with size nUnmodifiedFieldNames. |
boolean |
useOnlyLastHeaderLineFlag
Reduce the number of header lines to 1 even if there are more than 1 header line. |
UtilCM |
util
Global utilities UtilCM instance |
Fields inherited from class FileIO |
---|
errMsgLog, lastErrMsgLog, raf, rafBuffer, rafFileName, rafLastSeekPtr, zipFile |
Constructor Summary | |
---|---|
FileTable()
FileTable() - generic Constructor, set some defaults to 0. |
|
FileTable(java.lang.String tableName)
FileTable() - generic Constructor, set some defaults. |
|
FileTable(java.lang.String tableName,
int rows,
int cols)
FileTable() - Constructor to make empty table of known size |
Method Summary | |
---|---|
boolean |
addColumnToTable(java.lang.String newFieldName,
java.lang.String[] colData)
addColumnToTable() - add a new column to the Table with the specified field name. |
boolean |
addColumnToTable(java.lang.String newFieldName,
java.lang.String[] newHdrCols,
java.lang.String[] colData)
addColumnToTable() - add a new column to the Table with the specified field name. |
boolean |
addColumnToTable(java.lang.String newFieldName,
java.lang.String[] newHdrCols,
java.lang.String[] colData,
boolean hasColDataFlag)
addColumnToTable() - add a new column to the Table with the specified field name. |
boolean |
addEmptyColumnToExistingTable(java.lang.String newFieldName)
addEmptyColumnToExistingTable() - add empty column to existing Table. |
boolean |
appendRowToTable(java.lang.String[] rowData)
appendRowToTable() - append row of data to and grow the Table. |
boolean |
checkForBadTable()
checkForBadTable() - verify that it is a well formed Table with all field names present and with no null, "" or duplicate entries, and tRows EQ tData.length. |
boolean |
checkForBadTableHeader()
checkForBadTableHeader() - verify that is a well formed tField Table with all field names present and with no null, "" or duplicate entries. |
void |
clearTable()
clearTable() - set to empty table. |
FileTable |
cloneTable(java.lang.String cloneTableName)
cloneTable() - clone the current Table. |
int |
computeFileLineTermSize(java.io.RandomAccessFile rafL,
long setSeekPtr)
computeFileLineTermSize() - compute a file's line terminator size. |
java.lang.String |
cvtTableToTabDelimStr(boolean addHdrFlag)
cvtTableToTabDelimStr() - convert Table to tab delimited string. |
boolean |
deleteRowsFromTable(int[] rowsToDelete)
deleteRowsFromTable() - delete rows from the table and resize the table. |
boolean |
deleteTableColumnByColIdx(int cIdx)
deleteTableColumnByColIdx() - delete a column from table by column index where (column 1 has index 0). |
boolean |
deleteTableColumnByName(java.lang.String columnName)
deleteTableColumnByName() - delete a column from the table. |
boolean |
deleteTrailingEmptyColumnsFromTable()
deleteTrailingEmptyColumnsFromTable() - removes empty trailing columns from defined as columns in a Table with a header as null column names. |
java.lang.String[] |
getColumnData(java.lang.String colName)
getColumnData() - lookup the column name and then return all data in the column from tData[][c] if the column exists. |
boolean |
joinTables(FileTable ftJoin)
joinTableToCurrentTable() - join another Table ftJoin to current Table. |
boolean |
limitMaxRows(int maxRowsToKeep,
boolean useAbsValueFlag)
limitMaxRows() - keep max nbr rows in front of the Table. |
boolean |
limitMaxRowsSortedByField(java.lang.String sortField,
boolean sortTblAscendingFlag,
int maxRowsToKeep,
boolean doSortFirstFlag,
boolean useAbsValueFlag)
limitMaxRowsSortedByField() - sort Table by field, then keep max nbr rows. |
int |
lookupFieldIdx(java.lang.String fieldName)
lookupFieldIdx() - lookup column index of field if exists. |
java.lang.String |
lookupRowDataFromColumnData(java.lang.String col1Name,
java.lang.String col1Value,
java.lang.String col2Name)
lookupCol2DataFromCol1DataRow() - lookup col2 data from row with col1 data match. |
int |
lookupRowFromColumnData(java.lang.String colName,
java.lang.String colValue)
lookupRowFromColumnData() - lookup row index from column data if exists. |
boolean |
mapHeaderColNames(java.lang.String[] oldHdrMapNames,
java.lang.String[] newHdrMapNames,
int nHdrMapNames)
mapHeaderColNames() - map tField & tHeaders old to new names in map list. |
boolean |
parseTableFromString(java.lang.String tblStr)
parseTableFromString() - convert tab-delim string to Table structure. |
boolean |
readAndParseTable(java.lang.String inputFile)
readAndParseTable() - read & convert tab-delim file to Table structure. |
boolean |
readAndParseTableAll(java.lang.String inputFile)
readAndParseTableAll() - read & convert tab-delim file to Table structure. |
boolean |
readAndParseTableData(java.lang.String inputFile,
boolean onlyReadHeaderFlag,
boolean saveTblRowDataFlag,
boolean makeIndexMapFlag)
readAndParseTableData() - read & convert tab-delim file to Table structure. |
boolean |
readAndParseTableFields(java.lang.String inputFile)
readAndParseTableFields() - read tab-delim file to tFields Table structure. |
boolean |
readAndParseTableFieldsAndIndexMap(java.lang.String inputFile)
readAndParseTableFieldsAndIndexMap - read tab-delim file to tFields and ftIdxMap Table. |
boolean |
readAndParseTableIndexMap(java.lang.String inputFile)
readAndParseTableIndexMap() - read tab-delim file to Table Index-Map. |
java.lang.String |
readLineRowFromFile(java.lang.String fileName,
int r,
FileTable ftIdxMap)
readLineRowFromFile() - random access read row r data from indexed file. |
java.lang.String[] |
readTableLineRowFromFile(java.lang.String fileName,
int r,
FileTable ftIdxMap,
java.lang.String nullFillStr)
readTableRowFromFile() - random access read row r token list from indexed file. |
boolean |
removeRowFromTable(int rowToDelete)
removeRowFromTable() - remove row of data from table. |
boolean |
reorderColumnsInTable(java.lang.String[] reordColName,
int[] reordColNbr,
int nReorderColName,
boolean reorderRemainingColsFlag)
reorderColumnsInTable() - reorder Table tFields and tData by column index of the Table based on the list of column header names reordColName[0:nReorderColName-1] to be reordered by a corresponding list of new column numbers in reordColNbr[]. |
boolean |
reorderRowsBySortIndex(int[] sortIdx)
reorderRowsBySortIndex() - reorder the entire table rows by the sortIdx. |
boolean |
replaceColumnData(int colIdx,
java.lang.String[] colData,
boolean replaceByValueFlag)
replaceColumnData() - replace data in a column in the Table. |
boolean |
replaceColumnData(java.lang.String fieldName,
java.lang.String[] colData)
replaceColumnData() - replace Table data in a column by reference. |
boolean |
replaceColumnDataByValue(java.lang.String fieldName,
java.lang.String[] colData)
replaceColumnData() - replace Table data in a column by value. |
boolean |
rmvTrailingBlankLinesFromTable()
rmvTrailingBlankLinesFromTable() - remove Table trailing blank lines by shortening the table from the bottom of the table. |
void |
setColNameIndexMapKeys(java.lang.String[] colNameIndexMap)
setColNameIndexMapKeys() - set column names keys for ftIdxMap index-map. |
boolean |
setColumnDataByValue(int colIdx,
java.lang.String colValue)
setColumnDataByValue() - set all data in a column in Table to a value. |
boolean |
setColumnDataByValue(java.lang.String fieldName,
java.lang.String colValue)
setColumnDataByValue() - set all data in a column in Table to a value. |
void |
setDuplicateFieldsFlag(boolean ignoreDuplicateFieldsFlag)
setDuplicateFieldsFlag() - set duplicate fields Flag. |
boolean |
setFieldsToTable(java.lang.String[] fieldNames)
setFieldsToTable() - set the Fields list to the Table and set tCols. |
void |
setHasEmptyLineBeforeTableFlag(boolean hasEmptyLineBeforeTableFlag)
setHasEmptyLineBeforeTableFlag() - set look for empty line(s) BEFORE table data flag |
void |
setHasTableHeaderFlag(boolean hasTableHeaderRowFlag)
setHasTableHeaderFlag() - set Has Table Header Flag. |
boolean |
setHeadersToTable(java.lang.String[][] hdrNames,
int nHeaders,
int nCols)
setHeadersToTable() - set the Headers list to the Table and set tHdrRows. |
void |
setNbrTableHdrLines(int nbrTableHdrLines)
setNbrTableHdrLines() - number of lines of the Table header. |
void |
setRmvTrailingBlankLinesFlag(boolean rmvTrailingBlankLinesFlag)
setRmvTrailingBlankLinesFlag() - remove trailing blank lines in the table by shortening the end of the table. |
void |
setRmvTrailingEmptyColumnsFlag(boolean rmvTrailingEmptyColumnsFlag)
setRmvTrailingEmptyColumnsFlag() - set remove empty trailing columns flag. |
void |
setStartTableAtColStr(java.lang.String startTblColStr)
setStartTableAtColStr() - start Table at string known to be in header. |
void |
setUseOnlyLastHeaderLineFlag(boolean useOnlyLastHeaderLineFlag)
setUseOnlyLastHeaderLineFlag() - set reduce number of header lines to 1 even if there are more than 1 header lines. |
boolean |
sortTableRowsByField(int idxSortField,
java.lang.String sortField,
boolean sortTblAscendingFlag,
boolean useAbsValueFlag)
sortTableRowsByField() - sort table rows by idxSortField field index. |
boolean |
sortTableRowsByField(java.lang.String sortField,
boolean sortTblAscendingFlag,
boolean useAbsValueFlag)
sortTableRowsByField() - sort table rows by field. |
void |
trimTableEnclWhitespace(boolean cleanHeaderFlag,
boolean cleanDataFlag)
trimTableEnclWhitespace() - trim (clean) enclosing white space in Table. |
boolean |
writeTableToTabDelimFile(java.lang.String fileName,
boolean addHdrFlag)
writeTableToTabDelimFile() - convert Table to tab delimited file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public UtilCM util
public boolean hasTableHeaderRowFlag
public boolean ignoreDuplicateFieldsFlag
public boolean hasEmptyLineBeforeTableFlag
public boolean rmvTrailingBlankLinesFlag
public boolean rmvTrailingEmptyColumnsFlag
public java.lang.String startTblColStr
public boolean useOnlyLastHeaderLineFlag
public int bufSize
public java.lang.String[] unmodifiedFieldNames
public int nUnmodifiedFieldNames
public int firstDataRowLineNbr
public int firstDataRowCharIdx
public int nbrTableHdrLines
public java.lang.String fileName
public int tHdrRows
public int tCols
public int tRows
public java.lang.String tName
public java.lang.String tPreface
public java.lang.String[][] tHeader
public java.lang.String[] tFields
public java.lang.String[][] tData
public long[] lineStartHeaderBytePtr
public long[] lineEndHeaderBytePtr
public long[] lineStartDataBytePtr
public long[] lineEndDataBytePtr
public java.lang.String[] colNameIndexMap
public FileTable ftIdxMap
public boolean needToSortTableAgainFlag
public java.lang.String[][] tDataFull
Constructor Detail |
---|
public FileTable()
public FileTable(java.lang.String tableName)
tableName
- String name of tableUtilCM
,
setDuplicateFieldsFlag(boolean)
,
setNbrTableHdrLines(int)
,
setRmvTrailingBlankLinesFlag(boolean)
,
setHasEmptyLineBeforeTableFlag(boolean)
public FileTable(java.lang.String tableName, int rows, int cols)
tableName
- String name of tablerows
- max rows in tablecols
- max columns in tableUtilCM
,
setDuplicateFieldsFlag(boolean)
,
setNbrTableHdrLines(int)
,
setRmvTrailingBlankLinesFlag(boolean)
,
setHasEmptyLineBeforeTableFlag(boolean)
Method Detail |
---|
public void clearTable()
public FileTable cloneTable(java.lang.String cloneTableName)
cloneTableName
- is new tName of the clonereturn
- FileTable instance of clone if successful, else null.public void setNbrTableHdrLines(int nbrTableHdrLines)
nbrTableHdrLines
- valuepublic void setHasTableHeaderFlag(boolean hasTableHeaderRowFlag)
hasTableHeaderRowFlag
- valuepublic void setDuplicateFieldsFlag(boolean ignoreDuplicateFieldsFlag)
ignoreDuplicateFieldsFlag
- valuepublic void setHasEmptyLineBeforeTableFlag(boolean hasEmptyLineBeforeTableFlag)
hasEmptyLineBeforeTableFlag
- valuepublic void setRmvTrailingBlankLinesFlag(boolean rmvTrailingBlankLinesFlag)
rmvTrailingBlankLinesFlag
- valuepublic void setRmvTrailingEmptyColumnsFlag(boolean rmvTrailingEmptyColumnsFlag)
rmvTrailingEmptyColumnsFlag
- valuepublic void setStartTableAtColStr(java.lang.String startTblColStr)
startTblColStr
- - value that is known to be in the headerpublic void setColNameIndexMapKeys(java.lang.String[] colNameIndexMap)
colNameIndexMap
- - list of column names keys for ftIdxMap index-map.public void setUseOnlyLastHeaderLineFlag(boolean useOnlyLastHeaderLineFlag)
useOnlyLastHeaderLineFlag
- - value to set the flag.public java.lang.String[] readTableLineRowFromFile(java.lang.String fileName, int r, FileTable ftIdxMap, java.lang.String nullFillStr)
fileName
- file namer
- is the row to retrieveftIdxMap
- is the FileTable index previously created by
MakeIndexFile for the file.nullFillStr
- is the string to replace all null strings
if not null.
FileIO.readRandomAccessLine(java.lang.String, long)
public java.lang.String readLineRowFromFile(java.lang.String fileName, int r, FileTable ftIdxMap)
fileName
- file namer
- is the row to retrieveftIdxMap
- is the FileTable index previously created by
MakeIndexFile for the file.
FileIO.readRandomAccessLine(java.lang.String, long)
public boolean checkForBadTable()
public boolean checkForBadTableHeader()
public boolean parseTableFromString(java.lang.String tblStr)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
tblStr
- is String to parse and convert to Table
rmvTrailingBlankLinesFromTable()
,
deleteTrailingEmptyColumnsFromTable()
,
checkForBadTable()
public boolean readAndParseTableIndexMap(java.lang.String inputFile)
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader and lineStartDataBytePtr[], and lineEndDataBytePtr[] for the tData.
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
inputFile
- is file to read and convert to table
readAndParseTableData(java.lang.String, boolean, boolean, boolean)
public boolean readAndParseTableAll(java.lang.String inputFile)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader and lineStartDataBytePtr[], and lineEndDataBytePtr[] for the tData. It creates the ftIdxMap index-Map Table as one of the elements of this Table.
inputFile
- is file to read and convert to table
readAndParseTableData(java.lang.String, boolean, boolean, boolean)
public boolean readAndParseTable(java.lang.String inputFile)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader and lineStartDataBytePtr[], and lineEndDataBytePtr[] for the tData. It does not create the ftIdxMap index-Map Table.
inputFile
- is file to read and convert to table
readAndParseTableData(java.lang.String, boolean, boolean, boolean)
public boolean readAndParseTableFields(java.lang.String inputFile)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader. It does not read the tData rows, but instead closes the file and returns. So the index map is incomplete.
inputFile
- is file to read and convert to table
readAndParseTableData(java.lang.String, boolean, boolean, boolean)
public boolean readAndParseTableFieldsAndIndexMap(java.lang.String inputFile)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader. It creates the ftIdxMap index-Map Table as one of the elements of this Table. It does not read the tData rows, but instead closes the file and returns.
inputFile
- is file to read and convert to table
readAndParseTableData(java.lang.String, boolean, boolean, boolean)
public boolean readAndParseTableData(java.lang.String inputFile, boolean onlyReadHeaderFlag, boolean saveTblRowDataFlag, boolean makeIndexMapFlag)
If the table is not at the front of the file, one option is to find the start of the table by searching for a this.startTblColStr string if you know a unique string in the header row. This is used if startTblColStr is not blank (set by setStartTableAtColStr()). If it matches, we then search backwards to the front of the string for a '\n' which is the end of the previous row.
An alternate method for finding the start of the file, if the this.hasEmptyLineBeforeTableFlag is set, is to look for the first non-empty empty row after seeing an empty row that it is then assumed to be the Table data (Fields + data or data) follows. This can be problematic if there are multiple blank lines.
When the front of the table is found, then it sets this.firstDataRowLineNbr to that line number. If there is no empty row found, then it assumes there is no extra data before the table and it sets this.firstDataRowLineNbr to 0. If there is text before the Table, then it is put into this.tPreface.
It also sets the the Index-Map byte pointers lineStartHeaderBytePtr[], lineEndHeaderBytePtr[] for the tHeader and lineStartDataBytePtr[], and lineEndDataBytePtr[] for the tData if making an Index-Map ftIdxMap. If makeIndexMapFlag is set it creates the ftIdxMap index-Map Table as one of the elements of this Table.
inputFile
- is file to read and convert to tableonlyReadHeaderFlag
- only read the tPreface, tFields and tHeader
and then stop reading the file unless making an index map.saveTblRowDataFlag
- to save the tData rows, else just compute
the Index-Map for the data rows.makeIndexMapFlag
- make an index map of Table in this.ftIdxMap
rmvTrailingBlankLinesFromTable()
,
deleteTrailingEmptyColumnsFromTable()
,
checkForBadTable()
public int computeFileLineTermSize(java.io.RandomAccessFile rafL, long setSeekPtr)
rafL
- is the opened RandomAccessFilesetSeekPtr
- leave the file at this seek pointer if != -1.
public java.lang.String cvtTableToTabDelimStr(boolean addHdrFlag)
addHdrFlag
- - add the header (i.e., tFields) to front
public boolean writeTableToTabDelimFile(java.lang.String fileName, boolean addHdrFlag)
fileName
- - to write the TableaddHdrFlag
- - add the header (i.e., tFields) to front
public boolean rmvTrailingBlankLinesFromTable()
public boolean deleteTableColumnByName(java.lang.String columnName)
columnName
- of column to be deleted if found.
deleteTableColumnByColIdx(int)
public boolean deleteTableColumnByColIdx(int cIdx)
cIdx
- is index of column to be deleted.
public int lookupFieldIdx(java.lang.String fieldName)
fieldName
- to lookup
public int lookupRowFromColumnData(java.lang.String colName, java.lang.String colValue)
colName
- of column to lookupcolValue
- in column to lookup in a matching row
public java.lang.String lookupRowDataFromColumnData(java.lang.String col1Name, java.lang.String col1Value, java.lang.String col2Name)
col1Name
- of column 1 to lookup matching rowcol1Value
- in column 1 to lookup matching rowcol2Name
- is column of data to return for matching row.
public boolean appendRowToTable(java.lang.String[] rowData)
rowData
- is row of data to append
public boolean removeRowFromTable(int rowToDelete)
rowToDelete
- (count from row 0)
public boolean deleteRowsFromTable(int[] rowsToDelete)
rowsToDelete
- if not null
public boolean deleteTrailingEmptyColumnsFromTable()
public boolean mapHeaderColNames(java.lang.String[] oldHdrMapNames, java.lang.String[] newHdrMapNames, int nHdrMapNames)
oldHdrMapNames
- is list of current (old) header column names.newHdrMapNames
- is list of new header column names.nHdrMapNames
- is number of header column names to map.
public boolean setFieldsToTable(java.lang.String[] fieldNames)
fieldNames
- is the list of field column names.
public boolean setHeadersToTable(java.lang.String[][] hdrNames, int nHeaders, int nCols)
hdrNames
- is the lists of tHeaders column names.nHeaders
- is the number of columns in the header that should
match the tFields if it exists.nCols
- this is the number of columns in the tHeader rows,
and should be the same as in tFields[].
public boolean addEmptyColumnToExistingTable(java.lang.String newFieldName)
newFieldName
- the new field name. If the field name already
exists, then do not add the field.colData
- is optional data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.
replaceColumnData(java.lang.String, java.lang.String[])
public boolean addColumnToTable(java.lang.String newFieldName, java.lang.String[] colData)
newFieldName
- the new field name. If the field name already
exists, then do not add the field.colData
- is optional data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.
replaceColumnData(java.lang.String, java.lang.String[])
public boolean addColumnToTable(java.lang.String newFieldName, java.lang.String[] newHdrCols, java.lang.String[] colData)
newFieldName
- the new field name. If the field name already
exists, then do not add the field.newHdrCols[]
- is the new header column data [0:tHdrRows] if not
null. If it is null, then fill in the extended header entries
with "".colData
- is optional data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.
replaceColumnData(java.lang.String, java.lang.String[])
public boolean addColumnToTable(java.lang.String newFieldName, java.lang.String[] newHdrCols, java.lang.String[] colData, boolean hasColDataFlag)
newFieldName
- the new field name. If the field name already
exists, then do not add the field.newHdrCols[]
- is the new header column data [0:tHdrRows] if not
null. If it is null, then fill in the extended header entries
with "".colData
- is optional data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.hasColDataFlag
- - has column data and fill the row data
if any with "" data.
replaceColumnData(java.lang.String, java.lang.String[])
public boolean replaceColumnData(java.lang.String fieldName, java.lang.String[] colData)
fieldName
- is the field name for the column.colData
- is column data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.
lookupFieldIdx(java.lang.String)
,
replaceColumnData(java.lang.String, java.lang.String[])
public boolean replaceColumnDataByValue(java.lang.String fieldName, java.lang.String[] colData)
fieldName
- is the field name for the column.colData
- is column data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.
lookupFieldIdx(java.lang.String)
,
replaceColumnData(java.lang.String, java.lang.String[])
public boolean replaceColumnData(int colIdx, java.lang.String[] colData, boolean replaceByValueFlag)
colIdx
- is the field index for the column.colData
- is column data for the new field. The size of the
array must be [0:tRows-1]. If adding the data to an existing
column, just replace the data.replaceByValueFlag
- - to replace by value else by reference.
public boolean setColumnDataByValue(java.lang.String fieldName, java.lang.String colValue)
fieldName
- is the field name for the column.colValue
- is column data for the new field.
lookupFieldIdx(java.lang.String)
,
replaceColumnData(java.lang.String, java.lang.String[])
public boolean setColumnDataByValue(int colIdx, java.lang.String colValue)
colIdx
- is the field index for the column.colValue
- is column data for the new field.
public java.lang.String[] getColumnData(java.lang.String colName)
columnName
- the field name.
public boolean reorderRowsBySortIndex(int[] sortIdx)
sortIdx
- is array of new row 'toRow' indexesreturn
- true if successful.public boolean reorderColumnsInTable(java.lang.String[] reordColName, int[] reordColNbr, int nReorderColName, boolean reorderRemainingColsFlag)
Multiple new columns must be different. All reorderColName[] names must be in tFields or it is an error. Those columns not specified are moved toward the right. This is done after the list of dropped columns has been processed. It will also reorder the tData column if tData exists (i.e., is not null).
if reorderRemainingColumnsAlphabeticlyFlag is set, then sort the remaining columns not specified, but that are used, alphabetically.
reordColName
- - list of column names to be reorderedreordColNbr
- - corresponding list of new column numbers
starting at 1 (used specified, but we
map to n-1).nReorderColName
- - number of mappingsreorderRemainingColsFlag
- to sort the remaining
columns not specified, but that are used,
alphabetically.
public boolean joinTables(FileTable ftJoin)
ftJoin
- is the Table file to join to current Table
public void trimTableEnclWhitespace(boolean cleanHeaderFlag, boolean cleanDataFlag)
cleanHeaderFlag
- to clean the tFields and tHeadercleanDataFlag
- to clean the tDatapublic boolean sortTableRowsByField(java.lang.String sortField, boolean sortTblAscendingFlag, boolean useAbsValueFlag)
sortField
- is the field to sort by and to use in the thresholdinguseNumericSortFlag
- sort data numerically else by stringsortTblAscendingFlag
- to sort the table in ascending orderuseAbsValueFlag
- to ignore the sign of the data in the search.
If the table is sorted by numeric value, and both + and - changes
were found, it will set the this.needToSortTableAgainFlag
so the calling program can resort one more time if it wants.
to keep the data in numeric order.
public boolean sortTableRowsByField(int idxSortField, java.lang.String sortField, boolean sortTblAscendingFlag, boolean useAbsValueFlag)
idxSortField
- is the field index to sort by.sortField
- is the name of sort field to sort by for msgsuseNumericSortFlag
- sort data numerically else by stringsortTblAscendingFlag
- to sort the table in ascending orderuseAbsValueFlag
- to ignore the sign of the data in the search.
If the table is sorted by numeric value, and both + and - changes
were found, it will set the this.needToSortTableAgainFlag
so the calling program can resort one more time if it wants.
to keep the data in numeric order.
public boolean limitMaxRows(int maxRowsToKeep, boolean useAbsValueFlag)
maxRowsToKeep
- is the maximum number of rows to keep.useAbsValueFlag
- to ignore the sign of the data in the search.
If the table is sorted by numeric value, and both + and - changes
were found, it will set the this.needToSortTableAgainFlag
so the calling program can resort one more time if it wants.
public boolean limitMaxRowsSortedByField(java.lang.String sortField, boolean sortTblAscendingFlag, int maxRowsToKeep, boolean doSortFirstFlag, boolean useAbsValueFlag)
sortField
- is the field to sort by and to use in the thresholdingsortTblAscendingFlag
- maxRowsToKeep
- is the maximum number of rows to keep.useAbsValueFlag
- to ignore the sign of the data in the search.
If the table is sorted by numeric value, and both + and - changes
were found, it will set the this.needToSortTableAgainFlag
so the calling program can resort one more time if it wants.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |