com.univocity.parsers.annotations.helpers
Class FieldMapping

java.lang.Object
  extended by com.univocity.parsers.annotations.helpers.FieldMapping

public class FieldMapping
extends Object

A helper class with information about the location of an field annotated with Parsed in a record.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com

Constructor Summary
FieldMapping(Class<?> beanClass, AnnotatedElement target, PropertyWrapper property, HeaderTransformer transformer, String[] headers)
          Creates the mapping and identifies how it is mapped (by name or by index)
 
Method Summary
 boolean canWrite(Object instance)
          Queries whether this field mapping can be applied over a given object instance.
 boolean equals(Object o)
           
 String getFieldName()
          Returns the column name against which this field is mapped.
 Class<?> getFieldParent()
          Returns the parent class that contains the mapped field.
 Class<?> getFieldType()
          Returns the type of the mapped field
 int getIndex()
          Returns the column index against which this field is mapped.
 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
 Object read(Object instance)
          Reads the value accessible by this field mapping from a given object
 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.
 String toString()
           
 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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FieldMapping

public FieldMapping(Class<?> beanClass,
                    AnnotatedElement target,
                    PropertyWrapper property,
                    HeaderTransformer transformer,
                    String[] 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 - a Field or Method annotated with Parsed
property - 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...)
Method Detail

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isMappedToIndex

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

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

isMappedToField

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

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

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.

setFieldName

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 - the column name associated with this field

getFieldName

public String 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 AnnotatedElement getTarget()
Returns the Field mapped to a column

Returns:
the Field mapped to a column

getFieldParent

public Class<?> getFieldParent()
Returns the parent class that contains the mapped field.

Returns:
the field's parent class

getFieldType

public Class<?> getFieldType()
Returns the type of the mapped field

Returns:
the field type.

canWrite

public boolean canWrite(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; otherwise false

read

public Object read(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

write

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 - the object whose field will be set
value - the value to set on the given object's field.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.