public final class ColumnMapping extends Object implements ColumnMapper
ColumnMapper interface which allows
users to manually define mappings from attributes/methods of a given class
to columns to be parsed or written.ColumnMapper| Constructor and Description |
|---|
ColumnMapping()
Creates a new column mapping instance
|
ColumnMapping(String prefix,
ColumnMapping parent)
Creates a nested column mapping instance for handling nested attributes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attributesToColumnNames(Map<String,String> mappings)
Maps multiple attributes to multiple column names.
|
void |
attributesToColumns(Map<String,Enum<?>> mappings)
Maps multiple attributes to multiple columns.
|
void |
attributesToIndexes(Map<String,Integer> mappings)
Maps multiple attributes to multiple column positions.
|
void |
attributeToColumn(String attributeName,
Enum<?> column)
Maps an attribute to a column.
|
void |
attributeToColumnName(String attributeName,
String columnName)
Maps an attribute to a column name.
|
void |
attributeToIndex(String attributeName,
int columnIndex)
Maps an attribute to a column position.
|
ColumnMapper |
clone()
Creates a deep copy of this object with all its mappings.
|
Set<String> |
getNestedAttributeNames()
Returns the first-level names of all nested members whose attributes or methods have been mapped
|
String |
getPrefix()
Returns object the nesting path associated with the current mapping.
|
boolean |
isMapped(MethodDescriptor method,
String targetName)
Tests whether a method or attribute has been mapped to a column.
|
void |
methodsToColumnNames(Map<String,String> mappings)
Maps multiple methods to multiple column names.
|
void |
methodsToColumns(Map<String,Enum<?>> mappings)
Maps multiple methods to multiple columns.
|
void |
methodsToIndexes(Map<String,Integer> mappings)
Maps multiple methods to multiple column positions.
|
void |
methodToColumn(String setterName,
Class<?> parameterType,
Enum<?> column)
Maps a setter method to a column.
|
void |
methodToColumn(String methodName,
Enum<?> column)
Maps a method to a column.
|
void |
methodToColumnName(String setterName,
Class<?> parameterType,
String columnName)
Maps a setter method to a column name.
|
void |
methodToColumnName(String methodName,
String columnName)
Maps a method to a column name.
|
void |
methodToIndex(String setterName,
Class<?> parameterType,
int columnIndex)
Maps a setter method to a column position.
|
void |
methodToIndex(String methodName,
int columnIndex)
Maps a method to a column position.
|
void |
remove(String methodOrAttributeName)
Removes any mappings that target a given method or attribute name.
|
boolean |
updateMapping(FieldMapping fieldMapping,
String targetName,
MethodDescriptor method)
Updates the mapping of a attribute/method so a mapped class member can target
a user provided column.
|
public ColumnMapping()
public ColumnMapping(String prefix, ColumnMapping parent)
prefix - the current nesting path, denoted by a dot separated string of attribute namesparent - the mappings of the parent object in the nested structure.public void attributeToColumnName(String attributeName, String columnName)
ColumnMapperattributeToColumnName in interface ColumnMapperattributeName - the name of the attribute.
Use the dot character to access attributes of nested objects,
e.g. contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.columnName - the name of the column that:
(a) when parsing, will be read from to populate the given attribute of an object;
(b) when writing, will receive the value of the given attribute of an object;public void attributeToColumn(String attributeName, Enum<?> column)
ColumnMapperattributeToColumn in interface ColumnMapperattributeName - the name of the attribute.
Use the dot character to access attributes of nested objects,
e.g. contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.column - an enumeration representing the column that:
(a) when parsing, will be read from to populate the given attribute of an object;
(b) when writing, will receive the value of the given attribute of an object;public void attributeToIndex(String attributeName, int columnIndex)
ColumnMapperattributeToIndex in interface ColumnMapperattributeName - the name of the attribute.
Use the dot character to access attributes of nested objects,
e.g. contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.columnIndex - the position of the column that:
(a) when parsing, will be read from to populate the given attribute of an object;
(b) when writing, will receive the value of the given attribute of an object;public void attributesToColumnNames(Map<String,String> mappings)
ColumnMapperattributesToColumnNames in interface ColumnMappermappings - a map of attribute names associated with a corresponding column name, where:
contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.
public void attributesToColumns(Map<String,Enum<?>> mappings)
ColumnMapperattributesToColumns in interface ColumnMappermappings - a map of attribute names associated with a corresponding column, where:
contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.
public void attributesToIndexes(Map<String,Integer> mappings)
ColumnMapperattributesToIndexes in interface ColumnMappermappings - a map of attribute names associated with a corresponding column, where:
contact.mobile will target the attribute "mobile"
from a Contact attribute inside a Customer class.
public boolean isMapped(MethodDescriptor method, String targetName)
method - a descriptor of getter/setter methods (can be null)targetName - name of a method or attributetrue if the given method or attribute has been mapped to a columnpublic boolean updateMapping(FieldMapping fieldMapping, String targetName, MethodDescriptor method)
fieldMapping - a class member that has should be mapped to a columntargetName - name of a method or attributemethod - a descriptor of getter/setter methods (can be null)true if the mapping has been successfully updated.public String getPrefix()
public void methodToColumnName(String methodName, String columnName)
ColumnMapperColumnMapper.methodToColumnName(String, Class, String)
to specify the exact parameter type to match the appropriate setter method.
When writing, only "getter" methods will be used i.e. the given method
doesn't accept any parameters and returns a value.methodToColumnName in interface ColumnMappermethodName - the name of the method.
Use the dot character to access methods of nested objects,
e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
from a Contact attribute inside a Customer class.columnName - the name of the column that:
(a) when parsing, will be read from to invoke given setter method of an object;
(b) when writing, will receive the value returned by the given getter method of an object;public void methodToColumn(String methodName, Enum<?> column)
ColumnMapperColumnMapper.methodToColumnName(String, Class, String)
to specify the exact parameter type to match the appropriate setter method.
When writing, only "getter" methods will be used i.e. the given method
doesn't accept any parameters and returns a value.methodToColumn in interface ColumnMappermethodName - the name of the method.
Use the dot character to access methods of nested objects,
* e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
* from a Contact attribute inside a Customer class.column - an enumeration representing the column that:
(a) when parsing, will be read from to invoke given setter method of an object;
(b) when writing, will receive the value returned by the given getter method of an object;public void methodToIndex(String methodName, int columnIndex)
ColumnMapperColumnMapper.methodToColumnName(String, Class, String)
to specify the exact parameter type to match the appropriate setter method.
When writing, only "getter" methods will be used i.e. the given method
doesn't accept any parameters and returns a value.methodToIndex in interface ColumnMappermethodName - the name of the method.
Use the dot character to access methods of nested objects,
* e.g. contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
* from a Contact attribute inside a Customer class.columnIndex - the position of the column that:
(a) when parsing, will be read from to invoke given setter method of an object;
(b) when writing, will receive the value returned by the given getter method of an object;public void methodsToColumnNames(Map<String,String> mappings)
ColumnMappermethodsToColumnNames in interface ColumnMappermappings - a map of methods names associated with a corresponding column name, where:
contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
from a Contact attribute inside a Customer class.
public void methodsToColumns(Map<String,Enum<?>> mappings)
ColumnMappermethodsToColumns in interface ColumnMappermappings - a map of methods names associated with a corresponding column, where:
contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
from a Contact attribute inside a Customer class.
public void methodsToIndexes(Map<String,Integer> mappings)
ColumnMappermethodsToIndexes in interface ColumnMappermappings - a map of methods names associated with a corresponding column position, where:
contact.mobile will target the method "mobile(String)" when parsing, or "String mobile()" when writing,
from a Contact attribute inside a Customer class.
public void remove(String methodOrAttributeName)
ColumnMapperremove in interface ColumnMappermethodOrAttributeName - the name of the method or attribute to be removed.public void methodToColumnName(String setterName, Class<?> parameterType, String columnName)
ColumnMapperColumnMapper.methodToColumnName(String, String)
is not enough to uniquely identify the method you need (e.g. when there are
overloaded methods with different parameter types)
Used only for parsing. Will be ignored when writing.methodToColumnName in interface ColumnMappersetterName - the name of the setter method.
Use the dot character to access methods of nested objects,
e.g. contact.mobile will target the setter method "mobile(String)"
from a Contact attribute inside a Customer class.parameterType - the type of the parameter used in the given setter name.columnName - the name of the column that when parsing, will be read from to invoke given setter method of an objectpublic void methodToColumn(String setterName, Class<?> parameterType, Enum<?> column)
ColumnMapperColumnMapper.methodToColumnName(String, String)
is not enough to uniquely identify the method you need (e.g. when there are
overloaded methods with different parameter types)
Used only for parsing. Will be ignored when writing.methodToColumn in interface ColumnMappersetterName - the name of the setter method.
Use the dot character to access methods of nested objects,
e.g. contact.mobile will target the setter method "mobile(String)"
from a Contact attribute inside a Customer class.parameterType - the type of the parameter used in the given setter name.column - an enumeration representing the column that when parsing, will be read from to invoke given setter method of an objectpublic void methodToIndex(String setterName, Class<?> parameterType, int columnIndex)
ColumnMapperColumnMapper.methodToColumnName(String, String)
is not enough to uniquely identify the method you need (e.g. when there are
overloaded methods with different parameter types)
Used only for parsing. Will be ignored when writing.methodToIndex in interface ColumnMappersetterName - the name of the setter method.
Use the dot character to access methods of nested objects,
e.g. contact.mobile will target the setter method "mobile(String)"
from a Contact attribute inside a Customer class.parameterType - the type of the parameter used in the given setter name.columnIndex - the position of the column that when parsing, will be read from to invoke given setter method of an objectpublic Set<String> getNestedAttributeNames()
public ColumnMapper clone()
ColumnMapperclone in interface ColumnMapperclone in class ObjectCopyright © 2021 Univocity Software Pty Ltd. All rights reserved.