Package com.day.text

Class StringTable


  • public class StringTable
    extends java.lang.Object
    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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static StringTable fromString​(java.lang.String srcString, java.lang.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 StringTable fromString​(java.lang.String srcString, java.lang.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.
      int getCols()
      Returns the number of columns in the table.
      int getRows()
      Returns the number of rows in the table.
      java.lang.String[][] getTable()
      Returns the string table created.
      StringTable transpose()
      Transposes the table - cols will be rows and rows will be cols.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • fromString

        public static StringTable fromString​(java.lang.String srcString,
                                             java.lang.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. 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 table
        delims - The delimiters for columns.
        Returns:
        The table from the string.
      • fromString

        public static StringTable fromString​(java.lang.String srcString,
                                             java.lang.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. 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 table
        delims - The delimiters for columns.
        preserveEmptyRows - If true empty 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

        public StringTable 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

        public java.lang.String[][] 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.