Class ColumnSplitter<T>

java.lang.Object
com.univocity.parsers.common.processor.core.ColumnSplitter<T>
Type Parameters:
T - the type of values stored in the columns.

class ColumnSplitter<T> extends Object
A utility class used split and store values columns parsed from each row in a Processor. Used to centralize common code used by implementations of ColumnReader, namely: AbstractColumnProcessor, AbstractObjectColumnProcessor, AbstractBatchedColumnProcessor and AbstractBatchedObjectColumnProcessor.
See Also:
  • Field Details

    • columnValues

      private List<List<T>> columnValues
    • headers

      private String[] headers
    • expectedRowCount

      private int expectedRowCount
    • rowCount

      private long rowCount
    • addNullsFrom

      private long addNullsFrom
  • Constructor Details

    • ColumnSplitter

      ColumnSplitter(int expectedRowCount)
      Creates a splitter allocating a space for a give number of expected rows to be read
      Parameters:
      expectedRowCount - the expected number of rows to be parsed
  • Method Details

    • clearValues

      void clearValues()
      Removes any column values previously processed
    • reset

      void reset()
      Prepares to execute a column splitting process from the beginning. Removes any column values previously processed, as well as information about headers in the input. Resets row count to 0.
    • getColumnValues

      List<List<T>> getColumnValues()
      Returns the values processed for each column
      Returns:
      a list of lists. The stored lists correspond to the position of the column processed from the input; Each list contains the corresponding values parsed for a column, across multiple rows.
    • getHeaders

      String[] getHeaders()
      Returns the headers of the input. This can be either the headers defined in CommonSettings.getHeaders() or the headers parsed in the input when CommonSettings.getHeaders() equals to true
      Returns:
      the headers of all records parsed.
    • initialize

      private void initialize(Context context)
      Initializes the list of column values, the headers of each column and which columns to read if fields have been selected using CommonSettings.selectFields(String...) or CommonSettings.selectIndexes(Integer...)
      Parameters:
      context - the current active parsing context, which will be used to obtain information about headers and selected fields.
    • getHeader

      String getHeader(int columnIndex)
      Returns the header of a particular column
      Parameters:
      columnIndex - the index of the column whose header is to be obtained
      Returns:
      the name of the column at the given index, or null if there's no header defined for the given column index.
    • addValuesToColumns

      void addValuesToColumns(T[] row, Context context)
      Splits the row and add stores the value of each column in its corresponding list in columnValues
      Parameters:
      row - the row whose column values will be split
      context - the current active parsing context.
    • putColumnValuesInMapOfNames

      void putColumnValuesInMapOfNames(Map<String,List<T>> map)
      Fills a given map associating each column name to its list o values
      Parameters:
      map - the map to hold the values of each column
      Throws:
      IllegalArgumentException - if a column does not have a name associated to it. In this case, use putColumnValuesInMapOfIndexes(Map) instead.
    • getColumnValues

      <V> List<V> getColumnValues(int columnIndex, Class<V> columnType)
      Returns the values of a given column.
      Type Parameters:
      V - the type of data in that column
      Parameters:
      columnIndex - the position of the column in the input (0-based).
      columnType - the type of data in that column
      Returns:
      a list with all data stored in the given column
    • getColumnValues

      <V> List<V> getColumnValues(String columnName, Class<V> columnType)
      Returns the values of a given column.
      Type Parameters:
      V - the type of data in that column
      Parameters:
      columnName - the name of the column in the input.
      columnType - the type of data in that column
      Returns:
      a list with all data stored in the given column
    • putColumnValuesInMapOfIndexes

      void putColumnValuesInMapOfIndexes(Map<Integer,List<T>> map)
      Fills a given map associating each column index to its list of values
      Parameters:
      map - the map to hold the values of each column
    • getColumnValuesAsMapOfNames

      Map<String,List<T>> getColumnValuesAsMapOfNames()
      Returns a map of column names and their respective list of values parsed from the input.
      Returns:
      a map of column names and their respective list of values.
    • getColumnValuesAsMapOfIndexes

      Map<Integer,List<T>> getColumnValuesAsMapOfIndexes()
      Returns a map of column indexes and their respective list of values parsed from the input.
      Returns:
      a map of column indexes and their respective list of values.