Class AbstractBeanListProcessor<T,C extends Context>
- java.lang.Object
-
- com.univocity.parsers.common.DefaultConversionProcessor
-
- com.univocity.parsers.common.processor.core.BeanConversionProcessor<T>
-
- com.univocity.parsers.common.processor.core.AbstractBeanProcessor<T,C>
-
- com.univocity.parsers.common.processor.core.AbstractBeanListProcessor<T,C>
-
- Type Parameters:
T
- the annotated class type.
- All Implemented Interfaces:
ConversionProcessor
,Processor<C>
- Direct Known Subclasses:
BeanListProcessor
public abstract class AbstractBeanListProcessor<T,C extends Context> extends AbstractBeanProcessor<T,C>
A convenienceProcessor
implementation for storing all java objects generated form the parsed input into a list. A typical use case of this class will be:parserSettings.setRowProcessor(new BeanListProcessor(MyObject.class)); parser.parse(reader); // will invoke the {@link AbstractBeanListProcessor#beanProcessed(Object, C)} method for each generated object. List<T> beans = rowProcessor.getBeans();
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<T>
beans
private int
expectedBeanCount
private java.lang.String[]
headers
-
Fields inherited from class com.univocity.parsers.common.processor.core.BeanConversionProcessor
beanClass, constructor, initialized, methodFilter, parsedFields, strictHeaderValidationEnabled, transformer
-
Fields inherited from class com.univocity.parsers.common.DefaultConversionProcessor
conversions
-
-
Constructor Summary
Constructors Constructor Description AbstractBeanListProcessor(java.lang.Class<T> beanType)
Creates a processor that stores java beans of a given type into a listAbstractBeanListProcessor(java.lang.Class<T> beanType, int expectedBeanCount)
Creates a processor that stores java beans of a given type into a list
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beanProcessed(T bean, C context)
Stores the generated java bean produced with a parsed record into a list.java.util.List<T>
getBeans()
Returns the list of generated java beans at the end of the parsing process.java.lang.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.-
Methods inherited from class com.univocity.parsers.common.processor.core.AbstractBeanProcessor
rowProcessed
-
Methods inherited from class com.univocity.parsers.common.processor.core.BeanConversionProcessor
addConversion, cloneConversions, createBean, createNestedProcessor, describeField, getBeanClass, getColumnMapper, getNestedAttributes, initialize, initialize, initialize, isStrictHeaderValidationEnabled, mapValuesToFields, processField, processField, processNestedAttributes, reverseConversions, setColumnMapper, setStrictHeaderValidationEnabled, validateMappings
-
Methods inherited from class com.univocity.parsers.common.DefaultConversionProcessor
applyConversions, convertAll, convertFields, convertIndexes, convertType, handleConversionError, initializeConversions, reverseConversions, toDataProcessingException
-
-
-
-
Field Detail
-
beans
private java.util.List<T> beans
-
headers
private java.lang.String[] headers
-
expectedBeanCount
private final int expectedBeanCount
-
-
Constructor Detail
-
AbstractBeanListProcessor
public AbstractBeanListProcessor(java.lang.Class<T> beanType)
Creates a processor that stores java beans of a given type into a list- Parameters:
beanType
- the class with its attributes mapped to fields of records parsed by anAbstractParser
or written by anAbstractWriter
.
-
AbstractBeanListProcessor
public AbstractBeanListProcessor(java.lang.Class<T> beanType, int expectedBeanCount)
Creates a processor that stores java beans of a given type into a list- Parameters:
beanType
- the class with its attributes mapped to fields of records parsed by anAbstractParser
or written by anAbstractWriter
.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 outputList
returned bygetBeans()
-
-
Method Detail
-
beanProcessed
public void beanProcessed(T bean, C context)
Stores the generated java bean produced with a parsed record into a list.- Specified by:
beanProcessed
in classAbstractBeanProcessor<T,C extends Context>
- Parameters:
bean
- java bean generated with the information extracted by the parser for an individual recordcontext
- A contextual object with information and controls over the current state of the parsing process- See Also:
BeanProcessor
-
getBeans
public java.util.List<T> getBeans()
Returns the list of generated java beans at the end of the parsing process.- Returns:
- the list of generated java beans at the end of the parsing process.
-
processStarted
public 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 interfaceProcessor<T>
- Overrides:
processStarted
in classAbstractBeanProcessor<T,C extends Context>
- Parameters:
context
- A contextual object with information and controls over the current state of the parsing process
-
processEnded
public 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 interfaceProcessor<T>
- Overrides:
processEnded
in classAbstractBeanProcessor<T,C extends Context>
- Parameters:
context
- A contextual object with information and controls over the state of the parsing process
-
getHeaders
public java.lang.String[] getHeaders()
Returns the record headers. This can be either the headers defined inCommonSettings.getHeaders()
or the headers parsed in the file whenCommonSettings.getHeaders()
equals true- Returns:
- the headers of all records parsed.
-
-