Record Class CSVBeanMapping

java.lang.Object
java.lang.Record
org.csvobjects.csv.mapping.CSVBeanMapping
All Implemented Interfaces:
Iterable<CSVFieldMapping>

public record CSVBeanMapping(String beanName, String beanClass, boolean csvHeaderPresent, SortedSet<CSVFieldMapping> fieldMappings, int maxFieldPosition) extends Record implements Iterable<CSVFieldMapping>
Represents the CSV to Java Bean mapping for a single Java bean. Instances of this class store the bean name, fully qualified class name, CSV header indicator, as well as individual CSV field mappings.

The bean name (which is user defined) acts as the name of the mapping as well, and is used for looking up or accessing the specific parsers for this mapping.

Instances are immutable; the field mapping set is defensively copied and exposed read-only. builder() constructs a mapping incrementally while its field mappings are being parsed; withFieldMappings(Collection) returns a copy with the field mappings replaced once formatters and bean references have been resolved.

Since:
1.8
Author:
Anupam Sengupta
See Also:
  • Constructor Details

    • CSVBeanMapping

      public CSVBeanMapping(String beanName, String beanClass, boolean csvHeaderPresent, SortedSet<CSVFieldMapping> fieldMappings, int maxFieldPosition)
      Compact constructor which normalizes the trimmable string attributes and defensively copies the field mapping set into an unmodifiable snapshot.
  • Method Details

    • builder

      public static CSVBeanMapping.Builder builder()
      Returns a new builder for incrementally constructing a bean mapping while its field mappings are being parsed.
      Returns:
      a new, empty builder
    • withFieldMappings

      public CSVBeanMapping withFieldMappings(Collection<CSVFieldMapping> newFieldMappings)
      Returns a copy of this bean mapping with its field mappings replaced, for example once formatters and bean references have been resolved for each field. The maximum field position is recomputed from the new field set.
      Parameters:
      newFieldMappings - the resolved field mappings to set
      Returns:
      a copy of this bean mapping with the field mappings replaced
    • hashCode

      public int hashCode()
      Returns the hash code for this bean mapping. The hashcode is based on the bean name.
      Specified by:
      hashCode in class Record
      Returns:
      the hash code
    • equals

      public boolean equals(Object other)
      Compares this bean mapping to another for equality. The comparison is based on the declarative bean name.
      Specified by:
      equals in class Record
      Parameters:
      other - the other bean mapping to compare against
      Returns:
      true if equal, false otherwise
    • toString

      public String toString()
      Dumps content of the bean mapping. This is meant for debugging only.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this bean mapping
      See Also:
    • iterator

      public Iterator<CSVFieldMapping> iterator()
      Provides an iterator over the CSV field mappings present in this bean mapping.
      Specified by:
      iterator in interface Iterable<CSVFieldMapping>
      Returns:
      returns an iterator over the field mappings present in this bean mapping
      See Also:
    • beanName

      public String beanName()
      Returns the value of the beanName record component.
      Returns:
      the value of the beanName record component
    • beanClass

      public String beanClass()
      Returns the value of the beanClass record component.
      Returns:
      the value of the beanClass record component
    • csvHeaderPresent

      public boolean csvHeaderPresent()
      Returns the value of the csvHeaderPresent record component.
      Returns:
      the value of the csvHeaderPresent record component
    • fieldMappings

      public SortedSet<CSVFieldMapping> fieldMappings()
      Returns the value of the fieldMappings record component.
      Returns:
      the value of the fieldMappings record component
    • maxFieldPosition

      public int maxFieldPosition()
      Returns the value of the maxFieldPosition record component.
      Returns:
      the value of the maxFieldPosition record component