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>
A concrete implementation of Processor that allows switching among different implementations of Processor based on values found on the rows parsed from the input.
  • Field Details

  • Constructor Details

    • AbstractInputValueSwitch

      public AbstractInputValueSwitch()
      Creates a switch that will analyze the first column of rows found in the input to determine which Processor 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 which Processor to use.
      Parameters:
      columnIndex - the column index whose value will be used to determine which Processor to use for each parsed row.
    • AbstractInputValueSwitch

      public AbstractInputValueSwitch(String columnName)
      Creates a switch that will analyze a column in rows parsed from the input to determine which Processor to use.
      Parameters:
      columnName - name of the column whose values will be used to determine which Processor 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 in addSwitchForValue(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(Comparator<String> 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 - the comparator to use for matching values in the input column with the values provided in addSwitchForValue(String, Processor, String...)
    • setDefaultSwitch

      public void setDefaultSwitch(Processor<T> processor, String... headersToUse)
      Defines a default Processor implementation to use when no matching value is found in the input row.
      Parameters:
      processor - the default processor implementation
      headersToUse - the (optional) sequence of headers to assign to the ParsingContext of the given processor
    • setDefaultSwitch

      public void setDefaultSwitch(Processor<T> processor)
      Defines a default Processor implementation 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 default Processor implementation to use when no matching value is found in the input row.
      Parameters:
      processor - the default processor implementation
      indexesToUse - the (optional) sequence of column indexes to assign to the ParsingContext of the given processor
    • hasDefaultSwitch

      public boolean hasDefaultSwitch()
      Returns a flag indicating whether this switch contains a default Processor implementation to use when no matching value is found in the input row.
      Returns:
      true if a Processor implementation has been provided to process input rows that doesn't have any matching value.
    • addSwitchForValue

      public void addSwitchForValue(String value, Processor<T> processor)
      Associates a Processor 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

      public void addSwitchForValue(String value, Processor<T> processor, String... headersToUse)
      Associates a Processor 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 the ParsingContext of the given processor
    • addSwitchForValue

      public void addSwitchForValue(CustomMatcher matcher, Processor<T> processor)
      Associates a Processor 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 a Processor 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 the ParsingContext of the given processor
    • addSwitchForValue

      public void addSwitchForValue(String value, Processor<T> processor, int... indexesToUse)
      Associates a Processor 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 the ParsingContext of the given processor
    • addSwitchForValue

      public void addSwitchForValue(CustomMatcher matcher, Processor<T> processor, int... indexesToUse)
      Associates a Processor 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 the ParsingContext of the given processor
    • getHeaders

      public String[] getHeaders()
      Description copied from class: AbstractProcessorSwitch
      Returns the headers in use by the current row processor implementation, which can vary among row processors. If null, the headers parsed by the input, or defined in CommonSettings.getHeaders() will be returned.
      Overrides:
      getHeaders in class AbstractProcessorSwitch<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. If null all columns of a given record will be considered.
      Overrides:
      getIndexes in class AbstractProcessorSwitch<T extends Context>
      Returns:
      the current sequence of indexes to use.
    • switchRowProcessor

      protected final Processor<T> switchRowProcessor(String[] row, T context)
      Description copied from class: AbstractProcessorSwitch
      Analyzes the input to determine whether or not the row processor implementation must be changed
      Specified by:
      switchRowProcessor in class AbstractProcessorSwitch<T extends Context>
      Parameters:
      row - a row parsed from the input
      context - 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.