Class TableUtils
java.lang.Object
org.troy.capstone.utils.TableUtils
Utility class for working with Tablesaw tables, including reading and writing CSV files.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateOnly exists to prevent Jacoco from complaining about the default constructor not being tested. -
Method Summary
Modifier and TypeMethodDescriptionprivate static CsvReadOptionscreateCsvReadOptions(String path) Helper method to create CSV read options with specified path.private static voidinsertIndexColumn(Table table) Inserts an index column into the given table, with values from 0 to rowCount-1.static TableReads the data from a CSV file into a Tablesaw Table, and adds an index column to the table.tableToRowList(Table table) Converts a Tablesaw Table to a list of Rows.static voidWrites the cleaned data CSV file.
-
Constructor Details
-
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
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
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
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
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
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.
-