Class FieldMapping
- java.lang.Object
-
- com.univocity.parsers.annotations.helpers.FieldMapping
-
public class FieldMapping extends java.lang.Object
A helper class with information about the location of an field annotated withParsed
in a record.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 fieldint
getIndex()
Returns the column index against which this field is mapped.java.lang.reflect.AnnotatedElement
getTarget()
Returns theField
mapped to a columnint
hashCode()
boolean
isMappedToField()
Returnstrue
if the field is mapped to a column name, otherwisefalse
boolean
isMappedToIndex()
Returnstrue
if the field is mapped to a column index, otherwisefalse
java.lang.Object
read(java.lang.Object instance)
Reads the value accessible by this field mapping from a given objectprivate 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.
-
-
-
Field Detail
-
parentClass
private final java.lang.Class parentClass
-
target
private final java.lang.reflect.AnnotatedElement target
-
index
private int index
-
fieldName
private NormalizedString fieldName
-
beanClass
private final java.lang.Class<?> beanClass
-
readMethod
private final java.lang.reflect.Method readMethod
-
writeMethod
private final java.lang.reflect.Method writeMethod
-
accessible
private boolean accessible
-
primitive
private final boolean primitive
-
defaultPrimitiveValue
private final java.lang.Object defaultPrimitiveValue
-
applyDefault
private java.lang.Boolean applyDefault
-
fieldType
private java.lang.Class fieldType
-
primitiveNumber
private boolean primitiveNumber
-
-
Constructor Detail
-
FieldMapping
public 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)- Parameters:
beanClass
- the class that contains a the given field.target
- aField
orMethod
annotated withParsed
property
- the property descriptor of this field, if any. If this bean does not have getters/setters, it will be accessed directly.transformer
- an optionalHeaderTransformer
to modify header names/positions in attributes ofNested
classes.headers
- list of headers parsed from the input or manually set withCommonSettings.setHeaders(String...)
-
-
Method Detail
-
determineFieldMapping
private void determineFieldMapping(HeaderTransformer transformer, NormalizedString[] headers)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isMappedToIndex
public boolean isMappedToIndex()
Returnstrue
if the field is mapped to a column index, otherwisefalse
- Returns:
true
if the field is mapped to a column index, otherwisefalse
-
isMappedToField
public boolean isMappedToField()
Returnstrue
if the field is mapped to a column name, otherwisefalse
- Returns:
true
if the field is mapped to a column name, otherwisefalse
-
getIndex
public int getIndex()
Returns the column index against which this field is mapped.- Returns:
- the column index associated with this field, or -1 if there's no such association.
-
setIndex
public void setIndex(int index)
Defines the column index against which this field is mapped, overriding any current position derived from annotations.- Parameters:
index
- the column index associated with this field
-
setFieldName
public 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.- Parameters:
fieldName
- the column name associated with this field
-
setFieldName
public 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.- Parameters:
fieldName
- the column name associated with this field
-
getFieldName
public NormalizedString getFieldName()
Returns the column name against which this field is mapped.- Returns:
- the column name associated with this field, or
null
if there's no such association.
-
getTarget
public java.lang.reflect.AnnotatedElement getTarget()
Returns theField
mapped to a column- Returns:
- the
Field
mapped to a column
-
setAccessible
private void setAccessible()
-
getFieldParent
public java.lang.Class<?> getFieldParent()
Returns the parent class that contains the mapped field.- Returns:
- the field's parent class
-
getFieldType
public java.lang.Class<?> getFieldType()
Returns the type of the mapped field- Returns:
- the field type.
-
canWrite
public boolean canWrite(java.lang.Object instance)
Queries whether this field mapping can be applied over a given object instance.- Parameters:
instance
- the object whose type will be verified in order to identify if it contains the mapped field- Returns:
true
if the given instance contains the field/accessor method and can use this field mapping to modify its internal state; otherwisefalse
-
read
public java.lang.Object read(java.lang.Object instance)
Reads the value accessible by this field mapping from a given object- Parameters:
instance
- the object whose field, mapped by this field mapping, will be read- Returns:
- the value contained in the given instance's field
-
read
private java.lang.Object read(java.lang.Object instance, boolean ignoreErrors)
-
write
public 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.- Parameters:
instance
- the object whose field will be setvalue
- the value to set on the given object's field.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-