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 java.lang.ObjectA utility class used split and store values columns parsed from each row in aProcessor. Used to centralize common code used by implementations ofColumnReader, namely:AbstractColumnProcessor,AbstractObjectColumnProcessor,AbstractBatchedColumnProcessorandAbstractBatchedObjectColumnProcessor.
-
-
Field Summary
Fields Modifier and Type Field Description private longaddNullsFromprivate java.util.List<java.util.List<T>>columnValuesprivate intexpectedRowCountprivate java.lang.String[]headersprivate longrowCount
-
Constructor Summary
Constructors Constructor Description ColumnSplitter(int expectedRowCount)Creates a splitter allocating a space for a give number of expected rows to be read
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddValuesToColumns(T[] row, Context context)Splits the row and add stores the value of each column in its corresponding list incolumnValues(package private) voidclearValues()Removes any column values previously processed(package private) java.util.List<java.util.List<T>>getColumnValues()Returns the values processed for each column(package private) <V> java.util.List<V>getColumnValues(int columnIndex, java.lang.Class<V> columnType)Returns the values of a given column.(package private) <V> java.util.List<V>getColumnValues(java.lang.String columnName, java.lang.Class<V> columnType)Returns the values of a given column.(package private) java.util.Map<java.lang.Integer,java.util.List<T>>getColumnValuesAsMapOfIndexes()Returns a map of column indexes and their respective list of values parsed from the input.(package private) java.util.Map<java.lang.String,java.util.List<T>>getColumnValuesAsMapOfNames()Returns a map of column names and their respective list of values parsed from the input.(package private) java.lang.StringgetHeader(int columnIndex)Returns the header of a particular column(package private) java.lang.String[]getHeaders()Returns the headers of the input.private voidinitialize(Context context)Initializes the list of column values, the headers of each column and which columns to read if fields have been selected usingCommonSettings.selectFields(String...)orCommonSettings.selectIndexes(Integer...)(package private) voidputColumnValuesInMapOfIndexes(java.util.Map<java.lang.Integer,java.util.List<T>> map)Fills a given map associating each column index to its list of values(package private) voidputColumnValuesInMapOfNames(java.util.Map<java.lang.String,java.util.List<T>> map)Fills a given map associating each column name to its list o values(package private) voidreset()Prepares to execute a column splitting process from the beginning.
-
-
-
Field Detail
-
columnValues
private java.util.List<java.util.List<T>> columnValues
-
headers
private java.lang.String[] headers
-
expectedRowCount
private int expectedRowCount
-
rowCount
private long rowCount
-
addNullsFrom
private long addNullsFrom
-
-
Method Detail
-
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
java.util.List<java.util.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
java.lang.String[] getHeaders()
Returns the headers of the input. This can be either the headers defined inCommonSettings.getHeaders()or the headers parsed in the input whenCommonSettings.getHeaders()equals totrue- 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 usingCommonSettings.selectFields(String...)orCommonSettings.selectIndexes(Integer...)- Parameters:
context- the current active parsing context, which will be used to obtain information about headers and selected fields.
-
getHeader
java.lang.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 incolumnValues- Parameters:
row- the row whose column values will be splitcontext- the current active parsing context.
-
putColumnValuesInMapOfNames
void putColumnValuesInMapOfNames(java.util.Map<java.lang.String,java.util.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:
java.lang.IllegalArgumentException- if a column does not have a name associated to it. In this case, useputColumnValuesInMapOfIndexes(Map)instead.
-
getColumnValues
<V> java.util.List<V> getColumnValues(int columnIndex, java.lang.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> java.util.List<V> getColumnValues(java.lang.String columnName, java.lang.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(java.util.Map<java.lang.Integer,java.util.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
java.util.Map<java.lang.String,java.util.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
java.util.Map<java.lang.Integer,java.util.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.
-
-