CSVObjects Framework

net.sf.anupam.csv.mapping
Class CSVFieldMapping

java.lang.Object
  extended by 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.5
Version:
$Revision: 1.3 $
Author:
Anupam Sengupta
See Also:
CSVBeanMapping

Constructor Summary
CSVFieldMapping()
          Constructor for CSVFieldMapping.
 
Method Summary
 int compareTo(CSVFieldMapping other)
          Compares this field mapping to another mapping.
 boolean equals(Object other)
          Compares this field mapping with another for equality.
 String getAttributeName()
          Returns the mapped POJO bean's attribute name corresponding to this field.
 CSVBeanMapping getBeanReference()
          Returns the referenced bean mapping, if one is present.
 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.
 String getFieldName()
          Returns the user defined name of this field.
 int getFieldPosition()
          Returns this field's position in the CSV line.
 String getFieldType()
          Returns the fully qualified Java type name of this field.
 CSVFieldFormatter getFormatter()
          Returns the CSV formatter attached to this field.
 String getReformatterName()
          Returns the declarative name of the formatter attached to this field.
 int hashCode()
          Returns the hash code for this field mapping.
 void setAttributeName(String attributeName)
          Sets the mapped POJO's attribute name corresponding to this field.
 void setBeanReference(CSVBeanMapping beanReference)
          Sets the referenced bean mapping for this field.
 void setBeanReferenceName(String beanReferenceName)
          Sets the declarative name of a referenced bean mapping for this field.
 void setFieldName(String fieldName)
          Sets the user defined name of this field.
 void setFieldPosition(int fieldPosition)
          Sets this field's position in the CSV line.
 void setFieldType(String fieldType)
          Sets the fully qualified Java type name of this field.
 void setFormatter(CSVFieldFormatter formatter)
          Sets the formatter attached to this field.
 void setReformatterName(String reformatterName)
          Sets the declarative name of the formatter attached to this field.
 String toString()
          Dumps the contents of this field mapping as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CSVFieldMapping

public CSVFieldMapping()
Constructor for CSVFieldMapping.

Method Detail

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:
Object.hashCode()

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:
Object.equals(Object)

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:
Object.toString()

compareTo

public int compareTo(CSVFieldMapping other)
Compares this field mapping to another mapping. The comparision 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:
Comparable.compareTo(T)

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 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

SourceForge.net Logo

© Anupam Sengupta 2005