Class AbstractInputValueSwitch<T extends Context>
java.lang.Object
com.univocity.parsers.common.processor.core.AbstractProcessorSwitch<T>
com.univocity.parsers.common.processor.core.AbstractInputValueSwitch<T>
- All Implemented Interfaces:
ColumnOrderDependent
,Processor<T>
- Direct Known Subclasses:
InputValueSwitch
public abstract class AbstractInputValueSwitch<T extends Context>
extends AbstractProcessorSwitch<T>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
AbstractInputValueSwitch.Switch<T extends Context>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Comparator<String>
private static final Comparator<String>
private int
private NormalizedString
private Comparator<String>
private AbstractInputValueSwitch.Switch
private String[]
private int[]
private AbstractInputValueSwitch.Switch[]
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a switch that will analyze the first column of rows found in the input to determine whichProcessor
to use for each parsed rowAbstractInputValueSwitch
(int columnIndex) Creates a switch that will analyze a column of rows parsed from the input to determine whichProcessor
to use.AbstractInputValueSwitch
(String columnName) Creates a switch that will analyze a column in rows parsed from the input to determine whichProcessor
to use. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSwitchForValue
(CustomMatcher matcher, Processor<T> processor) Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.void
addSwitchForValue
(CustomMatcher matcher, Processor<T> processor, int... indexesToUse) Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.void
addSwitchForValue
(CustomMatcher matcher, Processor<T> processor, String... headersToUse) Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.void
addSwitchForValue
(String value, Processor<T> processor) Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.void
addSwitchForValue
(String value, Processor<T> processor, int... indexesToUse) Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.void
addSwitchForValue
(String value, Processor<T> processor, String... headersToUse) Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.String[]
Returns the headers in use by the current row processor implementation, which can vary among row processors.int[]
Returns the indexes in use by the current row processor implementation, which can vary among row processors.boolean
Returns a flag indicating whether this switch contains a defaultProcessor
implementation to use when no matching value is found in the input row.void
setCaseSensitive
(boolean caseSensitive) Configures the switch to be case sensitive when comparing values provided inaddSwitchForValue(String, Processor, String...)
with the column given in the constructor of this class.void
setComparator
(Comparator<String> comparator) Configures the switch to use a customComparator
to compare values in the column to analyze which is given in the constructor of this class.void
setDefaultSwitch
(Processor<T> processor) Defines a defaultProcessor
implementation to use when no matching value is found in the input row.void
setDefaultSwitch
(Processor<T> processor, int... indexesToUse) Defines a defaultProcessor
implementation to use when no matching value is found in the input row.void
setDefaultSwitch
(Processor<T> processor, String... headersToUse) Defines a defaultProcessor
implementation to use when no matching value is found in the input row.switchRowProcessor
(String[] row, T context) Analyzes the input to determine whether or not the row processor implementation must be changedMethods inherited from class com.univocity.parsers.common.processor.core.AbstractProcessorSwitch
preventColumnReordering, processEnded, processorSwitched, processStarted, rowProcessed, rowProcessorSwitched, wrapContext
-
Field Details
-
columnIndex
private int columnIndex -
columnName
-
switches
-
defaultSwitch
-
headers
-
indexes
private int[] indexes -
caseSensitiveComparator
-
caseInsensitiveComparator
-
comparator
-
-
Constructor Details
-
AbstractInputValueSwitch
public AbstractInputValueSwitch()Creates a switch that will analyze the first column of rows found in the input to determine whichProcessor
to use for each parsed row -
AbstractInputValueSwitch
public AbstractInputValueSwitch(int columnIndex) Creates a switch that will analyze a column of rows parsed from the input to determine whichProcessor
to use.- Parameters:
columnIndex
- the column index whose value will be used to determine whichProcessor
to use for each parsed row.
-
AbstractInputValueSwitch
Creates a switch that will analyze a column in rows parsed from the input to determine whichProcessor
to use.- Parameters:
columnName
- name of the column whose values will be used to determine whichProcessor
to use for each parsed row.
-
-
Method Details
-
setCaseSensitive
public void setCaseSensitive(boolean caseSensitive) Configures the switch to be case sensitive when comparing values provided inaddSwitchForValue(String, Processor, String...)
with the column given in the constructor of this class.- Parameters:
caseSensitive
- a flag indicating whether the switch should compare values not considering the character case.
-
setComparator
Configures the switch to use a customComparator
to compare values in the column to analyze which is given in the constructor of this class.- Parameters:
comparator
- the comparator to use for matching values in the input column with the values provided inaddSwitchForValue(String, Processor, String...)
-
setDefaultSwitch
Defines a defaultProcessor
implementation to use when no matching value is found in the input row.- Parameters:
processor
- the default processor implementationheadersToUse
- the (optional) sequence of headers to assign to theParsingContext
of the given processor
-
setDefaultSwitch
Defines a defaultProcessor
implementation to use when no matching value is found in the input row.- Parameters:
processor
- the default processor implementation
-
setDefaultSwitch
Defines a defaultProcessor
implementation to use when no matching value is found in the input row.- Parameters:
processor
- the default processor implementationindexesToUse
- the (optional) sequence of column indexes to assign to theParsingContext
of the given processor
-
hasDefaultSwitch
public boolean hasDefaultSwitch()Returns a flag indicating whether this switch contains a defaultProcessor
implementation to use when no matching value is found in the input row.- Returns:
true
if aProcessor
implementation has been provided to process input rows that doesn't have any matching value.
-
addSwitchForValue
Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.- Parameters:
value
- the value to match against the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.
-
addSwitchForValue
Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.- Parameters:
value
- the value to match against the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.headersToUse
- the (optional) sequence of headers to assign to theParsingContext
of the given processor
-
addSwitchForValue
Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.- Parameters:
matcher
- a user defined matching implementation to execute against the values in the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.
-
addSwitchForValue
public void addSwitchForValue(CustomMatcher matcher, Processor<T> processor, String... headersToUse) Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.- Parameters:
matcher
- a user defined matching implementation to execute against the values in the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.headersToUse
- the (optional) sequence of headers to assign to theParsingContext
of the given processor
-
addSwitchForValue
Associates aProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.- Parameters:
value
- the value to match against the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.indexesToUse
- the (optional) sequence of column indexes to assign to theParsingContext
of the given processor
-
addSwitchForValue
Associates aProcessor
implementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.- Parameters:
matcher
- a user defined matching implementation to execute against the values in the column of the current input row and trigger the usage of the given processor implementation.processor
- the processor implementation when the given value matches with the contents in the column provided in the constructor of this class.indexesToUse
- the (optional) sequence of column indexes to assign to theParsingContext
of the given processor
-
getHeaders
Description copied from class:AbstractProcessorSwitch
Returns the headers in use by the current row processor implementation, which can vary among row processors. Ifnull
, the headers parsed by the input, or defined inCommonSettings.getHeaders()
will be returned.- Overrides:
getHeaders
in classAbstractProcessorSwitch<T extends Context>
- Returns:
- the current sequence of headers to use.
-
getIndexes
public int[] getIndexes()Description copied from class:AbstractProcessorSwitch
Returns the indexes in use by the current row processor implementation, which can vary among row processors. Ifnull
all columns of a given record will be considered.- Overrides:
getIndexes
in classAbstractProcessorSwitch<T extends Context>
- Returns:
- the current sequence of indexes to use.
-
switchRowProcessor
Description copied from class:AbstractProcessorSwitch
Analyzes the input to determine whether or not the row processor implementation must be changed- Specified by:
switchRowProcessor
in classAbstractProcessorSwitch<T extends Context>
- Parameters:
row
- a row parsed from the inputcontext
- the current parsing context (not associated with the current row processor used by this class)- Returns:
- the row processor implementation to use. If it is not the same as the one used by the previous row,
the returned row processor will be used, and the
AbstractProcessorSwitch.processorSwitched(Processor, Processor)
method will be called.
-