Record Class CSVFieldMapping

java.lang.Object
java.lang.Record
org.csvobjects.csv.mapping.CSVFieldMapping
Record Components:
fieldName - user defined name of CSV field being mapped
fieldType - fully qualified class name of the field being mapped
fieldPosition - the CSV field position (starting at 0)
attributeName - name of the bean's attribute
formatter - the CSV field formatter to use for this field, or null if not yet resolved
reformatterName - declarative name of the CSV field formatter to use
beanReferenceName - declarative bean name of the bean being referenced by this field mapping, or "none"
beanReference - the CSV bean mapping referenced by this field mapping, or null if 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:
  • 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

      public static CSVFieldMapping.Builder builder()
      Returns a new builder for incrementally constructing a field mapping from its declarative (parse-time) attributes.
      Returns:
      a new, empty builder
    • withFormatter

      public CSVFieldMapping withFormatter(CSVFieldFormatter newFormatter)
      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

      public CSVFieldMapping 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).
      Parameters:
      newBeanReferenceName - the bean reference name to set
      Returns:
      a copy of this field mapping with the bean reference name set
    • withBeanReference

      public CSVFieldMapping withBeanReference(CSVBeanMapping newBeanReference)
      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.
      Specified by:
      hashCode in class Record
      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.
      Specified by:
      equals in class Record
      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.
      Specified by:
      toString in class Record
      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:
    • fieldName

      public String fieldName()
      Returns the value of the fieldName record component.
      Returns:
      the value of the fieldName record component
    • fieldType

      public String fieldType()
      Returns the value of the fieldType record component.
      Returns:
      the value of the fieldType record component
    • fieldPosition

      public int fieldPosition()
      Returns the value of the fieldPosition record component.
      Returns:
      the value of the fieldPosition record component
    • attributeName

      public String attributeName()
      Returns the value of the attributeName record component.
      Returns:
      the value of the attributeName record component
    • formatter

      public CSVFieldFormatter formatter()
      Returns the value of the formatter record component.
      Returns:
      the value of the formatter record component
    • reformatterName

      public String reformatterName()
      Returns the value of the reformatterName record component.
      Returns:
      the value of the reformatterName record component
    • beanReferenceName

      public String beanReferenceName()
      Returns the value of the beanReferenceName record component.
      Returns:
      the value of the beanReferenceName record component
    • beanReference

      public CSVBeanMapping beanReference()
      Returns the value of the beanReference record component.
      Returns:
      the value of the beanReference record component