com.univocity.parsers.common.processor
Class OutputValueSwitch

java.lang.Object
  extended by com.univocity.parsers.common.processor.RowWriterProcessorSwitch
      extended by com.univocity.parsers.common.processor.OutputValueSwitch
All Implemented Interfaces:
RowWriterProcessor<Object>

public class OutputValueSwitch
extends RowWriterProcessorSwitch

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


Constructor Summary
OutputValueSwitch()
          Creates a switch that will analyze the first column of output rows to determine which RowWriterProcessor to use for each output row
OutputValueSwitch(int columnIndex)
          Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.
OutputValueSwitch(String headerName)
          Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.
OutputValueSwitch(String headerName, int columnIndex)
          Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.
 
Method Summary
<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.
<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.
<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.
 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.
 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.
 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.
protected  String describeSwitch()
           
 int getColumnIndex()
          Returns the column index whose values will be used to switching from a row processor to another.
protected  String[] getHeaders()
          Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.
 String[] getHeaders(Map headerMapping, Map mapInput)
          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.
 String[] getHeaders(Object input)
          Returns the sequence of headers to use for processing an input record.
protected  int[] getIndexes()
          Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.
 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.
 void setDefaultSwitch(RowWriterProcessor<Object[]> rowProcessor, int... indexesToUse)
          Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.
 void setDefaultSwitch(RowWriterProcessor<Object[]> rowProcessor, String... headersToUse)
          Defines a default RowWriterProcessor implementation to use when no matching value is found in the output row.
protected  RowWriterProcessor<?> switchRowProcessor(Object row)
          Analyzes an output row to determine whether or not the row writer processor implementation must be changed
 
Methods inherited from class com.univocity.parsers.common.processor.RowWriterProcessorSwitch
getMinimumRowLength, rowProcessorSwitched, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputValueSwitch

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


OutputValueSwitch

public OutputValueSwitch(int columnIndex)
Creates a switch that will analyze a column of output rows to determine which RowWriterProcessor to use.

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

OutputValueSwitch

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 - the column name whose value will be used to determine which RowWriterProcessor to use for each output row.

OutputValueSwitch

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 - the column name whose value will be used to determine which RowWriterProcessor to use for each output row.
columnIndex - the position of an input column to use to perform the switch when no headers are available.
Method Detail

setComparator

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 - the comparator to use for matching values in the output column with the values provided in addSwitchForValue(Object, RowWriterProcessor)

setDefaultSwitch

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 - the default row writer processor implementation
headersToUse - the (optional) sequence of headers to assign to the given row writer processor

setDefaultSwitch

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 - the default row writer processor implementation
indexesToUse - the (optional) sequence of column indexes to assign to the given row writer processor

getHeaders

protected String[] getHeaders()
Description copied from class: RowWriterProcessorSwitch
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 CommonSettings.getHeaders() will be returned.

Overrides:
getHeaders in class RowWriterProcessorSwitch
Returns:
the current sequence of headers to use.

getIndexes

protected int[] getIndexes()
Description copied from class: RowWriterProcessorSwitch
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.

Overrides:
getIndexes in class RowWriterProcessorSwitch
Returns:
the current sequence of indexes to use.

switchRowProcessor

protected RowWriterProcessor<?> switchRowProcessor(Object row)
Description copied from class: RowWriterProcessorSwitch
Analyzes an output row to determine whether or not the row writer processor implementation must be changed

Specified by:
switchRowProcessor in class RowWriterProcessorSwitch
Parameters:
row - a record with data to be written to the output
Returns:
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 RowWriterProcessorSwitch.rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor) method will be called.

addSwitchForValue

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 - the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
rowProcessor - 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 - the (optional) sequence of headers to assign to the given row writer processor

addSwitchForValue

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 - the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
rowProcessor - 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.

addSwitchForValue

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 - the value to match against the column of incoming output rows and trigger the usage of the given row writer processor implementation.
rowProcessor - 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 - the (optional) sequence of column indexes to assign to the given row writer processor

addSwitchForType

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.

Type Parameters:
T - the type of annotated java beans whose instances will be used to trigger the usage of a different format.
Parameters:
beanType - the type of annotated java beans whose instances will be used to trigger the usage of a different format.
headersToUse - the (optional) sequence of headers to assign to the given row writer processor

addSwitchForType

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.

Type Parameters:
T - the type of annotated java beans whose instances will be used to trigger the usage of a different format.
Parameters:
beanType - the type of annotated java beans whose instances will be used to trigger the usage of a different format.
indexesToUse - the (optional) sequence of column indexes to assign to the given row writer processor

addSwitchForType

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.

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

getHeaders

public String[] getHeaders(Object input)
Description copied from class: RowWriterProcessorSwitch
Returns the sequence of headers to use for processing an input record.

Specified by:
getHeaders in class RowWriterProcessorSwitch
Parameters:
input - the record data
Returns:
the sequence of headers to use when processing the given record.

getHeaders

public String[] getHeaders(Map headerMapping,
                           Map mapInput)
Description copied from class: RowWriterProcessorSwitch
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.

Specified by:
getHeaders in class RowWriterProcessorSwitch
Parameters:
headerMapping - an optional map associating keys of the rowData map with expected header names
mapInput - the record data
Returns:
the sequence of headers to use when processing the given input map.

getColumnIndex

public int getColumnIndex()
Returns the column index whose values will be used to switching from a row processor to another.

Returns:
the column index targeted by this switch.

describeSwitch

protected String describeSwitch()
Specified by:
describeSwitch in class RowWriterProcessorSwitch


Copyright © 2017 uniVocity Software Pty Ltd. All rights reserved.