Top Description Fields Constructors Methods
com.univocity.parsers.common.processor.core

pack-priv Class ColumnSplitter<T>

extends Object
Class Inheritance
Type Parameters
<T>
the type of values stored in the columns.
Imports
com.univocity.parsers.common.*, java.util.*

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.
Author
Univocity Software Pty Ltd - [email protected]
See Also
ColumnReader, AbstractColumnProcessor, AbstractObjectColumnProcessor, AbstractBatchedColumnProcessor, AbstractBatchedObjectColumnProcessor, Processor

Field Summary

Modifier and TypeField and Description
private long
private List<List<T>>
private int
private String[]
private long

Constructor Summary

AccessConstructor and Description
pack-priv
ColumnSplitter(int
the expected number of rows to be parsed
expectedRowCount
)

Creates a splitter allocating a space for a give number of expected rows to be read

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addValuesToColumns(T[]
the row whose column values will be split
row
,
Context
the current active parsing context.
context
)

Splits the row and add stores the value of each column in its corresponding list in columnValues

pack-priv void
clearValues()

Removes any column values previously processed

pack-priv List<List<T>>

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.
getColumnValues
()

Returns the values processed for each column

pack-priv <
the type of data in that column
V
>
List<V>

Returns:

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

Returns the values of a given column.

pack-priv <
the type of data in that column
V
>
List<V>

Returns:

a list with all data stored in the given column
getColumnValues
(String
the name of the column in the input.
columnName
,
Class<V>
the type of data in that column
columnType
)

Returns the values of a given column.

pack-priv Map<Integer, List<T>>

Returns:

a map of column indexes and their respective list of values.
getColumnValuesAsMapOfIndexes
()

Returns a map of column indexes and their respective list of values parsed from the input.

pack-priv Map<String, List<T>>

Returns:

a map of column names and their respective list of values.
getColumnValuesAsMapOfNames
()

Returns a map of column names and their respective list of values parsed from the input.

pack-priv String

Returns:

the name of the column at the given index, or null if there's no header defined for the given column index.
getHeader
(int
the index of the column whose header is to be obtained
columnIndex
)

Returns the header of a particular column

pack-priv String[]

Returns:

the headers of all records parsed.
getHeaders
()

Returns the headers of the input.

private void
initialize(Context
the current active parsing context, which will be used to obtain information about headers and selected fields.
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...)

pack-priv void
putColumnValuesInMapOfIndexes(Map<Integer, List<T>>
the map to hold the values of each column
map
)

Fills a given map associating each column index to its list of values

pack-priv void
putColumnValuesInMapOfNames(Map<String, List<T>>
the map to hold the values of each column
map
)

Fills a given map associating each column name to its list o values

pack-priv void
reset()

Prepares to execute a column splitting process from the beginning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addNullsFromback to summary
private long addNullsFrom
columnValuesback to summary
private List<List<T>> columnValues
expectedRowCountback to summary
private int expectedRowCount
headersback to summary
private String[] headers
rowCountback to summary
private long rowCount

Constructor Detail

ColumnSplitterback to summary
pack-priv ColumnSplitter(int expectedRowCount)

Creates a splitter allocating a space for a give number of expected rows to be read

Parameters
expectedRowCount:int

the expected number of rows to be parsed

Method Detail

addValuesToColumnsback to summary
pack-priv 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:T[]

the row whose column values will be split

context:Context

the current active parsing context.

clearValuesback to summary
pack-priv void clearValues()

Removes any column values previously processed

getColumnValuesback to summary
pack-priv List<List<T>> getColumnValues()

Returns the values processed for each column

Returns:List<List<T>>

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.

getColumnValuesback to summary
pack-priv <V> List<V> getColumnValues(int columnIndex, Class<V> columnType)

Returns the values of a given column.

Parameters
<V>
the type of data in that column
columnIndex:int

the position of the column in the input (0-based).

columnType:Class<V>

the type of data in that column

Returns:List<V>

a list with all data stored in the given column

getColumnValuesback to summary
pack-priv <V> List<V> getColumnValues(String columnName, Class<V> columnType)

Returns the values of a given column.

Parameters
<V>
the type of data in that column
columnName:String

the name of the column in the input.

columnType:Class<V>

the type of data in that column

Returns:List<V>

a list with all data stored in the given column

getColumnValuesAsMapOfIndexesback to summary
pack-priv Map<Integer, List<T>> getColumnValuesAsMapOfIndexes()

Returns a map of column indexes and their respective list of values parsed from the input.

Returns:Map<Integer, List<T>>

a map of column indexes and their respective list of values.

getColumnValuesAsMapOfNamesback to summary
pack-priv Map<String, List<T>> getColumnValuesAsMapOfNames()

Returns a map of column names and their respective list of values parsed from the input.

Returns:Map<String, List<T>>

a map of column names and their respective list of values.

getHeaderback to summary
pack-priv String getHeader(int columnIndex)

Returns the header of a particular column

Parameters
columnIndex:int

the index of the column whose header is to be obtained

Returns:String

the name of the column at the given index, or null if there's no header defined for the given column index.

getHeadersback to summary
pack-priv 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:String[]

the headers of all records parsed.

initializeback to summary
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:Context

the current active parsing context, which will be used to obtain information about headers and selected fields.

putColumnValuesInMapOfIndexesback to summary
pack-priv void putColumnValuesInMapOfIndexes(Map<Integer, List<T>> map)

Fills a given map associating each column index to its list of values

Parameters
map:Map<Integer, List<T>>

the map to hold the values of each column

putColumnValuesInMapOfNamesback to summary
pack-priv void putColumnValuesInMapOfNames(Map<String, List<T>> map)

Fills a given map associating each column name to its list o values

Parameters
map:Map<String, List<T>>

the map to hold the values of each column

Exceptions
IllegalArgumentException:
if a column does not have a name associated to it. In this case, use putColumnValuesInMapOfIndexes(Map) instead.
resetback to summary
pack-priv 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.