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 classAbstractInputValueSwitch.Switch<T extends Context> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Comparator<String>private static final Comparator<String>private intprivate NormalizedStringprivate Comparator<String>private AbstractInputValueSwitch.Switchprivate 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 whichProcessorto use for each parsed rowAbstractInputValueSwitch(int columnIndex) Creates a switch that will analyze a column of rows parsed from the input to determine whichProcessorto use.AbstractInputValueSwitch(String columnName) Creates a switch that will analyze a column in rows parsed from the input to determine whichProcessorto use. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSwitchForValue(CustomMatcher matcher, Processor<T> processor) Associates aProcessorimplementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.voidaddSwitchForValue(CustomMatcher matcher, Processor<T> processor, int... indexesToUse) Associates aProcessorimplementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.voidaddSwitchForValue(CustomMatcher matcher, Processor<T> processor, String... headersToUse) Associates aProcessorimplementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.voidaddSwitchForValue(String value, Processor<T> processor) Associates aProcessorimplementation with an expected value to be matched in the column provided in the constructor of this class.voidaddSwitchForValue(String value, Processor<T> processor, int... indexesToUse) Associates aProcessorimplementation with an expected value to be matched in the column provided in the constructor of this class.voidaddSwitchForValue(String value, Processor<T> processor, String... headersToUse) Associates aProcessorimplementation 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.booleanReturns a flag indicating whether this switch contains a defaultProcessorimplementation to use when no matching value is found in the input row.voidsetCaseSensitive(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.voidsetComparator(Comparator<String> comparator) Configures the switch to use a customComparatorto compare values in the column to analyze which is given in the constructor of this class.voidsetDefaultSwitch(Processor<T> processor) Defines a defaultProcessorimplementation to use when no matching value is found in the input row.voidsetDefaultSwitch(Processor<T> processor, int... indexesToUse) Defines a defaultProcessorimplementation to use when no matching value is found in the input row.voidsetDefaultSwitch(Processor<T> processor, String... headersToUse) Defines a defaultProcessorimplementation 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 whichProcessorto 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 whichProcessorto use.- Parameters:
columnIndex- the column index whose value will be used to determine whichProcessorto use for each parsed row.
-
AbstractInputValueSwitch
Creates a switch that will analyze a column in rows parsed from the input to determine whichProcessorto use.- Parameters:
columnName- name of the column whose values will be used to determine whichProcessorto 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 customComparatorto 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 defaultProcessorimplementation 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 theParsingContextof the given processor
-
setDefaultSwitch
Defines a defaultProcessorimplementation to use when no matching value is found in the input row.- Parameters:
processor- the default processor implementation
-
setDefaultSwitch
Defines a defaultProcessorimplementation 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 theParsingContextof the given processor
-
hasDefaultSwitch
public boolean hasDefaultSwitch()Returns a flag indicating whether this switch contains a defaultProcessorimplementation to use when no matching value is found in the input row.- Returns:
trueif aProcessorimplementation has been provided to process input rows that doesn't have any matching value.
-
addSwitchForValue
Associates aProcessorimplementation 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 aProcessorimplementation 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 theParsingContextof the given processor
-
addSwitchForValue
Associates aProcessorimplementation 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 aProcessorimplementation 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 theParsingContextof the given processor
-
addSwitchForValue
Associates aProcessorimplementation 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 theParsingContextof the given processor
-
addSwitchForValue
Associates aProcessorimplementation 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 theParsingContextof the given processor
-
getHeaders
Description copied from class:AbstractProcessorSwitchReturns 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:
getHeadersin classAbstractProcessorSwitch<T extends Context>- Returns:
- the current sequence of headers to use.
-
getIndexes
public int[] getIndexes()Description copied from class:AbstractProcessorSwitchReturns the indexes in use by the current row processor implementation, which can vary among row processors. Ifnullall columns of a given record will be considered.- Overrides:
getIndexesin classAbstractProcessorSwitch<T extends Context>- Returns:
- the current sequence of indexes to use.
-
switchRowProcessor
Description copied from class:AbstractProcessorSwitchAnalyzes the input to determine whether or not the row processor implementation must be changed- Specified by:
switchRowProcessorin 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.
-