Package io.slifer.csv

Class CsvFile


  • public class CsvFile
    extends Object
    Virtualizes a CSV file for fast and simple use in referencing and retrieving values.
    Author:
    Tim Slifer
    • 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.
        Overrides:
        clone in class Object
        Returns:
        A new instance of CsvFile, with the current Header and Row data.
      • 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.