Interface FieldMap<I, K extends Comparable<K>, C extends ComplexFieldMapEntry<I,K,T>, T>
- Type Parameters:
I- The initializer type used to build the many-to-one mappingK- Type of the field identifier (key)C- Type of the ComplexFieldMapEntry used. This is specified as a parameter so we can provide type safety and polymorphism through a generic interface on the one hand, and still extend specific implementations with methods needed for that type of complex mapping without having to add every such method to the generic interface.T- The type of the bean
- All Known Implementing Classes:
AbstractFieldMap, FieldMapByName, FieldMapByPosition
public interface FieldMap<I, K extends Comparable<K>, C extends ComplexFieldMapEntry<I,K,T>, T>
Defines the basic characteristics of a map between field identifiers and
their associated
BeanFields.
Such a mapping requires a method of matching multiple fields. This method
will require data to initialize itself. Such a mapping also requires a key to
index the BeanField that is to be provided for a match.- Since:
- 4.2
-
Method Summary
Modifier and TypeMethodDescriptionString[]generateHeader(T bean) This method generates a header that can be used for writing beans of the type provided back to a file.Gets theBeanFieldassociated with this key.Associates the givenBeanFieldwith the givenkey.voidputComplex(I initializer, BeanField<T, K> value) Adds aBeanFieldto this map indexed by the data ininitializer.voidsetErrorLocale(Locale errorLocale) Sets the locale to be used for error messages.values()Provides all values currently in the map.
-
Method Details
-
generateHeader
This method generates a header that can be used for writing beans of the type provided back to a file. Whether or not this generated header is used is decided by theMappingStrategyin use. The ordering of the headers should be carefully considered by the implementing class.- Parameters:
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, theMultiValuedMapin question must have the complete structure of the header to be generated, even if some values are empty.- Returns:
- An array of header names for the output file
- Throws:
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.
-
get
Gets theBeanFieldassociated with this key. If a key could possibly match both a regular, simple key (one added withput(Comparable, BeanField)), and a complex key (one added withputComplex(java.lang.Object, com.opencsv.bean.BeanField)), the simple key is always matched. If a key could match more than one complex key, the return value is undefined. -
put
-
putComplex
Adds aBeanFieldto this map indexed by the data ininitializer. This is what makes this map special: It allows one to define characteristics of a method to match multiple keys.- Parameters:
initializer- Whatever data the implementation needs to match multiple keysvalue- TheBeanFieldthat is to be returned on a later match
-
setErrorLocale
Sets the locale to be used for error messages.- Parameters:
errorLocale- The locale to be used for error messages
-
values
Collection<BeanField<T,K>> values()Provides all values currently in the map.- Returns:
- The values in the map
-