Package io.slifer.csv
Class CsvFile
- java.lang.Object
-
- io.slifer.csv.CsvFile
-
public class CsvFile extends Object
Virtualizes a CSV file for fast and simple use in referencing and retrieving values.- Author:
- Tim Slifer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CsvFileclone()Creates a clone of the current instance of the object, allowing "save points" between filter/exclude operations, or multiple filter/exclude paths for a single file.List<String>columnValues(String column)Retrieves a list of all row values in a given column.String[]currentRowValues()Retrieves all values from the current row.CsvFileexclude(String excludeBy)Reduces the rows to those not matching a specific value in the first column.CsvFileexclude(String column, String excludeBy)Reduces the rows to those not matching a specific value in a given column.CsvFilefilter(String filterBy)Reduces the rows to those matching a specific value in the first column.CsvFilefilter(String column, String filterBy)Reduces the rows to those matching a specific value in a given column.booleanhasNextRow()Indicates whether or not another row exists below the current row.CsvFilesetCurrentRow(int row)Changes focus to a specific row.CsvFilesetNextRow()Updates focus to the next row beneath the current row.CsvFilesetPreviousRow()Updates focus to the previous row above the current row.StringvalueOf(String column)Retrieves the value of the given column from the current row.
-
-
-
Method Detail
-
filter
public CsvFile filter(String filterBy)
Reduces the rows to those matching a specific value in the first column.- Parameters:
filterBy- The value by which matching rows will be retained.- Returns:
- A self reference with the reduced data set.
-
filter
public CsvFile filter(String column, String filterBy)
Reduces the rows to those matching a specific value in a given column.- Parameters:
column- The Column value to be used for the filter.filterBy- The value by which matching rows will be retained.- Returns:
- A self reference with the reduced data set.
-
exclude
public CsvFile exclude(String excludeBy)
Reduces the rows to those not matching a specific value in the first column.- Parameters:
excludeBy- The value by which matching rows will be discarded.- Returns:
- A self reference with the reduced data set.
-
exclude
public CsvFile exclude(String column, String excludeBy)
Reduces the rows to those not matching a specific value in a given column.- Parameters:
column- The Column value to be used for the exclusion.excludeBy- The value by which the matching rows will be discarded.- Returns:
- A self reference with the reduced data set.
-
valueOf
public String valueOf(String column)
Retrieves the value of the given column from the current row.- Parameters:
column- The name of the column.- Returns:
- The value of the CSV segment.
-
columnValues
public List<String> columnValues(String column)
Retrieves a list of all row values in a given column.- Parameters:
column- The name of the column.- Returns:
- A list of CSV values from the specified column.
-
currentRowValues
public String[] currentRowValues()
Retrieves all values from the current row.- Returns:
- An array of values from the current row.
-
clone
public CsvFile clone()
Creates a clone of the current instance of the object, allowing "save points" between filter/exclude operations, or multiple filter/exclude paths for a single file.
-
setCurrentRow
public CsvFile setCurrentRow(int row)
Changes focus to a specific row.- Parameters:
row- The new row to receive focus.- Returns:
- A self reference.
-
setNextRow
public CsvFile setNextRow()
Updates focus to the next row beneath the current row.- Returns:
- A self reference.
-
setPreviousRow
public CsvFile setPreviousRow()
Updates focus to the previous row above the current row.- Returns:
- A self reference.
-
hasNextRow
public boolean hasNextRow()
Indicates whether or not another row exists below the current row.- Returns:
- True if a row exists, false otherwise.
-
-