Class AbstractProcessorSwitch<T extends Context>
java.lang.Object
com.univocity.parsers.common.processor.core.AbstractProcessorSwitch<T>
- All Implemented Interfaces:
ColumnOrderDependent,Processor<T>
- Direct Known Subclasses:
AbstractInputValueSwitch,RowProcessorSwitch
public abstract class AbstractProcessorSwitch<T extends Context>
extends Object
implements Processor<T>, ColumnOrderDependent
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionString[]Returns the headers in use by the current row processor implementation, which can vary among row processors.int[]Returns the indexes in use by the current row processor implementation, which can vary among row processors.booleanReturns a flag indicating whether or not columns should be reordered by the parservoidprocessEnded(T context) This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.voidprocessorSwitched(Processor<T> from, Processor<T> to) Notifies a change ofProcessorimplementation.voidprocessStarted(T context) This method will by invoked by the parser once, when it is ready to start processing the input.final voidrowProcessed(String[] row, T context) Invoked by the parser after all values of a valid record have been processed.voidrowProcessorSwitched(RowProcessor from, RowProcessor to) Notifies a change ofRowProcessorimplementation.switchRowProcessor(String[] row, T context) Analyzes the input to determine whether or not the row processor implementation must be changedprotected abstract TwrapContext(T context) Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.
-
Field Details
-
processors
-
selectedProcessor
-
contextForProcessor
-
-
Constructor Details
-
AbstractProcessorSwitch
public AbstractProcessorSwitch()
-
-
Method Details
-
switchRowProcessor
Analyzes the input to determine whether or not the row processor implementation must be changed- Parameters:
row- a row parsed from the inputcontext- 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
processorSwitched(Processor, Processor)method will be called.
-
getHeaders
Returns the headers in use by the current row processor implementation, which can vary among row processors. Ifnull, the headers parsed by the input, or defined inCommonSettings.getHeaders()will be returned.- Returns:
- the current sequence of headers to use.
-
getIndexes
public int[] getIndexes()Returns the indexes in use by the current row processor implementation, which can vary among row processors. Ifnullall columns of a given record will be considered.- Returns:
- the current sequence of indexes to use.
-
processorSwitched
Notifies a change ofProcessorimplementation. Users are expected to override this method to receive the notification.- Parameters:
from- the processor previously in useto- the new processor to use to continue processing the input.
-
rowProcessorSwitched
Notifies a change ofRowProcessorimplementation. Users are expected to override this method to receive the notification.- Parameters:
from- the row processor previously in useto- the new row processor to use to continue processing the input.
-
processStarted
Description copied from interface:ProcessorThis method will by invoked by the parser once, when it is ready to start processing the input.- Specified by:
processStartedin interfaceProcessor<T extends Context>- Parameters:
context- A contextual object with information and controls over the current state of the parsing process
-
wrapContext
Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.- Parameters:
context- the context to wrap- Returns:
- a wrapped context that returns the headers and extracted field
indexes from
getHeaders()andgetIndexes()
-
rowProcessed
Description copied from interface:ProcessorInvoked by the parser after all values of a valid record have been processed.- Specified by:
rowProcessedin interfaceProcessor<T extends Context>- Parameters:
row- the data extracted by the parser for an individual record. Note that:- it will never by null.
- it will never be empty unless explicitly configured using
CommonSettings.setSkipEmptyLines(boolean) - it won't contain lines identified by the parser as comments. To disable comment processing set
Format.setComment(char)to '\0'
context- A contextual object with information and controls over the current state of the parsing process
-
processEnded
Description copied from interface:ProcessorThis 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
Context.stop().- Specified by:
processEndedin interfaceProcessor<T extends Context>- Parameters:
context- A contextual object with information and controls over the state of the parsing process
-
preventColumnReordering
public boolean preventColumnReordering()Description copied from interface:ColumnOrderDependentReturns a flag indicating whether or not columns should be reordered by the parser- Specified by:
preventColumnReorderingin interfaceColumnOrderDependent- Returns:
- a flag indicating whether or not columns should be reordered by the parser
-