Package org.csvobjects.csv.mapping
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable builder for incrementally constructing an immutableCSVBeanMappingwhile its field mappings are being parsed. -
Constructor Summary
ConstructorsConstructorDescriptionCSVBeanMapping(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 Summary
Modifier and TypeMethodDescriptionReturns the value of thebeanClassrecord component.beanName()Returns the value of thebeanNamerecord component.static CSVBeanMapping.Builderbuilder()Returns a new builder for incrementally constructing a bean mapping while its field mappings are being parsed.booleanReturns the value of thecsvHeaderPresentrecord component.booleanCompares this bean mapping to another for equality.Returns the value of thefieldMappingsrecord component.inthashCode()Returns the hash code for this bean mapping.iterator()Provides an iterator over the CSV field mappings present in this bean mapping.intReturns the value of themaxFieldPositionrecord component.toString()Dumps content of the bean mapping.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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
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
Returns a new builder for incrementally constructing a bean mapping while its field mappings are being parsed.- Returns:
- a new, empty builder
-
withFieldMappings
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. -
equals
Compares this bean mapping to another for equality. The comparison is based on the declarative bean name. -
toString
Dumps content of the bean mapping. This is meant for debugging only. -
iterator
Provides an iterator over the CSV field mappings present in this bean mapping.- Specified by:
iteratorin interfaceIterable<CSVFieldMapping>- Returns:
- returns an iterator over the field mappings present in this bean mapping
- See Also:
-
beanName
Returns the value of thebeanNamerecord component.- Returns:
- the value of the
beanNamerecord component
-
beanClass
Returns the value of thebeanClassrecord component.- Returns:
- the value of the
beanClassrecord component
-
csvHeaderPresent
public boolean csvHeaderPresent()Returns the value of thecsvHeaderPresentrecord component.- Returns:
- the value of the
csvHeaderPresentrecord component
-
fieldMappings
Returns the value of thefieldMappingsrecord component.- Returns:
- the value of the
fieldMappingsrecord component
-
maxFieldPosition
public int maxFieldPosition()Returns the value of themaxFieldPositionrecord component.- Returns:
- the value of the
maxFieldPositionrecord component
-