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.
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
.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionColumnSplitter
(int expectedRowCount) Creates a splitter allocating a space for a give number of expected rows to be read -
Method Summary
Modifier and TypeMethodDescription(package private) void
addValuesToColumns
(T[] row, Context context) Splits the row and add stores the value of each column in its corresponding list incolumnValues
(package private) void
Removes any column values previously processedReturns the values processed for each column(package private) <V> List<V>
getColumnValues
(int columnIndex, Class<V> columnType) Returns the values of a given column.(package private) <V> List<V>
getColumnValues
(String columnName, Class<V> columnType) Returns the values of a given column.Returns a map of column indexes and their respective list of values parsed from the input.Returns a map of column names and their respective list of values parsed from the input.(package private) String
getHeader
(int columnIndex) Returns the header of a particular column(package private) String[]
Returns the headers of the input.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...)
(package private) void
putColumnValuesInMapOfIndexes
(Map<Integer, List<T>> map) Fills a given map associating each column index to its list of values(package private) void
putColumnValuesInMapOfNames
(Map<String, List<T>> map) Fills a given map associating each column name to its list o values(package private) void
reset()
Prepares to execute a column splitting process from the beginning.
-
Field Details
-
columnValues
-
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
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 inCommonSettings.getHeaders()
or the headers parsed in the input whenCommonSettings.getHeaders()
equals totrue
- Returns:
- the headers of all records parsed.
-
initialize
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
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
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
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, useputColumnValuesInMapOfIndexes(Map)
instead.
-
getColumnValues
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
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
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
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
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.
-