Class TableUtils

java.lang.Object
org.troy.capstone.utils.TableUtils

public class TableUtils extends Object
Utility class for working with Tablesaw tables, including reading and writing CSV files.
  • Constructor Details

    • TableUtils

      @Generated private TableUtils()
      Only exists to prevent Jacoco from complaining about the default constructor not being tested. As the only function of this class is to provide static methods, there is no reason for it to be instantiated, so the constructor is private.
  • Method Details

    • createCsvReadOptions

      private static CsvReadOptions createCsvReadOptions(String path)
      Helper method to create CSV read options with specified path.
      Parameters:
      path - The path to the CSV file.
      Returns:
      CsvReadOptions configured with the specified path and column types.
    • readData

      public static Table readData(DataPath dataPath)
      Reads the data from a CSV file into a Tablesaw Table, and adds an index column to the table.
      Parameters:
      dataPath - The DataPath enum value representing the path to the CSV file to be read.
      Returns:
      A Tablesaw Table containing the data from the cleaned data CSV file, with an added index column.
      Preconditions:
      The cleaned data CSV file exists with the right data.
    • writeData

      @Generated public static void writeData(Table table, DataPath dataPath)
      Writes the cleaned data CSV file.
      Parameters:
      table - The Tablesaw Table containing the data to be written.
      dataPath - The DataPath enum value representing the path to the CSV file to be written.
      Postconditions:
      The cleaned data CSV file is created at the specified path, containing the data from the provided table.
    • insertIndexColumn

      private static void insertIndexColumn(Table table)
      Inserts an index column into the given table, with values from 0 to rowCount-1.
      Parameters:
      table - The Tablesaw Table to have the index column inserted. The table must not already contain a column with the name specified by TableColumnName.INDEX.
    • tableToRowList

      public static List<Row> tableToRowList(Table table)
      Converts a Tablesaw Table to a list of Rows. Uses a loop instead of stream due to stream returning a list of the same row repeated.
      Parameters:
      table - The Tablesaw Table to be converted.
      Returns:
      A list of Rows representing the data in the table.
      Preconditions:
      table is not null and contains at least one row. The rows in the table are properly formatted and contain the expected columns for the application.