Class CSVFieldMapping

java.lang.Object
net.sf.anupam.csv.mapping.CSVFieldMapping
All Implemented Interfaces:
Comparable<CSVFieldMapping>

public class CSVFieldMapping extends Object implements Comparable<CSVFieldMapping>
Represents a single CSV field to Java Bean attribute mapping. The mapping can be for basic data types, or point to other referenced CSV bean mappings for representing nested beans.
Since:
1.8
Version:
$Revision$
Author:
Anupam Sengupta
See Also:
  • Constructor Details

    • CSVFieldMapping

      public CSVFieldMapping()
      Constructor for CSVFieldMapping.
  • Method Details

    • hashCode

      public int hashCode()
      Returns the hash code for this field mapping. The hash code is based on the field name and the field position.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
      See Also:
    • equals

      public boolean equals(Object other)
      Compares this field mapping with another for equality. Field mappings are compared for the name and the field position.
      Overrides:
      equals in class Object
      Parameters:
      other - the other field mapping to compare against
      Returns:
      true if equal, false otherwise
      See Also:
    • toString

      public String toString()
      Dumps the contents of this field mapping as a string. This is meant for debugging only.
      Overrides:
      toString in class Object
      Returns:
      the string representation
      See Also:
    • compareTo

      public int compareTo(CSVFieldMapping other)
      Compares this field mapping to another mapping. The comparison is based on the field position.
      Specified by:
      compareTo in interface Comparable<CSVFieldMapping>
      Parameters:
      other - the other field mapping to compare to
      Returns:
      0 if the two field mappings are equal, -1 if this field mapping position is less than the other's, and +1 if this field mapping position is higher than the others.
      See Also:
    • getAttributeName

      public String getAttributeName()
      Returns the mapped POJO bean's attribute name corresponding to this field.
      Returns:
      Returns the mapped POJO attribute name
    • setAttributeName

      public void setAttributeName(String attributeName)
      Sets the mapped POJO's attribute name corresponding to this field. The name has to exactly match the attribute name (including the case).
      Parameters:
      attributeName - The mapped POJO' attribute name
    • getFieldName

      public String getFieldName()
      Returns the user defined name of this field.
      Returns:
      Returns the name of this field.
    • setFieldName

      public void setFieldName(String fieldName)
      Sets the user defined name of this field. This need not be the same as the CSV field name (if defined on the CSV header row).
      Parameters:
      fieldName - The name of this field
    • getFieldPosition

      public int getFieldPosition()
      Returns this field's position in the CSV line. Field positions start at 0.
      Returns:
      Returns the field's position
    • setFieldPosition

      public void setFieldPosition(int fieldPosition)
      Sets this field's position in the CSV line. Field positions start at 0.
      Parameters:
      fieldPosition - The field's position in the CSV line
    • getFieldType

      public String getFieldType()
      Returns the fully qualified Java type name of this field.
      Returns:
      Returns the Java type name of this field
    • setFieldType

      public void setFieldType(String fieldType)
      Sets the fully qualified Java type name of this field.
      Parameters:
      fieldType - The Java type name of this field
    • getFormatter

      public CSVFieldFormatter getFormatter()
      Returns the CSV formatter attached to this field.
      Returns:
      Returns the formatter
    • setFormatter

      public void setFormatter(CSVFieldFormatter formatter)
      Sets the formatter attached to this field.
      Parameters:
      formatter - The formatter to set
    • getReformatterName

      public String getReformatterName()
      Returns the declarative name of the formatter attached to this field.
      Returns:
      Returns the declarative formatter name
    • setReformatterName

      public void setReformatterName(String reformatterName)
      Sets the declarative name of the formatter attached to this field.
      Parameters:
      reformatterName - The declarative formatter name to set
    • getBeanReferenceName

      public String getBeanReferenceName()
      Returns the declarative name of the referenced bean mapping for this field, or null if no bean mapping if referenced by this field.
      Returns:
      Returns name of the referenced bean mapping
    • setBeanReferenceName

      public void setBeanReferenceName(String beanReferenceName)
      Sets the declarative name of a referenced bean mapping for this field.
      Parameters:
      beanReferenceName - The declarative name of the referenced bean
    • setBeanReference

      public void setBeanReference(CSVBeanMapping beanReference)
      Sets the referenced bean mapping for this field.
      Parameters:
      beanReference - The bean mapping reference to set
    • getBeanReference

      public CSVBeanMapping getBeanReference()
      Returns the referenced bean mapping, if one is present. Returns null if this field does not have any bean reference.
      Returns:
      Returns the bean mapping reference