public class FieldMapping
extends java.lang.Object
Parsed in a record.| Modifier and Type | Field and Description |
|---|---|
private boolean |
accessible |
private java.lang.Boolean |
applyDefault |
private java.lang.Class<?> |
beanClass |
private java.lang.Object |
defaultPrimitiveValue |
private NormalizedString |
fieldName |
private java.lang.Class |
fieldType |
private int |
index |
private java.lang.Class |
parentClass |
private boolean |
primitive |
private boolean |
primitiveNumber |
private java.lang.reflect.Method |
readMethod |
private java.lang.reflect.AnnotatedElement |
target |
private java.lang.reflect.Method |
writeMethod |
| Constructor and Description |
|---|
FieldMapping(java.lang.Class<?> beanClass,
java.lang.reflect.AnnotatedElement target,
PropertyWrapper property,
HeaderTransformer transformer,
NormalizedString[] headers)
Creates the mapping and identifies how it is mapped (by name or by index)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canWrite(java.lang.Object instance)
Queries whether this field mapping can be applied over a given object instance.
|
private void |
determineFieldMapping(HeaderTransformer transformer,
NormalizedString[] headers) |
boolean |
equals(java.lang.Object o) |
NormalizedString |
getFieldName()
Returns the column name against which this field is mapped.
|
java.lang.Class<?> |
getFieldParent()
Returns the parent class that contains the mapped field.
|
java.lang.Class<?> |
getFieldType()
Returns the type of the mapped field
|
int |
getIndex()
Returns the column index against which this field is mapped.
|
java.lang.reflect.AnnotatedElement |
getTarget()
Returns the
Field mapped to a column |
int |
hashCode() |
boolean |
isMappedToField()
Returns
true if the field is mapped to a column name, otherwise false |
boolean |
isMappedToIndex()
Returns
true if the field is mapped to a column index, otherwise false |
java.lang.Object |
read(java.lang.Object instance)
Reads the value accessible by this field mapping from a given object
|
private java.lang.Object |
read(java.lang.Object instance,
boolean ignoreErrors) |
private void |
setAccessible() |
void |
setFieldName(NormalizedString fieldName)
Defines the column name against which this field is mapped, overriding any current name derived from
annotations or from the attribute name itself.
|
void |
setFieldName(java.lang.String fieldName)
Defines the column name against which this field is mapped, overriding any current name derived from
annotations or from the attribute name itself.
|
void |
setIndex(int index)
Defines the column index against which this field is mapped, overriding any current position derived from
annotations.
|
java.lang.String |
toString() |
void |
write(java.lang.Object instance,
java.lang.Object value)
Writes a value to the field of a given object instance, whose field is accessible through this field mapping.
|
private final java.lang.Class parentClass
private final java.lang.reflect.AnnotatedElement target
private int index
private NormalizedString fieldName
private final java.lang.Class<?> beanClass
private final java.lang.reflect.Method readMethod
private final java.lang.reflect.Method writeMethod
private boolean accessible
private final boolean primitive
private final java.lang.Object defaultPrimitiveValue
private java.lang.Boolean applyDefault
private java.lang.Class fieldType
private boolean primitiveNumber
public FieldMapping(java.lang.Class<?> beanClass,
java.lang.reflect.AnnotatedElement target,
PropertyWrapper property,
HeaderTransformer transformer,
NormalizedString[] headers)
beanClass - the class that contains a the given field.target - a Field or Method annotated with Parsedproperty - the property descriptor of this field, if any. If this bean does not have getters/setters, it will be accessed directly.transformer - an optional HeaderTransformer to modify header names/positions in attributes of Nested classes.headers - list of headers parsed from the input or manually set with CommonSettings.setHeaders(String...)private void determineFieldMapping(HeaderTransformer transformer, NormalizedString[] headers)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean isMappedToIndex()
true if the field is mapped to a column index, otherwise falsetrue if the field is mapped to a column index, otherwise falsepublic boolean isMappedToField()
true if the field is mapped to a column name, otherwise falsetrue if the field is mapped to a column name, otherwise falsepublic int getIndex()
public void setIndex(int index)
index - the column index associated with this fieldpublic void setFieldName(java.lang.String fieldName)
fieldName - the column name associated with this fieldpublic void setFieldName(NormalizedString fieldName)
fieldName - the column name associated with this fieldpublic NormalizedString getFieldName()
null if there's no such association.public java.lang.reflect.AnnotatedElement getTarget()
Field mapped to a columnField mapped to a columnprivate void setAccessible()
public java.lang.Class<?> getFieldParent()
public java.lang.Class<?> getFieldType()
public boolean canWrite(java.lang.Object instance)
instance - the object whose type will be verified in order to identify if it contains the mapped fieldtrue if the given instance contains the field/accessor method and can use this field mapping to modify its internal state; otherwise falsepublic java.lang.Object read(java.lang.Object instance)
instance - the object whose field, mapped by this field mapping, will be readprivate java.lang.Object read(java.lang.Object instance,
boolean ignoreErrors)
public void write(java.lang.Object instance,
java.lang.Object value)
instance - the object whose field will be setvalue - the value to set on the given object's field.public java.lang.String toString()
toString in class java.lang.Object