Class CSVRecord

java.lang.Object
nl.colorize.util.stats.CSVRecord

public class CSVRecord extends Object
One of the records witin a CSV file. Records are usually parsed from a CSV file using CSVFormat, but can also be created programmatically. Fields within the record can be retrieved by index or by column name. The latter is only available if the CSV contains column information.

Note: This class is intended for basic CSV support. When working with CSV files produced by other applications, prefer using the FastCSV library.

  • Constructor Details

    • CSVRecord

      protected CSVRecord(List<String> columns, List<String> cells, CSVFormat format)
      Creates a new CSV record from the specified cells. The column information is optional: null indicates that no column information is available, meaning that cells can only be retrieved by index.

      CSVRecord instances are normally by obtained by parsing CSV files using CSVFormat. There is normally no need for applications to use this constructor directly.

  • Method Details

    • get

      public String get(int index)
      Returns the value of the cell with the specified index. This method is always available, even if the CSV file does not include any column information.
      Throws:
      IllegalArgumentException - if the column index is invalid.
    • hasColumnInformation

      public boolean hasColumnInformation()
      Returns true if this CSV record included column information. If false, cells can only be accessed by index, not by column name.
    • get

      public String get(String column)
      Returns the value for the cell with the specified column name.
      Throws:
      IllegalStateException - if no column name information is available.
      IllegalArgumentException - if no column with that name exists.
    • getColumns

      public List<String> getColumns()
      Returns a list of all named columns in this CSV record. The columns will be sorted in the same order as they appear in the CSV.
      Throws:
      IllegalStateException - if no column name information is available.
    • getColumnValues

      public TupleList<String,String> getColumnValues()
      Returns a list of column values for all cells in this CSV record. Each tuple in the list consists of the column name and corresponding cell value. The list will be sorted to match the order in which the columns appear in the CSV.
      Throws:
      IllegalStateException - if no column name information is available.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCells

      public List<String> getCells()
    • getFormat

      public CSVFormat getFormat()