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

public abstract Class AbstractMasterDetailProcessor<T extends Context>

extends AbstractObjectProcessor<T extends Context>
Class Inheritance
Known Direct Subclasses
com.univocity.parsers.common.processor.MasterDetailProcessor, com.univocity.parsers.common.processor.core.AbstractMasterDetailListProcessor
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.processor.*, com.univocity.parsers.conversions.*, java.util.*

A Processor implementation for associating rows extracted from any implementation of AbstractParser into MasterDetailRecord instances.

For each row processed, a call to AbstractMasterDetailProcessor#isMasterRecord(String[], Context) will be made to identify whether or not it is a master row.

The detail rows are automatically associated with the master record in an instance of MasterDetailRecord.

When the master record is fully processed (i.e. MasterDetailRecord contains a master row and all associated detail rows), it is sent to the user for processing in AbstractMasterDetailProcessor#masterDetailRecordProcessed(MasterDetailRecord, Context).

Note

this class extends AbstractObjectProcessor and value conversions provided by Conversion instances are fully supported.

Author
Univocity Software Pty Ltd - [email protected]
See Also
MasterDetailRecord, RowPlacement, AbstractParser, ObjectRowListProcessor, Processor

Field Summary

Modifier and TypeField and Description
private final AbstractObjectListProcessor<T extends Context>
private final boolean
private MasterDetailRecord

Constructor Summary

AccessConstructor and Description
public
AbstractMasterDetailProcessor(RowPlacement
indication whether the master records are placed in relation its detail records in the input.

Master record (Totals)       Master record (Totals)
 above detail records         under detail records

   Totals | 100                 Item   | 60
   Item   | 60                  Item   | 40
   Item   | 40                  Totals | 100

rowPlacement
,
AbstractObjectListProcessor<T extends Context>
the ObjectRowListProcessor that processes detail rows.
detailProcessor
)

Creates a MasterDetailProcessor

public
AbstractMasterDetailProcessor(AbstractObjectListProcessor<T extends Context>
the AbstractObjectListProcessor that processes detail rows.
detailProcessor
)

Creates a MasterDetailProcessor assuming master records are positioned above its detail records in the input.

Method Summary

Modifier and TypeMethod and Description
protected abstract boolean

Returns:

true if the row is a master record, false if it is a detail record.
isMasterRecord
(String[]
the data extracted by the parser for an individual record.
row
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Queries whether or not the given row is a master record.

protected abstract void
masterDetailRecordProcessed(MasterDetailRecord
The master detail records
record
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Invoked by the processor after a master row and all associated detail rows have been processed.

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

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.processEnded.

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.
private void
processRecord(Object[]
a record extracted from the parser that had all (if any) conversions executed and is ready to be sent to the user.
row
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Associates individual rows to a MasterDetailRecord and invokes AbstractMasterDetailProcessor#masterDetailRecordProcessed(MasterDetailRecord, T) when it is fully populated.

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

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.processStarted.

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.
row
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.rowProcessed.

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

Invoked by the parser after all values of a valid record have been processed.
public final void
rowProcessed(Object[]
the data extracted by the parser for an individual record.
row
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Implements abstract com.univocity.parsers.common.processor.core.AbstractObjectProcessor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed and any conversions have been executed.

Field Detail

detailProcessorback to summary
private final AbstractObjectListProcessor<T extends Context> detailProcessor
isMasterRowAboveDetailback to summary
private final boolean isMasterRowAboveDetail
recordback to summary
private MasterDetailRecord record

Constructor Detail

AbstractMasterDetailProcessorback to summary
public AbstractMasterDetailProcessor(RowPlacement rowPlacement, AbstractObjectListProcessor<T extends Context> detailProcessor)

Creates a MasterDetailProcessor

Parameters
rowPlacement:RowPlacement

indication whether the master records are placed in relation its detail records in the input.



Master record (Totals)       Master record (Totals)
 above detail records         under detail records

   Totals | 100                 Item   | 60
   Item   | 60                  Item   | 40
   Item   | 40                  Totals | 100

detailProcessor:AbstractObjectListProcessor<T extends Context>

the ObjectRowListProcessor that processes detail rows.

AbstractMasterDetailProcessorback to summary
public AbstractMasterDetailProcessor(AbstractObjectListProcessor<T extends Context> detailProcessor)

Creates a MasterDetailProcessor assuming master records are positioned above its detail records in the input.

Parameters
detailProcessor:AbstractObjectListProcessor<T extends Context>

the AbstractObjectListProcessor that processes detail rows.

Method Detail

isMasterRecordback to summary
protected abstract boolean isMasterRecord(String[] row, T context)

Queries whether or not the given row is a master record.

Parameters
row:String[]

the data extracted by the parser for an individual record.

context:T

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

Returns:boolean

true if the row is a master record, false if it is a detail record.

masterDetailRecordProcessedback to summary
protected abstract void masterDetailRecordProcessed(MasterDetailRecord record, T context)

Invoked by the processor after a master row and all associated detail rows have been processed.

Parameters
record:MasterDetailRecord

The master detail records

context:T

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

processEndedback to summary
public void processEnded(T context)

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.processEnded.

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
processRecordback to summary
private void processRecord(Object[] row, T context)

Associates individual rows to a MasterDetailRecord and invokes AbstractMasterDetailProcessor#masterDetailRecordProcessed(MasterDetailRecord, T) when it is fully populated.

Parameters
row:Object[]

a record extracted from the parser that had all (if any) conversions executed and is ready to be sent to the user.

context:T

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

processStartedback to summary
public void processStarted(T context)

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.processStarted.

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, T context)

Overrides com.univocity.parsers.common.processor.core.AbstractObjectProcessor.rowProcessed.

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

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

This method will then try to identify whether the given record is a master record.

If it is, any conversions applied to the fields of the master record will be executed;

Otherwise, the parsed row will be delegated to the AbstractMasterDetailProcessor#detailProcessor given in the constructor, and a detail record will be associated with the current MasterDetailRecord

Parameters
row:String[]

the data extracted by the parser for an individual record.

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(Object[] row, T context)

Implements abstract com.univocity.parsers.common.processor.core.AbstractObjectProcessor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed and any conversions have been executed.

Parameters
row:Object[]

the data extracted by the parser for an individual record.

context:T

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

Annotations
@Override