Package com.day.text
Class StringTable
java.lang.Object
com.day.text.StringTable
The
StringTable class easy handling of string tables, especially
creating tables from strings and lists. The table constructed is guaranteed
to be complete in that each row has the exact same number of columns and
each table cell is guaranteed to not be null.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringTablefromString(String srcString, String delims) Constructor does the hard work converting the string Creates a new table from the string, where the fields are separated by any one of the delimiters.static StringTablefromString(String srcString, String delims, boolean preserveEmptyRows) Constructor does the hard work converting the string Creates a new table from the string, where the fields are separated by any one of the delimiters.intgetCols()Returns the number of columns in the table.intgetRows()Returns the number of rows in the table.String[][]getTable()Returns the string table created.Transposes the table - cols will be rows and rows will be cols.
-
Method Details
-
fromString
Constructor does the hard work converting the string Creates a new table from the string, where the fields are separated by any one of the delimiters. Consecutive delimiters define empty field values. The table rows in the string are separated by either CR, LF or both. So neither CR nor LF may be used as a field delimiter.The string is logically split on CR/LF to get the rows. Each row is then split on the delimiters to get the cells.
Any empty rows in the string table are preserved as empty rows in the resulting table.
- Parameters:
srcString- The string from which to construct the tabledelims- The delimiters for columns.- Returns:
- The table from the string.
-
fromString
Constructor does the hard work converting the string Creates a new table from the string, where the fields are separated by any one of the delimiters. Consecutive delimiters define empty field values. The table rows in the string are separated by either CR, LF or both. So neither CR nor LF may be used as a field delimiter.The string is logically split on CR/LF to get the rows. Each row is then split on the delimiters to get the cells.
- Parameters:
srcString- The string from which to construct the tabledelims- The delimiters for columns.preserveEmptyRows- Iftrueempty rows in the input string are added as empty rows in the table. Otherwise empty rows in the input are ignored.- Returns:
- The table from the string.
-
transpose
Transposes the table - cols will be rows and rows will be cols. The operation is that the table is mirrored on the diagonal from 0/0 to n/n. -
getTable
Returns the string table created. This is the original table, so modifying entries in this object, also modifies the table. Especially modifying array elements of the first dimension may invalidate the class invariant, in that the table is not complete anymore. User beware.- Returns:
- The string table
-
getRows
public int getRows()Returns the number of rows in the table. -
getCols
public int getCols()Returns the number of columns in the table.
-