Class AbstractColumnMapping<K>
java.lang.Object
com.univocity.parsers.common.fields.AbstractColumnMapping<K>
- Type Parameters:
K
- the type of key (attribute/method names or specific method definition with parameter and return types)
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ColumnMapping.MethodMapping
,ColumnMapping.NameMapping
Basic support operations for mapping attributes/methods to columns in a
ColumnMapper
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractColumnMapping
(String prefix, AbstractColumnMapping parent) Creates a mapping with a prefix. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a deep copy of this mapping that is independent from the original.(package private) void
extractPrefixes
(Set<String> out) Returns all prefixes used by the keys in this mapping.(package private) abstract K
Locates a given key based on an attribute or method name.(package private) abstract String
getKeyPrefix
(String prefix, K key) Returns the prefix of a given key, i.e.private Object
getMappedColumn
(K key) (package private) boolean
Tests whether a given attribute or method is mapped to a column(package private) void
mapToColumn
(K key, Enum<?> column) Maps a attribute or method to a column name(package private) void
mapToColumnIndex
(K key, int columnIndex) Maps a attribute or method to a column name(package private) void
mapToColumnIndexes
(Map<K, Integer> mappings) Maps multiple attributes or methods to multiple column names(package private) void
mapToColumnName
(K key, String columnName) Maps a attribute or method to a column name(package private) void
mapToColumnNames
(Map<K, String> mappings) Maps multiple attributes or methods to multiple column names(package private) void
mapToColumns
(Map<K, Enum<?>> mappings) Maps multiple attributes or methods to multiple column names(package private) abstract K
Transforms the key so it can work with the given prefix.(package private) void
Removes any mappings containing keys that have a given attribute or method name.(package private) boolean
updateFieldMapping
(FieldMapping fieldMapping, K key) Updates the mapping of a attribute/method so a mapped class member can target a user provided column.
-
Field Details
-
prefix
-
mapping
-
-
Constructor Details
-
AbstractColumnMapping
AbstractColumnMapping(String prefix, AbstractColumnMapping parent) Creates a mapping with a prefix.- Parameters:
prefix
- a dot separated sequence of names that represents the nesting of complex attributes inside a class (e.g customer.contact.phone).parent
- the parent mapping of columns, relevant only when nested objects' attributes or methods are being mapped.
-
-
Method Details
-
mapToColumnName
Maps a attribute or method to a column name- Parameters:
key
- attribute/method name or specific method definition with parameter and return typecolumnName
- name of column associated with the given key
-
mapToColumn
Maps a attribute or method to a column name- Parameters:
key
- attribute/method name or specific method definition with parameter and return typecolumn
- enumeration representing the column associated with the given key
-
mapToColumnIndex
Maps a attribute or method to a column name- Parameters:
key
- attribute/method name or specific method definition with parameter and return typecolumnIndex
- number representing the position of the column associated with the given key
-
mapToColumnNames
Maps multiple attributes or methods to multiple column names- Parameters:
mappings
- the mappings to be added
-
mapToColumns
Maps multiple attributes or methods to multiple column names- Parameters:
mappings
- the mappings to be added
-
mapToColumnIndexes
Maps multiple attributes or methods to multiple column names- Parameters:
mappings
- the mappings to be added
-
isMapped
Tests whether a given attribute or method is mapped to a column- Parameters:
key
- the attribute or method name/descriptor- Returns:
true
if the key is mapped.
-
prefixKey
Transforms the key so it can work with the given prefix.- Parameters:
prefix
- the current object nesting level, denoted by a dot-separated string of nested attribute names.key
- the key to transform.- Returns:
- the transformed key or
null
if the key can't be used with the given prefix
-
getMappedColumn
-
updateFieldMapping
Updates the mapping of a attribute/method so a mapped class member can target a user provided column.- Parameters:
fieldMapping
- a class member that has should be mapped to a columnkey
- the attribute name or method specification that matches with the given field.- Returns:
true
if the mapping has been successfully updated.
-
extractPrefixes
Returns all prefixes used by the keys in this mapping. These represent names of nested objects that will be navigated through to access their attributes/methods.- Parameters:
out
- the set of prefixes to populate.
-
getKeyPrefix
Returns the prefix of a given key, i.e. the current nested object that is being targeted.- Parameters:
prefix
- the current prefix - a dot separated string with nested attribute nameskey
- the attribute name or method definition. If its own prefix starts with the given prefix, the next element after the dot will be returned (if any)- Returns:
- the name of the next nested object relative to the current prefix.
-
clone
Creates a deep copy of this mapping that is independent from the original. -
findKey
Locates a given key based on an attribute or method name.- Parameters:
nameWithPrefix
- name of the attribute or method, prefixed with nested object names that identify the path to the target class member.- Returns:
- the key formed with the given attribute name or method definition
-
remove
Removes any mappings containing keys that have a given attribute or method name.- Parameters:
nameWithPrefix
- name of the attribute or method, prefixed with nested object names that identify the path to the target class member.
-