Top Description Fields Constructors Methods
com.univocity.parsers.common.processor

public abstract Class RowWriterProcessorSwitch

extends Object
implements RowWriterProcessor<Object>
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.processor.RowWriterProcessor
Known Direct Subclasses
com.univocity.parsers.common.processor.OutputValueSwitch
Imports
com.univocity.parsers.common.*, java.util.Arrays, .Map

A special RowWriterProcessor implementation that combines and allows switching among different RowWriterProcessors. Concrete implementations of this class are expected to implement the switchRowProcessor(T) method and analyze the input row to determine whether or not the current RowWriterProcessor implementation must be changed to handle a special circumstance (determined by the concrete implementation) such as a different row format. When the row writer processor is switched, the rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor) will be called, and must be overridden, to notify the change to the user.

Field Summary

Modifier and TypeField and Description
private int
private NormalizedString[]
private String[]
private RowWriterProcessor<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract String
protected NormalizedString[]

Returns:

the current sequence of headers to use.
getHeaders
()

Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.

public abstract NormalizedString[]

Returns:

the sequence of headers to use when processing the given input map.
getHeaders
(Map<K, V>
an optional map associating keys of the rowData map with expected header names
headerMapping
,
Map<K, V>
the record data
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.

public abstract NormalizedString[]

Returns:

the sequence of headers to use when processing the given record.
getHeaders
(Object
the record data
input
)

Returns the sequence of headers to use for processing an input record.

protected int[]

Returns:

the current sequence of indexes to use.
getIndexes
()

Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.

public final int

Returns:

the minimum length a row must have in order to be sent to the output
getMinimumRowLength
()

Returns the minimum row length based on the number of headers and index sizes

public void
rowProcessorSwitched(RowWriterProcessor<?>
the row writer processor previously in use
from
,
RowWriterProcessor<?>
the new row writer processor to use to continue processing the output rows.
to
)

Notifies a change of row writer processor implementation.

protected abstract RowWriterProcessor<?>

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 rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor) method will be called.
switchRowProcessor
(Object
a record with data to be written to the output
row
)

Analyzes an output row to determine whether or not the row writer processor implementation must be changed

public Object[]
write(Object input, String[] headers, int[] indicesToWrite)

public Object[]
write(Object
The original input record that must be converted into an Object array before writing to an output.
input
,
NormalizedString[]
All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings#getHeaders()
headers
,
int[]
The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings#selectFields(String...) or CommonSettings#selectIndexes(Integer...)
indicesToWrite
)

Implements com.univocity.parsers.common.processor.RowWriterProcessor.write.

Converts the given input into an Object array that is suitable for writing.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

minimumRowLengthback to summary
private int minimumRowLength
normalizedHeadersback to summary
private NormalizedString[] normalizedHeaders
previousHeadersback to summary
private String[] previousHeaders
selectedRowWriterProcessorback to summary
private RowWriterProcessor<T> selectedRowWriterProcessor

Constructor Detail

RowWriterProcessorSwitchback to summary
public RowWriterProcessorSwitch()

Method Detail

describeSwitchback to summary
protected abstract String describeSwitch()
getHeadersback to summary
protected NormalizedString[] getHeaders()

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 CommonWriterSettings#getHeaders() will be returned.

Returns:NormalizedString[]

the current sequence of headers to use.

getHeadersback to summary
public abstract NormalizedString[] getHeaders(Map<K, V> headerMapping, Map<K, V> 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. This is useful when the input map has keys will generate unwanted header names.

Parameters
headerMapping:Map<K, V>

an optional map associating keys of the rowData map with expected header names

mapInput:Map<K, V>

the record data

Returns:NormalizedString[]

the sequence of headers to use when processing the given input map.

getHeadersback to summary
public abstract NormalizedString[] getHeaders(Object input)

Returns the sequence of headers to use for processing an input record.

Parameters
input:Object

the record data

Returns:NormalizedString[]

the sequence of headers to use when processing the given record.

getIndexesback to summary
protected int[] getIndexes()

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.

Returns:int[]

the current sequence of indexes to use.

getMinimumRowLengthback to summary
public final int getMinimumRowLength()

Returns the minimum row length based on the number of headers and index sizes

Returns:int

the minimum length a row must have in order to be sent to the output

rowProcessorSwitchedback to summary
public void rowProcessorSwitched(RowWriterProcessor<?> from, RowWriterProcessor<?> to)

Notifies a change of row writer processor implementation. Users are expected to override this method to receive the notification.

Parameters
from:RowWriterProcessor<?>

the row writer processor previously in use

to:RowWriterProcessor<?>

the new row writer processor to use to continue processing the output rows.

switchRowProcessorback to summary
protected abstract RowWriterProcessor<?> switchRowProcessor(Object row)

Analyzes an output row to determine whether or not the row writer processor implementation must be changed

Parameters
row:Object

a record with data to be written to the output

Returns:RowWriterProcessor<?>

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 rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor) method will be called.

writeback to summary
public Object[] write(Object input, String[] headers, int[] indicesToWrite)
writeback to summary
public Object[] write(Object input, NormalizedString[] headers, int[] indicesToWrite)

Implements com.univocity.parsers.common.processor.RowWriterProcessor.write.

Doc from com.univocity.parsers.common.processor.RowWriterProcessor.write.

Converts the given input into an Object array that is suitable for writing. Used by format-specific writers that extend AbstractWriter.

Parameters
input:Object

The original input record that must be converted into an Object array before writing to an output.

headers:NormalizedString[]

All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings#getHeaders()

indicesToWrite:int[]

The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings#selectFields(String...) or CommonSettings#selectIndexes(Integer...)

Returns:Object[]

an Object array that is suitable for writing. If null or an empty array is returned then the writer might either skip this value or write an empty record (if CommonSettings#getSkipEmptyLines() is false)

Annotations
@Override