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>
-
-
Constructor Summary
Constructors Constructor Description AbstractInputValueSwitch()Creates 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(java.lang.String columnName)Creates a switch that will analyze a column in rows parsed from the input to determine whichProcessorto use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSwitchForValue(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, java.lang.String... headersToUse)Associates aProcessorimplementation with a custom matching algorithm to be executed in the column provided in the constructor of this class.voidaddSwitchForValue(java.lang.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(java.lang.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(java.lang.String value, Processor<T> processor, java.lang.String... headersToUse)Associates aProcessorimplementation with an expected value to be matched in the column provided in the constructor of this class.java.lang.String[]getHeaders()Returns the headers in use by the current row processor implementation, which can vary among row processors.int[]getIndexes()Returns the indexes in use by the current row processor implementation, which can vary among row processors.booleanhasDefaultSwitch()Returns 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(java.util.Comparator<java.lang.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, java.lang.String... headersToUse)Defines a defaultProcessorimplementation to use when no matching value is found in the input row.protected Processor<T>switchRowProcessor(java.lang.String[] row, T context)Analyzes the input to determine whether or not the row processor implementation must be changed-
Methods inherited from class com.univocity.parsers.common.processor.core.AbstractProcessorSwitch
preventColumnReordering, processEnded, processorSwitched, processStarted, rowProcessed, rowProcessorSwitched, wrapContext
-
-
-
-
Constructor Detail
-
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
public AbstractInputValueSwitch(java.lang.String columnName)
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 Detail
-
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
public void setComparator(java.util.Comparator<java.lang.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.- Parameters:
comparator- the comparator to use for matching values in the input column with the values provided inaddSwitchForValue(String, Processor, String...)
-
setDefaultSwitch
public void setDefaultSwitch(Processor<T> processor, java.lang.String... headersToUse)
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
public void setDefaultSwitch(Processor<T> processor)
Defines a defaultProcessorimplementation to use when no matching value is found in the input row.- Parameters:
processor- the default processor implementation
-
setDefaultSwitch
public void setDefaultSwitch(Processor<T> processor, int... indexesToUse)
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
public void addSwitchForValue(java.lang.String value, Processor<T> processor)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
public void addSwitchForValue(java.lang.String value, Processor<T> processor, java.lang.String... headersToUse)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
public void addSwitchForValue(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.- 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, java.lang.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
public void addSwitchForValue(java.lang.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.- 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
public void addSwitchForValue(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.- 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
public java.lang.String[] 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
protected final Processor<T> switchRowProcessor(java.lang.String[] row, T context)
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.
-
-