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

public Class OutputValueSwitch

extends RowWriterProcessorSwitch
Class Inheritance
Imports
com.univocity.parsers.annotations.helpers.*, com.univocity.parsers.common.*, java.util.ArrayList, .Arrays, .Comparator, .List, .Map

A concrete implementation of RowWriterProcessorSwitch that allows switching among different implementations of RowWriterProcessor based on values found on rows to be written to an output

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final int
private Comparator<T>
private OutputValueSwitch.Switch
private final String
private OutputValueSwitch.Switch
private OutputValueSwitch.Switch[]
private Class<T>[]

Constructor Summary

AccessConstructor and Description
public
OutputValueSwitch()

Creates a switch that will analyze the first column of output rows to determine which RowWriterProcessor to use for each output row

public
OutputValueSwitch(int
the column index whose value will be used to determine which RowWriterProcessor to use for each output row.
columnIndex
)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

public
OutputValueSwitch(String
the column name whose value will be used to determine which RowWriterProcessor to use for each output row.
headerName
)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

public
OutputValueSwitch(String
the column name whose value will be used to determine which RowWriterProcessor to use for each output row.
headerName
,
int
the position of an input column to use to perform the switch when no headers are available.
columnIndex
)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

Method Summary

Modifier and TypeMethod and Description
private void
public <
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
T
>
void
addSwitchForType(Class<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType
,
String...
the (optional) sequence of headers to assign to the given row writer processor
headersToUse
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

public <
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
T
>
void
addSwitchForType(Class<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType
,
int...
the (optional) sequence of column indexes to assign to the given row writer processor
indexesToUse
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

public <
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
T
>
void
addSwitchForType(Class<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

public void
addSwitchForValue(Object
the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
value
,
RowWriterProcessor<Object[]>
the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.
rowProcessor
,
String...
the (optional) sequence of headers to assign to the given row writer processor
headersToUse
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

public void
addSwitchForValue(Object
the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
value
,
RowWriterProcessor<Object[]>
the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.
rowProcessor
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

public void
addSwitchForValue(Object
the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
value
,
RowWriterProcessor<Object[]>
the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.
rowProcessor
,
int...
the (optional) sequence of column indexes to assign to the given row writer processor
indexesToUse
)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

protected String
public int

Returns:

the column index targeted by this switch.
getColumnIndex
()

Returns the column index whose values will be used to switching from a row processor to another.

protected NormalizedString[]
getHeaders()

Overrides com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.
public NormalizedString[]
getHeaders(Object
the record data
input
)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the sequence of headers to use for processing an input record.
public NormalizedString[]
getHeaders(Map<K, V>
an optional map associating keys of the rowData map with expected header names
headerMapping
,
Map<K, V>
the record data
mapInput
)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the sequence of headers to use for processing an input record represented by a map A map of headers can be optionally provided to assign a name to the keys of the input map.
private NormalizedString[]
protected int[]
getIndexes()

Overrides com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getIndexes.

Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.
private OutputValueSwitch.Switch
private List<Object>
private String
private int
getValidatedIndex(int columnIndex)

private <V> V
getValue(Map<?, V> map, int index)

public void
setComparator(Comparator<?>
the comparator to use for matching values in the output column with the values provided in addSwitchForValue(Object, RowWriterProcessor)
comparator
)

Configures the switch to use a custom Comparator to compare values in the column to analyze which is given in the constructor of this class.

public void
setDefaultSwitch(RowWriterProcessor<Object[]>
the default row writer processor implementation
rowProcessor
,
String...
the (optional) sequence of headers to assign to the given row writer processor
headersToUse
)

Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.

public void
setDefaultSwitch(RowWriterProcessor<Object[]>
the default row writer processor implementation
rowProcessor
,
int...
the (optional) sequence of column indexes to assign to the given row writer processor
indexesToUse
)

Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.

protected RowWriterProcessor<?>
switchRowProcessor(Object
a record with data to be written to the output
row
)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.switchRowProcessor.

Analyzes an output row to determine whether or not the row writer processor implementation must be changed
Inherited from com.univocity.parsers.common.processor.RowWriterProcessorSwitch:
getMinimumRowLengthrowProcessorSwitchedwritewrite

Field Detail

columnIndexback to summary
private final int columnIndex
comparatorback to summary
private Comparator<T> comparator
Annotations
@SuppressWarnings:rawtypes
defaultSwitchback to summary
private OutputValueSwitch.Switch defaultSwitch
headerNameback to summary
private final String headerName
selectedSwitchback to summary
private OutputValueSwitch.Switch selectedSwitch
switchesback to summary
private OutputValueSwitch.Switch[] switches
typesback to summary
private Class<T>[] types

Constructor Detail

OutputValueSwitchback to summary
public OutputValueSwitch()

Creates a switch that will analyze the first column of output rows to determine which RowWriterProcessor to use for each output row

OutputValueSwitchback to summary
public OutputValueSwitch(int columnIndex)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

Parameters
columnIndex:int

the column index whose value will be used to determine which RowWriterProcessor to use for each output row.

OutputValueSwitchback to summary
public OutputValueSwitch(String headerName)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use. When no column index is defined, the switch will use the first column of any input rows sent for writing.

Parameters
headerName:String

the column name whose value will be used to determine which RowWriterProcessor to use for each output row.

OutputValueSwitchback to summary
public OutputValueSwitch(String headerName, int columnIndex)

Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

Parameters
headerName:String

the column name whose value will be used to determine which RowWriterProcessor to use for each output row.

columnIndex:int

the position of an input column to use to perform the switch when no headers are available.

Method Detail

addSwitchback to summary
private void addSwitch(OutputValueSwitch.Switch newSwitch)
addSwitchForTypeback to summary
public <T> void addSwitchForType(Class<T> beanType, String... headersToUse)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType:Class<T>

the type of annotated java beans whose instances will be used to trigger the usage of a different format.

headersToUse:String[]

the (optional) sequence of headers to assign to the given row writer processor

addSwitchForTypeback to summary
public <T> void addSwitchForType(Class<T> beanType, int... indexesToUse)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType:Class<T>

the type of annotated java beans whose instances will be used to trigger the usage of a different format.

indexesToUse:int[]

the (optional) sequence of column indexes to assign to the given row writer processor

addSwitchForTypeback to summary
public <T> void addSwitchForType(Class<T> beanType)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
<T>
the type of annotated java beans whose instances will be used to trigger the usage of a different format.
beanType:Class<T>

the type of annotated java beans whose instances will be used to trigger the usage of a different format.

addSwitchForValueback to summary
public void addSwitchForValue(Object value, RowWriterProcessor<Object[]> rowProcessor, String... headersToUse)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
value:Object

the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.

rowProcessor:RowWriterProcessor<Object[]>

the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.

headersToUse:String[]

the (optional) sequence of headers to assign to the given row writer processor

addSwitchForValueback to summary
public void addSwitchForValue(Object value, RowWriterProcessor<Object[]> rowProcessor)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
value:Object

the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.

rowProcessor:RowWriterProcessor<Object[]>

the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.

addSwitchForValueback to summary
public void addSwitchForValue(Object value, RowWriterProcessor<Object[]> rowProcessor, int... indexesToUse)

Associates a RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class.

Parameters
value:Object

the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.

rowProcessor:RowWriterProcessor<Object[]>

the row writer processor implementation to use when the given value matches with the contents of the column provided in the constructor of this class.

indexesToUse:int[]

the (optional) sequence of column indexes to assign to the given row writer processor

describeSwitchback to summary
protected String describeSwitch()

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.describeSwitch.

Annotations
@Override
getColumnIndexback to summary
public int getColumnIndex()

Returns the column index whose values will be used to switching from a row processor to another.

Returns:int

the column index targeted by this switch.

getHeadersback to summary
protected NormalizedString[] getHeaders()

Overrides com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Doc from com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors. If null, the headers defined in CommonWriterSettings#getHeaders() will be returned.

Returns:NormalizedString[]

the current sequence of headers to use.

Annotations
@Override
getHeadersback to summary
public NormalizedString[] getHeaders(Object input)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Doc from com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the sequence of headers to use for processing an input record.

Parameters
input:Object

the record data

Returns:NormalizedString[]

the sequence of headers to use when processing the given record.

Annotations
@Override
getHeadersback to summary
public NormalizedString[] getHeaders(Map<K, V> headerMapping, Map<K, V> mapInput)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Doc from com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getHeaders.

Returns the sequence of headers to use for processing an input record represented by a map A map of headers can be optionally provided to assign a name to the keys of the input map. This is useful when the input map has keys will generate unwanted header names.

Parameters
headerMapping:Map<K, V>

an optional map associating keys of the rowData map with expected header names

mapInput:Map<K, V>

the record data

Returns:NormalizedString[]

the sequence of headers to use when processing the given input map.

Annotations
@Override
getHeadersFromSwitchback to summary
private NormalizedString[] getHeadersFromSwitch(Object value)
getIndexesback to summary
protected int[] getIndexes()

Overrides com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getIndexes.

Doc from com.univocity.parsers.common.processor.RowWriterProcessorSwitch.getIndexes.

Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors. If null, the indexes of fields that have been selected using CommonSettings#selectFields(String...) or CommonSettings#selectIndexes(Integer...) will be returned.

Returns:int[]

the current sequence of indexes to use.

Annotations
@Override
getSwitchback to summary
private OutputValueSwitch.Switch getSwitch(Object value)
getSwitchValuesback to summary
private List<Object> getSwitchValues()
getValidatedHeaderNameback to summary
private String getValidatedHeaderName(String headerName)
getValidatedIndexback to summary
private int getValidatedIndex(int columnIndex)
getValueback to summary
private <V> V getValue(Map<?, V> map, int index)
setComparatorback to summary
public void setComparator(Comparator<?> comparator)

Configures the switch to use a custom Comparator to compare values in the column to analyze which is given in the constructor of this class.

Parameters
comparator:Comparator<?>

the comparator to use for matching values in the output column with the values provided in addSwitchForValue(Object, RowWriterProcessor)

setDefaultSwitchback to summary
public void setDefaultSwitch(RowWriterProcessor<Object[]> rowProcessor, String... headersToUse)

Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.

Parameters
rowProcessor:RowWriterProcessor<Object[]>

the default row writer processor implementation

headersToUse:String[]

the (optional) sequence of headers to assign to the given row writer processor

setDefaultSwitchback to summary
public void setDefaultSwitch(RowWriterProcessor<Object[]> rowProcessor, int... indexesToUse)

Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.

Parameters
rowProcessor:RowWriterProcessor<Object[]>

the default row writer processor implementation

indexesToUse:int[]

the (optional) sequence of column indexes to assign to the given row writer processor

switchRowProcessorback to summary
protected RowWriterProcessor<?> switchRowProcessor(Object row)

Implements abstract com.univocity.parsers.common.processor.RowWriterProcessorSwitch.switchRowProcessor.

Doc from com.univocity.parsers.common.processor.RowWriterProcessorSwitch.switchRowProcessor.

Analyzes an output row to determine whether or not the row writer processor implementation must be changed

Parameters
row:Object

a record with data to be written to the output

Returns:RowWriterProcessor<?>

the row writer processor implementation to use. If it is not the same as the one used by the previous row, the returned row writer processor will be used, and the rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor) method will be called.

Annotations
@SuppressWarnings:unchecked
@Override
com.univocity.parsers.common.processor back to summary

private Class OutputValueSwitch.Switch

extends Object
Class Inheritance
  • java.lang.Object
  • com.univocity.parsers.common.processor.OutputValueSwitch.Switch

Field Summary

Modifier and TypeField and Description
pack-priv final NormalizedString[]
pack-priv final int[]
pack-priv final RowWriterProcessor<Object[]>
pack-priv final Object

Constructor Summary

AccessConstructor and Description
pack-priv
Switch(RowWriterProcessor<Object[]> processor, String[] headers, int[] indexes, Object value)

pack-priv
Switch(String[] headers, int[] indexes, Class<?> type)

private
Switch(RowWriterProcessor<Object[]> processor, String[] headers, int[] indexes, Object value, Class<?> type)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headersback to summary
pack-priv final NormalizedString[] headers
indexesback to summary
pack-priv final int[] indexes
processorback to summary
pack-priv final RowWriterProcessor<Object[]> processor
valueback to summary
pack-priv final Object value

Constructor Detail

Switchback to summary
pack-priv Switch(RowWriterProcessor<Object[]> processor, String[] headers, int[] indexes, Object value)
Switchback to summary
pack-priv Switch(String[] headers, int[] indexes, Class<?> type)
Switchback to summary
private Switch(RowWriterProcessor<Object[]> processor, String[] headers, int[] indexes, Object value, Class<?> type)