Package org.csvobjects.csv.mapping
Record Class CSVFieldMapping
java.lang.Object
java.lang.Record
org.csvobjects.csv.mapping.CSVFieldMapping
- Record Components:
fieldName- user defined name of CSV field being mappedfieldType- fully qualified class name of the field being mappedfieldPosition- the CSV field position (starting at 0)attributeName- name of the bean's attributeformatter- the CSV field formatter to use for this field, ornullif not yet resolvedreformatterName- declarative name of the CSV field formatter to usebeanReferenceName- declarative bean name of the bean being referenced by this field mapping, or"none"beanReference- the CSV bean mapping referenced by this field mapping, ornullif none
- All Implemented Interfaces:
Comparable<CSVFieldMapping>
public record CSVFieldMapping(String fieldName, String fieldType, int fieldPosition, String attributeName, CSVFieldFormatter formatter, String reformatterName, String beanReferenceName, CSVBeanMapping beanReference)
extends Record
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.
Instances are immutable. builder() constructs a mapping from
declarative (parse-time) attributes; withFormatter(CSVFieldFormatter),
withBeanReferenceName(String) and withBeanReference(CSVBeanMapping)
return a copy with a single resolved (post-parse) attribute changed.
- Since:
- 1.8
- Author:
- Anupam Sengupta
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable builder for incrementally constructing an immutableCSVFieldMappingfrom its declarative (parse-time) attributes. -
Constructor Summary
ConstructorsConstructorDescriptionCSVFieldMapping(String fieldName, String fieldType, int fieldPosition, String attributeName, CSVFieldFormatter formatter, String reformatterName, String beanReferenceName, CSVBeanMapping beanReference) Compact constructor which normalizes the trimmable string attributes. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theattributeNamerecord component.Returns the value of thebeanReferencerecord component.Returns the value of thebeanReferenceNamerecord component.static CSVFieldMapping.Builderbuilder()Returns a new builder for incrementally constructing a field mapping from its declarative (parse-time) attributes.intcompareTo(CSVFieldMapping other) Compares this field mapping to another mapping.booleanCompares this field mapping with another for equality.Returns the value of thefieldNamerecord component.intReturns the value of thefieldPositionrecord component.Returns the value of thefieldTyperecord component.Returns the value of theformatterrecord component.inthashCode()Returns the hash code for this field mapping.Returns the value of thereformatterNamerecord component.toString()Dumps the contents of this field mapping as a string.withBeanReference(CSVBeanMapping newBeanReference) Returns a copy of this field mapping with the resolved bean reference set.withBeanReferenceName(String newBeanReferenceName) Returns a copy of this field mapping with the declarative bean reference name replaced (for example, reset to"none"when the referenced bean cannot be resolved).withFormatter(CSVFieldFormatter newFormatter) Returns a copy of this field mapping with the resolved formatter set.
-
Constructor Details
-
CSVFieldMapping
public CSVFieldMapping(String fieldName, String fieldType, int fieldPosition, String attributeName, CSVFieldFormatter formatter, String reformatterName, String beanReferenceName, CSVBeanMapping beanReference) Compact constructor which normalizes the trimmable string attributes.
-
-
Method Details
-
builder
Returns a new builder for incrementally constructing a field mapping from its declarative (parse-time) attributes.- Returns:
- a new, empty builder
-
withFormatter
Returns a copy of this field mapping with the resolved formatter set.- Parameters:
newFormatter- the resolved formatter to attach- Returns:
- a copy of this field mapping with the formatter set
-
withBeanReferenceName
Returns a copy of this field mapping with the declarative bean reference name replaced (for example, reset to"none"when the referenced bean cannot be resolved).- Parameters:
newBeanReferenceName- the bean reference name to set- Returns:
- a copy of this field mapping with the bean reference name set
-
withBeanReference
Returns a copy of this field mapping with the resolved bean reference set.- Parameters:
newBeanReference- the resolved bean mapping reference to attach- Returns:
- a copy of this field mapping with the bean reference set
-
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. -
equals
Compares this field mapping with another for equality. Field mappings are compared for the name and the field position. -
toString
Dumps the contents of this field mapping as a string. This is meant for debugging only. -
compareTo
Compares this field mapping to another mapping. The comparison is based on the field position.- Specified by:
compareToin interfaceComparable<CSVFieldMapping>- Parameters:
other- the other field mapping to compare to- Returns:
0if the two field mappings are equal,-1if this field mapping position is less than the other's, and+1if this field mapping position is higher than the others.- See Also:
-
fieldName
Returns the value of thefieldNamerecord component.- Returns:
- the value of the
fieldNamerecord component
-
fieldType
Returns the value of thefieldTyperecord component.- Returns:
- the value of the
fieldTyperecord component
-
fieldPosition
public int fieldPosition()Returns the value of thefieldPositionrecord component.- Returns:
- the value of the
fieldPositionrecord component
-
attributeName
Returns the value of theattributeNamerecord component.- Returns:
- the value of the
attributeNamerecord component
-
formatter
Returns the value of theformatterrecord component.- Returns:
- the value of the
formatterrecord component
-
reformatterName
Returns the value of thereformatterNamerecord component.- Returns:
- the value of the
reformatterNamerecord component
-
beanReferenceName
Returns the value of thebeanReferenceNamerecord component.- Returns:
- the value of the
beanReferenceNamerecord component
-
beanReference
Returns the value of thebeanReferencerecord component.- Returns:
- the value of the
beanReferencerecord component
-