Top Description Fields Constructors Methods
com.univocity.parsers.annotations.helpers

public Class FieldMapping

extends Object
Class Inheritance
Imports
com.univocity.parsers.annotations.*, com.univocity.parsers.common.*, com.univocity.parsers.common.beans.*, java.lang.reflect.*

A helper class with information about the location of an field annotated with Parsed in a record.
Author
Univocity Software Pty Ltd - [email protected]

Field Summary

Modifier and TypeField and Description
private boolean
private Boolean
private final Class<?>
private final Object
private NormalizedString
private Class<T>
private int
private final Class<T>
private final boolean
private boolean
private final Method
private final AnnotatedElement
private final Method

Constructor Summary

AccessConstructor and Description
public
FieldMapping(Class<?>
the class that contains a the given field.
beanClass
,
AnnotatedElement target, PropertyWrapper
the property descriptor of this field, if any. If this bean does not have getters/setters, it will be accessed directly.
property
,
HeaderTransformer
an optional HeaderTransformer to modify header names/positions in attributes of Nested classes.
transformer
,
NormalizedString[]
list of headers parsed from the input or manually set with CommonSettings#setHeaders(String...)
headers
)

Creates the mapping and identifies how it is mapped (by name or by index)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the given instance contains the field/accessor method and can use this field mapping to modify its internal state; otherwise false
canWrite
(Object
the object whose type will be verified in order to identify if it contains the mapped field
instance
)

Queries whether this field mapping can be applied over a given object instance.

private void
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public NormalizedString

Returns:

the column name associated with this field, or null if there's no such association.
getFieldName
()

Returns the column name against which this field is mapped.

public Class<?>

Returns:

the field's parent class
getFieldParent
()

Returns the parent class that contains the mapped field.

public Class<?>

Returns:

the field type.
getFieldType
()

Returns the type of the mapped field

public int

Returns:

the column index associated with this field, or -1 if there's no such association.
getIndex
()

Returns the column index against which this field is mapped.

public AnnotatedElement

Returns:

the Field mapped to a column
getTarget
()

Returns the Field mapped to a column

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean

Returns:

true if the field is mapped to a column name, otherwise false
isMappedToField
()

Returns true if the field is mapped to a column name, otherwise false

public boolean

Returns:

true if the field is mapped to a column index, otherwise false
isMappedToIndex
()

Returns true if the field is mapped to a column index, otherwise false

public Object

Returns:

the value contained in the given instance's field
read
(Object
the object whose field, mapped by this field mapping, will be read
instance
)

Reads the value accessible by this field mapping from a given object

private Object
read(Object instance, boolean ignoreErrors)

private void
public void
setFieldName(String
the column name associated with this field
fieldName
)

Defines the column name against which this field is mapped, overriding any current name derived from annotations or from the attribute name itself.

public void
setFieldName(NormalizedString
the column name associated with this field
fieldName
)

Defines the column name against which this field is mapped, overriding any current name derived from annotations or from the attribute name itself.

public void
setIndex(int
the column index associated with this field
index
)

Defines the column index against which this field is mapped, overriding any current position derived from annotations.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(Object
the object whose field will be set
instance
,
Object
the value to set on the given object's field.
value
)

Writes a value to the field of a given object instance, whose field is accessible through this field mapping.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

accessibleback to summary
private boolean accessible
applyDefaultback to summary
private Boolean applyDefault
beanClassback to summary
private final Class<?> beanClass
defaultPrimitiveValueback to summary
private final Object defaultPrimitiveValue
fieldNameback to summary
private NormalizedString fieldName
fieldTypeback to summary
private Class<T> fieldType
indexback to summary
private int index
parentClassback to summary
private final Class<T> parentClass
primitiveback to summary
private final boolean primitive
primitiveNumberback to summary
private boolean primitiveNumber
readMethodback to summary
private final Method readMethod
targetback to summary
private final AnnotatedElement target
writeMethodback to summary
private final Method writeMethod

Constructor Detail

FieldMappingback to summary
public FieldMapping(Class<?> beanClass, AnnotatedElement target, PropertyWrapper property, HeaderTransformer transformer, NormalizedString[] headers)

Creates the mapping and identifies how it is mapped (by name or by index)

Parameters
beanClass:Class<?>

the class that contains a the given field.

target:AnnotatedElement

a java.lang.reflect.Field or java.lang.reflect.Method annotated with Parsed

property:PropertyWrapper

the property descriptor of this field, if any. If this bean does not have getters/setters, it will be accessed directly.

transformer:HeaderTransformer

an optional HeaderTransformer to modify header names/positions in attributes of Nested classes.

headers:NormalizedString[]

list of headers parsed from the input or manually set with CommonSettings#setHeaders(String...)

Method Detail

canWriteback to summary
public boolean canWrite(Object instance)

Queries whether this field mapping can be applied over a given object instance.

Parameters
instance:Object

the object whose type will be verified in order to identify if it contains the mapped field

Returns:boolean

true if the given instance contains the field/accessor method and can use this field mapping to modify its internal state; otherwise false

determineFieldMappingback to summary
private void determineFieldMapping(HeaderTransformer transformer, NormalizedString[] headers)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getFieldNameback to summary
public NormalizedString getFieldName()

Returns the column name against which this field is mapped.

Returns:NormalizedString

the column name associated with this field, or null if there's no such association.

getFieldParentback to summary
public Class<?> getFieldParent()

Returns the parent class that contains the mapped field.

Returns:Class<?>

the field's parent class

getFieldTypeback to summary
public Class<?> getFieldType()

Returns the type of the mapped field

Returns:Class<?>

the field type.

getIndexback to summary
public int getIndex()

Returns the column index against which this field is mapped.

Returns:int

the column index associated with this field, or -1 if there's no such association.

getTargetback to summary
public AnnotatedElement getTarget()

Returns the Field mapped to a column

Returns:AnnotatedElement

the Field mapped to a column

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isMappedToFieldback to summary
public boolean isMappedToField()

Returns true if the field is mapped to a column name, otherwise false

Returns:boolean

true if the field is mapped to a column name, otherwise false

isMappedToIndexback to summary
public boolean isMappedToIndex()

Returns true if the field is mapped to a column index, otherwise false

Returns:boolean

true if the field is mapped to a column index, otherwise false

readback to summary
public Object read(Object instance)

Reads the value accessible by this field mapping from a given object

Parameters
instance:Object

the object whose field, mapped by this field mapping, will be read

Returns:Object

the value contained in the given instance's field

readback to summary
private Object read(Object instance, boolean ignoreErrors)
setAccessibleback to summary
private void setAccessible()
setFieldNameback to summary
public void setFieldName(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:String

the column name associated with this field

setFieldNameback to summary
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:NormalizedString

the column name associated with this field

setIndexback to summary
public void setIndex(int index)

Defines the column index against which this field is mapped, overriding any current position derived from annotations.

Parameters
index:int

the column index associated with this field

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
writeback to summary
public void write(Object instance, Object value)

Writes a value to the field of a given object instance, whose field is accessible through this field mapping.

Parameters
instance:Object

the object whose field will be set

value:Object

the value to set on the given object's field.