com.univocity.parsers.common.processor.core
Class AbstractMultiBeanListProcessor<C extends Context>

java.lang.Object
  extended by com.univocity.parsers.common.processor.core.AbstractMultiBeanProcessor<C>
      extended by com.univocity.parsers.common.processor.core.AbstractMultiBeanRowProcessor<C>
          extended by com.univocity.parsers.common.processor.core.AbstractMultiBeanListProcessor<C>
All Implemented Interfaces:
ConversionProcessor, Processor<C>
Direct Known Subclasses:
MultiBeanListProcessor

public class AbstractMultiBeanListProcessor<C extends Context>
extends AbstractMultiBeanRowProcessor<C>

A Processor implementation for converting rows extracted from any implementation of AbstractParser into java objects, storing them into lists. This processor stores beans in separate lists, one for each type of bean processed. All lists of all types will have the same number of entries as the number of records in the input. When an object of a particular type can't be generated from a row, null will be added to the list. This ensures all lists are the same size, and each element of each list contains the exact information parsed from each row.

The class types passed to the constructor of this class must contain the annotations provided in com.univocity.parsers.annotations.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com
See Also:
AbstractParser, Processor, AbstractBeanProcessor, AbstractMultiBeanProcessor

Constructor Summary
AbstractMultiBeanListProcessor(Class... beanTypes)
          Creates a processor for java beans of multiple types
AbstractMultiBeanListProcessor(int expectedBeanCount, Class... beanTypes)
          Creates a processor for java beans of multiple types
 
Method Summary
 Map<Class<?>,List<?>> getBeans()
          Returns a map of all beans processed from the input.
<T> List<T>
getBeans(Class<T> beanType)
          Returns the beans of a given type processed from the input.
 String[] getHeaders()
          Returns the record headers.
 void processEnded(C context)
          This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
 void processStarted(C context)
          This method will by invoked by the parser once, when it is ready to start processing the input.
protected  void rowProcessed(Map<Class<?>,Object> row, C context)
          Invoked by the processor after all beans of a valid record have been processed.
 
Methods inherited from class com.univocity.parsers.common.processor.core.AbstractMultiBeanRowProcessor
beanProcessed
 
Methods inherited from class com.univocity.parsers.common.processor.core.AbstractMultiBeanProcessor
convertAll, convertFields, convertIndexes, convertType, getBeanClasses, getProcessorOfType, rowProcessed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMultiBeanListProcessor

public AbstractMultiBeanListProcessor(int expectedBeanCount,
                                      Class... beanTypes)
Creates a processor for java beans of multiple types

Parameters:
expectedBeanCount - expected number of rows to be parsed from the input which will be converted into java beans. Used to pre-allocate the size of the output List returned by getBeans()
beanTypes - the classes with their attributes mapped to fields of records parsed by an AbstractParser or written by an AbstractWriter.

AbstractMultiBeanListProcessor

public AbstractMultiBeanListProcessor(Class... beanTypes)
Creates a processor for java beans of multiple types

Parameters:
beanTypes - the classes with their attributes mapped to fields of records parsed by an AbstractParser or written by an AbstractWriter.
Method Detail

processStarted

public final void processStarted(C context)
Description copied from interface: Processor
This method will by invoked by the parser once, when it is ready to start processing the input.

Specified by:
processStarted in interface Processor<C extends Context>
Overrides:
processStarted in class AbstractMultiBeanRowProcessor<C extends Context>
Parameters:
context - A contextual object with information and controls over the current state of the parsing process

rowProcessed

protected final void rowProcessed(Map<Class<?>,Object> row,
                                  C context)
Description copied from class: AbstractMultiBeanRowProcessor
Invoked by the processor after all beans of a valid record have been processed.

Specified by:
rowProcessed in class AbstractMultiBeanRowProcessor<C extends Context>
Parameters:
row - a map containing all object instances generated from an input row. The map is reused internally. Make a copy if you want to keep the map.
context - A contextual object with information and controls over the current state of the parsing process

processEnded

public final void processEnded(C context)
Description copied from interface: Processor
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 Context.stop().

Specified by:
processEnded in interface Processor<C extends Context>
Overrides:
processEnded in class AbstractMultiBeanRowProcessor<C extends Context>
Parameters:
context - A contextual object with information and controls over the state of the parsing process

getHeaders

public final String[] getHeaders()
Returns the record headers. This can be either the headers defined in CommonSettings.getHeaders() or the headers parsed in the file when CommonSettings.getHeaders() equals true

Returns:
the headers of all records parsed.

getBeans

public <T> List<T> getBeans(Class<T> beanType)
Returns the beans of a given type processed from the input.

Type Parameters:
T - the type of bean processed
Parameters:
beanType - the type of bean processed
Returns:
a list with all beans of the given that were processed from the input. Might contain nulls.

getBeans

public Map<Class<?>,List<?>> getBeans()
Returns a map of all beans processed from the input.

Returns:
all beans processed from the input.


Copyright © 2017 uniVocity Software Pty Ltd. All rights reserved.