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

public abstract Class AbstractProcessorSwitch<T extends Context>

extends Object
implements Processor<T extends Context>, ColumnOrderDependent
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.processor.core.ColumnOrderDependent, com.univocity.parsers.common.processor.core.Processor
Known Direct Subclasses
com.univocity.parsers.common.processor.RowProcessorSwitch, com.univocity.parsers.common.processor.core.AbstractInputValueSwitch
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.processor.*, java.util.*, java.util.Map.*

A special Processor implementation that combines and allows switching among different Processors. Each Processor will have its own Context. Concrete implementations of this class are expected to implement the switchRowProcessor(String[], Context) method and analyze the input row to determine whether or not the current Processor implementation must be changed to handle a special circumstance (determined by the concrete implementation) such as a different row format. When the processor is switched, the processorSwitched(Processor, Processor) will be called, and must be overridden, to notify the change to the user.

Field Summary

Modifier and TypeField and Description
private T
private Map<Processor<T extends Context>, T>
private Processor<T extends Context>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

the current sequence of headers to use.
getHeaders
()

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

public int[]

Returns:

the current sequence of indexes to use.
getIndexes
()

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

public boolean
preventColumnReordering()

Implements com.univocity.parsers.common.processor.core.ColumnOrderDependent.preventColumnReordering.

Returns a flag indicating whether or not columns should be reordered by the parser
public void
processEnded(T
A contextual object with information and controls over the state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.processEnded.

This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
public void
processorSwitched(Processor<T>
the processor previously in use
from
,
Processor<T>
the new processor to use to continue processing the input.
to
)

Notifies a change of Processor implementation.

public void
processStarted(T
A contextual object with information and controls over the current state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.processStarted.

This method will by invoked by the parser once, when it is ready to start processing the input.
public final void
rowProcessed(String[]
the data extracted by the parser for an individual record. Note that:
row
,
final T
A contextual object with information and controls over the current state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed.
public void
rowProcessorSwitched(RowProcessor
the row processor previously in use
from
,
RowProcessor
the new row processor to use to continue processing the input.
to
)

Notifies a change of RowProcessor implementation.

protected abstract Processor<T>

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 processorSwitched(Processor, Processor) method will be called.
switchRowProcessor
(String[]
a row parsed from the input
row
,
T
the current parsing context (not associated with the current row processor used by this class)
context
)

Analyzes the input to determine whether or not the row processor implementation must be changed

protected abstract T

Returns:

a wrapped context that returns the headers and extracted field indexes from getHeaders() and getIndexes()
wrapContext
(T
the context to wrap
context
)

Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextForProcessorback to summary
private T contextForProcessor
processorsback to summary
private Map<Processor<T extends Context>, T> processors
selectedProcessorback to summary
private Processor<T extends Context> selectedProcessor

Constructor Detail

AbstractProcessorSwitchback to summary
public AbstractProcessorSwitch()

Method Detail

getHeadersback to summary
public String[] getHeaders()

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

Returns:String[]

the current sequence of headers to use.

getIndexesback to summary
public int[] getIndexes()

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.

Returns:int[]

the current sequence of indexes to use.

preventColumnReorderingback to summary
public boolean preventColumnReordering()

Implements com.univocity.parsers.common.processor.core.ColumnOrderDependent.preventColumnReordering.

Doc from com.univocity.parsers.common.processor.core.ColumnOrderDependent.preventColumnReordering.

Returns a flag indicating whether or not columns should be reordered by the parser

Returns:boolean

a flag indicating whether or not columns should be reordered by the parser

processEndedback to summary
public void processEnded(T context)

Implements com.univocity.parsers.common.processor.core.Processor.processEnded.

Doc from com.univocity.parsers.common.processor.core.Processor.processEnded.

This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.

It will always be called by the parser: in case of errors, if the end of the input us reached, or if the user stopped the process manually using ParsingContext#stop().

Parameters
context:T

A contextual object with information and controls over the state of the parsing process

Annotations
@Override
processorSwitchedback to summary
public void processorSwitched(Processor<T> from, Processor<T> to)

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

Parameters
from:Processor<T>

the processor previously in use

to:Processor<T>

the new processor to use to continue processing the input.

processStartedback to summary
public void processStarted(T context)

Implements com.univocity.parsers.common.processor.core.Processor.processStarted.

Doc from com.univocity.parsers.common.processor.core.Processor.processStarted.

This method will by invoked by the parser once, when it is ready to start processing the input.

Parameters
context:T

A contextual object with information and controls over the current state of the parsing process

Annotations
@Override
rowProcessedback to summary
public final void rowProcessed(String[] row, final T context)

Implements com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Doc from com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed.

Parameters
row:String[]

the data extracted by the parser for an individual record. Note that:

context:T

A contextual object with information and controls over the current state of the parsing process

Annotations
@Override
rowProcessorSwitchedback to summary
public void rowProcessorSwitched(RowProcessor from, RowProcessor to)

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

Parameters
from:RowProcessor

the row processor previously in use

to:RowProcessor

the new row processor to use to continue processing the input.

switchRowProcessorback to summary
protected abstract Processor<T> switchRowProcessor(String[] row, T context)

Analyzes the input to determine whether or not the row processor implementation must be changed

Parameters
row:String[]

a row parsed from the input

context:T

the current parsing context (not associated with the current row processor used by this class)

Returns:Processor<T>

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

wrapContextback to summary
protected abstract T wrapContext(T context)

Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.

Parameters
context:T

the context to wrap

Returns:T

a wrapped context that returns the headers and extracted field indexes from getHeaders() and getIndexes()