T
- The type of bean being created or writtenpublic abstract class HeaderNameBaseMappingStrategy<T> extends AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
AbstractMappingStrategy.RecursiveType
Modifier and Type | Field and Description |
---|---|
protected FieldMapByName<T> |
fieldMap
Given a header name, this map allows one to find the corresponding
BeanField . |
protected boolean |
forceCorrectRecordLength
If set, every record will be shortened or lengthened to match the number of headers.
|
protected Comparator<String> |
writeOrder
Holds a
Comparator to sort columns on writing. |
errorLocale, headerIndex, profile, recursiveTypeTree, type
Constructor and Description |
---|
HeaderNameBaseMappingStrategy()
Nullary constructor for compatibility.
|
HeaderNameBaseMappingStrategy(boolean forceCorrectRecordLength)
Constructor to allow setting options for header name mapping.
|
Modifier and Type | Method and Description |
---|---|
void |
captureHeader(CSVReader reader)
Implementation of this method can grab the header line before parsing
begins to use to map columns to bean properties.
|
protected String |
chooseMultivaluedFieldIndexFromHeaderIndex(int index)
For
BeanField.indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object)
it is necessary to determine which index to pass in. |
protected BeanField<T,String> |
findField(int col)
Gets the field for a given column position.
|
String |
findHeader(int col)
Gets the name (or position number) of the header for the given column
number.
|
protected FieldMap<String,String,? extends ComplexFieldMapEntry<String,String,T>,T> |
getFieldMap()
Returns the
FieldMap associated with this mapping strategy. |
protected void |
initializeFieldMap()
Creates an empty binding-type-specific field map that can be filled in
later steps.
|
protected void |
loadUnadornedFieldMap(org.apache.commons.collections4.ListValuedMap<Class<?>,Field> fields)
Creates a map of fields in the bean to be processed that have no binding
annotations.
|
void |
setColumnOrderOnWrite(Comparator<String> writeOrder)
Sets the
Comparator to be used to sort columns when
writing beans to a CSV file. |
void |
verifyLineLength(int numberOfFields)
Must be called once the length of input for a line/record is known to
verify that the line was complete.
|
createBean, determineConverter, filterIgnoredFields, generateHeader, getBindingAnnotations, getColumnName, getType, ignoreFields, indexBean, instantiateCustomConverter, isForbiddenClassForRecursion, loadAnnotatedFieldMap, loadFieldMap, loadRecursiveClasses, partitionFields, populateNewBean, selectAnnotationForProfile, setErrorLocale, setFieldValue, setProfile, setType, transmuteBean
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isAnnotationDriven
protected FieldMapByName<T> fieldMap
BeanField
.protected Comparator<String> writeOrder
Comparator
to sort columns on writing.protected final boolean forceCorrectRecordLength
public HeaderNameBaseMappingStrategy()
public HeaderNameBaseMappingStrategy(boolean forceCorrectRecordLength)
forceCorrectRecordLength
- If set, every record will be shortened
or lengthened to match the number of
headerspublic void captureHeader(CSVReader reader) throws IOException, CsvRequiredFieldEmptyException
MappingStrategy
reader
- The CSVReader to use for header parsingIOException
- If parsing failsCsvRequiredFieldEmptyException
- If a field is required, but the
header or column position for the field is not present in the inputprotected String chooseMultivaluedFieldIndexFromHeaderIndex(int index)
AbstractMappingStrategy
BeanField.indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object)
it is necessary to determine which index to pass in.chooseMultivaluedFieldIndexFromHeaderIndex
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
index
- The current column position while transmuting a bean to CSV
outputBeanField.indexAndSplitMultivaluedField(java.lang.Object, java.lang.Object)
public void verifyLineLength(int numberOfFields) throws CsvRequiredFieldEmptyException
AbstractMappingStrategy
verifyLineLength
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
numberOfFields
- The number of fields present in the line of inputCsvRequiredFieldEmptyException
- If a required column is missingprotected BeanField<T,String> findField(int col) throws CsvBadConverterException
AbstractMappingStrategy
findField
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
col
- The column to find the field forCsvBadConverterException
- If a custom converter for a field cannot
be initializedprotected void loadUnadornedFieldMap(org.apache.commons.collections4.ListValuedMap<Class<?>,Field> fields)
This method is called by AbstractMappingStrategy.loadFieldMap()
when absolutely no
binding annotations that are relevant for this mapping strategy are
found in the type of bean being processed. It is then assumed that every
field is to be included, and that the name of the member variable must
exactly match the header name of the input.
Two exceptions are made to the rule that everything is written:
CsvIgnore
will be
ignored on writingSerializable
.CsvRecurse
is respected.
loadUnadornedFieldMap
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
fields
- A list of all non-synthetic fields in the bean to be
processedprotected void initializeFieldMap()
AbstractMappingStrategy
This method may be called multiple times and must erase any state information from previous calls.
initializeFieldMap
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
protected FieldMap<String,String,? extends ComplexFieldMapEntry<String,String,T>,T> getFieldMap()
AbstractMappingStrategy
FieldMap
associated with this mapping strategy.getFieldMap
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
FieldMap
used by this strategypublic String findHeader(int col)
AbstractMappingStrategy
findHeader
in class AbstractMappingStrategy<String,String,ComplexFieldMapEntry<String,String,T>,T>
col
- The column number for which the header is soughtpublic void setColumnOrderOnWrite(Comparator<String> writeOrder)
Comparator
to be used to sort columns when
writing beans to a CSV file.
Behavior of this method when used on a mapping strategy intended for
reading data from a CSV source is not defined.writeOrder
- The Comparator
to use. May be
null
, in which case the natural ordering is used.Copyright © 2005–2023. All rights reserved.