T
- Type of the bean being convertedpublic class FieldMapByName<T> extends AbstractFieldMap<String,String,RegexToBeanField<T>,T>
complexMapList, errorLocale, simpleMap
Constructor and Description |
---|
FieldMapByName(Locale errorLocale)
Initializes this
FieldMap . |
Modifier and Type | Method and Description |
---|---|
List<FieldMapByNameEntry<T>> |
determineMissingRequiredHeaders(String[] headersPresent)
Returns a list of required headers that were not present in the input.
|
String[] |
generateHeader(T bean)
This method generates a header that can be used for writing beans of the
type provided back to a file.
|
void |
putComplex(String key,
BeanField<T,String> value)
Adds a
BeanField to this map indexed by the data in
initializer . |
void |
setColumnOrderOnWrite(Comparator<String> writeOrder)
Sets the
Comparator to be used to sort columns when
writing beans to a CSV file. |
get, put, setErrorLocale, values
public void putComplex(String key, BeanField<T,String> value)
FieldMap
BeanField
to this map indexed by the data in
initializer
.
This is what makes this map special: It allows one to define
characteristics of a method to match multiple keys.key
- A regular expression matching header namesvalue
- The BeanField
that is to be returned on a later
matchpublic List<FieldMapByNameEntry<T>> determineMissingRequiredHeaders(String[] headersPresent)
headersPresent
- An array of all headers present from the inputpublic String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException
The ordering of the headers is determined by the
Comparator
passed in to
setColumnOrderOnWrite(Comparator)
, should that method be called,
otherwise the natural ordering is used (alphabetically ascending).
This implementation will not write headers discovered in multi-valued bean fields if the headers would not be matched by the bean field on reading. There are two reasons for this:
BeanField
for
information concerning conversions, locales, necessity (whether or not
the field is required). Without this information, conversion is
impossible, and every value written under the unmatched header is blank,
regardless of the contents of the bean.bean
- One perfect, shining example of how the bean to be written
should look. The most crucial thing is, for fields that result from
joining multiple fields on reading and thus need to be split on
writing, the MultiValuedMap
in
question must have the complete structure of the header to be
generated, even if some values are empty.CsvRequiredFieldEmptyException
- If a required header is missing
while attempting to write. Since every other header is hard-wired
through the bean fields and their associated annotations, this can only
happen with multi-valued fields.public void setColumnOrderOnWrite(Comparator<String> writeOrder)
Comparator
to be used to sort columns when
writing beans to a CSV file.writeOrder
- The Comparator
to use. May be
null
, in which case the natural ordering is used.Copyright © 2005–2023. All rights reserved.