Class AbstractTable

  • All Implemented Interfaces:
    Table
    Direct Known Subclasses:
    CsvTable, HtmlTable

    public abstract class AbstractTable
    extends Object
    implements Table
    An abstract base class for implementing data tables.
    Author:
    Manoel Campos da Silva Filho
    • Constructor Detail

      • AbstractTable

        public AbstractTable()
      • AbstractTable

        public AbstractTable​(String title)
        Creates an Table
        Parameters:
        title - Title of the table
    • Method Detail

      • getTitle

        public String getTitle()
        Specified by:
        getTitle in interface Table
        Returns:
        the table title
      • setTitle

        public final Table setTitle​(String title)
        Specified by:
        setTitle in interface Table
        Parameters:
        title - the table title to set
        Returns:
        The Table instance
      • getColumnSeparator

        public String getColumnSeparator()
        Description copied from interface: Table
        Gets the string used to separate one column from another (optional).
        Specified by:
        getColumnSeparator in interface Table
        Returns:
      • setColumnSeparator

        public final Table setColumnSeparator​(String columnSeparator)
        Description copied from interface: Table
        Sets the string used to separate one column from another (optional).
        Specified by:
        setColumnSeparator in interface Table
        Parameters:
        columnSeparator - the separator to set
        Returns:
      • getRows

        protected List<List<Object>> getRows()
        Returns:
        The data to be printed, where each row contains a list of data columns.
      • newRow

        public List<Object> newRow()
        Description copied from interface: Table
        Adds a new row to the list of rows containing the data to be printed.
        Specified by:
        newRow in interface Table
        Returns:
      • print

        public void print()
        Description copied from interface: Table
        Prints the table.
        Specified by:
        print in interface Table
      • printColumnHeaders

        protected void printColumnHeaders()
      • printTableOpening

        protected abstract void printTableOpening()
        Prints the string to open the table.
      • printTitle

        protected abstract void printTitle()
        Prints the table title.
      • printRowOpening

        protected abstract void printRowOpening()
        Prints the string that has to precede each printed row.
      • printRowClosing

        protected abstract void printRowClosing()
        Prints the string to close a row.
      • printTableClosing

        protected abstract void printTableClosing()
        Prints the string to close the table.
      • addColumnList

        public final Table addColumnList​(String... columnTitles)
        Description copied from interface: Table
        Adds a list of columns (with given titles) to the end of the table's columns to be printed, where the column data will be printed without a specific format.
        Specified by:
        addColumnList in interface Table
        Parameters:
        columnTitles - The titles of the columns
        Returns:
        the Table instance.
        See Also:
        Table.addColumn(String)
      • addColumn

        public final TableColumn addColumn​(String columnTitle)
        Description copied from interface: Table
        Adds a column with a given to the end of the table's columns to be printed.
        Specified by:
        addColumn in interface Table
        Parameters:
        columnTitle - The title of the column to be added.
        Returns:
        The created column.
      • addColumn

        public final TableColumn addColumn​(String columnTitle,
                                           String columnSubTitle)
        Description copied from interface: Table
        Adds a column with a given title and sub-title to the end of the table's columns to be printed.
        Specified by:
        addColumn in interface Table
        Parameters:
        columnTitle - The title of the column to be added.
        columnSubTitle - The sub-title of the column to be added.
        Returns:
        the created column
      • addColumn

        public final TableColumn addColumn​(int index,
                                           TableColumn column)
        Description copied from interface: Table
        Adds a column object to a specific position of the table's columns to be printed.
        Specified by:
        addColumn in interface Table
        Parameters:
        index - the position to insert the column into the column's list
        column - The column to be added.
        Returns:
        the created column
      • addColumn

        public final TableColumn addColumn​(TableColumn column)
        Description copied from interface: Table
        Adds a column object to the end of the table's columns to be printed.
        Specified by:
        addColumn in interface Table
        Parameters:
        column - The column to be added.
        Returns:
        the created column
      • setPrintStream

        public void setPrintStream​(PrintStream printStream)
        Sets the PrintStream used to print the generated table.
        Parameters:
        printStream - the PrintStream to set