public class OutputValueSwitch extends RowWriterProcessorSwitch
RowWriterProcessorSwitch
that allows switching among different implementations of
RowWriterProcessor
based on values found on rows to be written to an outputModifier and Type | Class and Description |
---|---|
private static class |
OutputValueSwitch.Switch |
Modifier and Type | Field and Description |
---|---|
private int |
columnIndex |
private java.util.Comparator |
comparator |
private OutputValueSwitch.Switch |
defaultSwitch |
private java.lang.String |
headerName |
private OutputValueSwitch.Switch |
selectedSwitch |
private OutputValueSwitch.Switch[] |
switches |
private java.lang.Class[] |
types |
Constructor and Description |
---|
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(java.lang.String headerName)
Creates a switch that will analyze a column of output rows to determine which
RowWriterProcessor to use. |
OutputValueSwitch(java.lang.String headerName,
int columnIndex)
Creates a switch that will analyze a column of output rows to determine which
RowWriterProcessor to use. |
Modifier and Type | Method and Description |
---|---|
private void |
addSwitch(OutputValueSwitch.Switch newSwitch) |
<T> void |
addSwitchForType(java.lang.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(java.lang.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(java.lang.Class<T> beanType,
java.lang.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(java.lang.Object value,
RowWriterProcessor<java.lang.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(java.lang.Object value,
RowWriterProcessor<java.lang.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(java.lang.Object value,
RowWriterProcessor<java.lang.Object[]> rowProcessor,
java.lang.String... headersToUse)
Associates a
RowWriterProcessor implementation with an expected value to be matched in the column provided in the constructor of this class. |
protected java.lang.String |
describeSwitch() |
int |
getColumnIndex()
Returns the column index whose values will be used to switching from a row processor to another.
|
protected NormalizedString[] |
getHeaders()
Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.
|
NormalizedString[] |
getHeaders(java.util.Map headerMapping,
java.util.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.
|
NormalizedString[] |
getHeaders(java.lang.Object input)
Returns the sequence of headers to use for processing an input record.
|
private NormalizedString[] |
getHeadersFromSwitch(java.lang.Object value) |
protected int[] |
getIndexes()
Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.
|
private OutputValueSwitch.Switch |
getSwitch(java.lang.Object value) |
private java.util.List<java.lang.Object> |
getSwitchValues() |
private java.lang.String |
getValidatedHeaderName(java.lang.String headerName) |
private int |
getValidatedIndex(int columnIndex) |
private <V> V |
getValue(java.util.Map<?,V> map,
int index) |
void |
setComparator(java.util.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<java.lang.Object[]> rowProcessor,
int... indexesToUse)
Defines a default
RowWriterProcessor implementation to use when no matching value is found in the output row. |
void |
setDefaultSwitch(RowWriterProcessor<java.lang.Object[]> rowProcessor,
java.lang.String... headersToUse)
Defines a default
RowWriterProcessor implementation to use when no matching value is found in the output row. |
protected RowWriterProcessor<?> |
switchRowProcessor(java.lang.Object row)
Analyzes an output row to determine whether or not the row writer processor implementation must be changed
|
getMinimumRowLength, rowProcessorSwitched, write, write
private OutputValueSwitch.Switch defaultSwitch
private OutputValueSwitch.Switch[] switches
private OutputValueSwitch.Switch selectedSwitch
private java.lang.Class[] types
private final int columnIndex
private final java.lang.String headerName
private java.util.Comparator comparator
public OutputValueSwitch()
RowWriterProcessor
to use for each output rowpublic OutputValueSwitch(int columnIndex)
RowWriterProcessor
to use.columnIndex
- the column index whose value will be used to determine which RowWriterProcessor
to use for each output row.public OutputValueSwitch(java.lang.String headerName)
RowWriterProcessor
to use.
When no column index is defined, the switch will use the first column of any input rows sent for writing.headerName
- the column name whose value will be used to determine which RowWriterProcessor
to use for each output row.public OutputValueSwitch(java.lang.String headerName, int columnIndex)
RowWriterProcessor
to use.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.private int getValidatedIndex(int columnIndex)
private java.lang.String getValidatedHeaderName(java.lang.String headerName)
public void setComparator(java.util.Comparator<?> comparator)
Comparator
to compare values in the column to analyze which is given in the constructor of this class.comparator
- the comparator to use for matching values in the output column with the values provided in addSwitchForValue(Object, RowWriterProcessor)
public void setDefaultSwitch(RowWriterProcessor<java.lang.Object[]> rowProcessor, java.lang.String... headersToUse)
RowWriterProcessor
implementation to use when no matching value is found in the output row.rowProcessor
- the default row writer processor implementationheadersToUse
- the (optional) sequence of headers to assign to the given row writer processorpublic void setDefaultSwitch(RowWriterProcessor<java.lang.Object[]> rowProcessor, int... indexesToUse)
RowWriterProcessor
implementation to use when no matching value is found in the output row.rowProcessor
- the default row writer processor implementationindexesToUse
- the (optional) sequence of column indexes to assign to the given row writer processorprotected NormalizedString[] getHeaders()
RowWriterProcessorSwitch
null
, the headers defined in CommonSettings.getHeaders()
will be returned.getHeaders
in class RowWriterProcessorSwitch
protected int[] getIndexes()
RowWriterProcessorSwitch
null
, the indexes of fields that have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
will be returned.getIndexes
in class RowWriterProcessorSwitch
private OutputValueSwitch.Switch getSwitch(java.lang.Object value)
protected RowWriterProcessor<?> switchRowProcessor(java.lang.Object row)
RowWriterProcessorSwitch
switchRowProcessor
in class RowWriterProcessorSwitch
row
- a record with data to be written to the outputRowWriterProcessorSwitch.rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor)
method
will be called.public void addSwitchForValue(java.lang.Object value, RowWriterProcessor<java.lang.Object[]> rowProcessor, java.lang.String... headersToUse)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.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 processorpublic void addSwitchForValue(java.lang.Object value, RowWriterProcessor<java.lang.Object[]> rowProcessor)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.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.public void addSwitchForValue(java.lang.Object value, RowWriterProcessor<java.lang.Object[]> rowProcessor, int... indexesToUse)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.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 processorpublic <T> void addSwitchForType(java.lang.Class<T> beanType, java.lang.String... headersToUse)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.T
- the type of annotated java beans whose instances will be used to trigger the usage of a different format.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 processorpublic <T> void addSwitchForType(java.lang.Class<T> beanType, int... indexesToUse)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.T
- the type of annotated java beans whose instances will be used to trigger the usage of a different format.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 processorpublic <T> void addSwitchForType(java.lang.Class<T> beanType)
RowWriterProcessor
implementation with an expected value to be matched in the column provided in the constructor of this class.T
- the type of annotated java beans whose instances will be used to trigger the usage of a different format.beanType
- the type of annotated java beans whose instances will be used to trigger the usage of a different format.private void addSwitch(OutputValueSwitch.Switch newSwitch)
private <V> V getValue(java.util.Map<?,V> map, int index)
private NormalizedString[] getHeadersFromSwitch(java.lang.Object value)
public NormalizedString[] getHeaders(java.lang.Object input)
RowWriterProcessorSwitch
getHeaders
in class RowWriterProcessorSwitch
input
- the record datapublic NormalizedString[] getHeaders(java.util.Map headerMapping, java.util.Map mapInput)
RowWriterProcessorSwitch
getHeaders
in class RowWriterProcessorSwitch
headerMapping
- an optional map associating keys of the rowData map with expected header namesmapInput
- the record datapublic int getColumnIndex()
private java.util.List<java.lang.Object> getSwitchValues()
protected java.lang.String describeSwitch()
describeSwitch
in class RowWriterProcessorSwitch