Class CTable


  • public class CTable
    extends CList
    The `CTable` class represents a customizable table for displaying tabular data on a screen. It extends the `CList` class to inherit basic list functionality.
    • Constructor Detail

      • CTable

        public CTable​(String... columnHeader)
        Constructs a `CTable` with the specified column headers.
        Parameters:
        columnHeader - The headers for each column.
      • CTable

        public CTable​(List<List<String>> arr,
                      String... columnHeader)
        Constructs a `CTable` with the specified 2D list and column headers.
        Parameters:
        arr - The 2D list representing the table data.
        columnHeader - The headers for each column.
      • CTable

        public CTable​(String[][] arr,
                      String... columnHeader)
        Constructs a `CTable` with the specified 2D array and column headers.
        Parameters:
        arr - The 2D array representing the table data.
        columnHeader - The headers for each column.
      • CTable

        public CTable​(List<List<String>> arr,
                      Position pos,
                      boolean hasSeparator,
                      String... columnHeader)
        Constructs a `CTable` with the specified 2D list, column headers, position, and separator option.
        Parameters:
        arr - The 2D list representing the table data.
        pos - The position of the table title.
        hasSeparator - Indicates whether to use a separator between columns.
        columnHeader - The headers for each column.
    • Method Detail

      • display

        public void display()
        Displays the table on the screen.
        Overrides:
        display in class CList
      • hasSeparator

        public void hasSeparator​(boolean hasSeparator)
        Sets whether the table has a separator between columns.
        Parameters:
        hasSeparator - Indicates whether to use a separator.
      • addRow

        public void addRow​(String... row)
        Adds a row to the table.
        Parameters:
        row - The values to be added as a row.
      • getRow

        public List<String> getRow​(int index)
        Retrieves the values of a specific row.
        Parameters:
        index - The index of the row to retrieve.
        Returns:
        The values of the specified row.
      • getColumn

        public List<String> getColumn​(int index)
        Retrieves the values of a specific column.
        Parameters:
        index - The index of the column to retrieve.
        Returns:
        The values of the specified column.
      • removeRow

        public void removeRow​(int index)
        Removes a row from the table.
        Parameters:
        index - The index of the row to be removed.
      • getCell

        public String getCell​(int row,
                              int column)
        Retrieves the value of a specific cell in the table.
        Parameters:
        row - The row index of the cell.
        column - The column index of the cell.
        Returns:
        The value of the specified cell.
      • setCell

        public void setCell​(int row,
                            int column,
                            String str)
        Sets the value of a specific cell in the table.
        Parameters:
        row - The row index of the cell.
        column - The column index of the cell.
        str - The new value for the cell.
      • addList

        public void addList​(List<List<String>> arr)
        Adds a list of rows to the table.
        Parameters:
        arr - The 2D list representing the rows to be added.
      • findRows

        public List<List<String>> findRows​(int column,
                                           String text)
        Finds and retrieves rows based on a specified column and text.
        Parameters:
        column - The index of the column to search.
        text - The text to search for in the specified column.
        Returns:
        The list of rows matching the search criteria.
      • setColumnAlignment

        public void setColumnAlignment​(int columnIndex,
                                       Position position)
        Sets the alignment for a specific column in the table.
        Parameters:
        columnIndex - The index of the column.
        position - The alignment position for the column.
      • setColumnAlignment

        public void setColumnAlignment​(Position position)
        Sets the alignment for all columns in the table.
        Parameters:
        position - The alignment position for all the columns.
      • getTotal

        public int getTotal​(int columnIndex)
        Calculates the total sum of numeric values in a specific column.
        Parameters:
        columnIndex - The index of the column.
        Returns:
        The total sum of numeric values in the specified column.
      • getDoubleTotal

        public double getDoubleTotal​(int columnIndex)
        Calculates the total sum of floating-point values in a specific column.
        Parameters:
        columnIndex - The index of the column.
        Returns:
        The total sum of floating-point values in the specified column.