Package net.tangly.gleam.model
Record Class TsvProperty<T,U>
java.lang.Object
java.lang.Record
net.tangly.gleam.model.TsvProperty<T,U>
- Type Parameters:
T
- class owning the Java propertyU
- type of the property- Record Components:
columns
- an ordered list of columns in the TSV file used to encode the property. Simple fields have one column, complex fields mapped on multiple columns have multiple valuesgetter
- getter function to retrieve the property from a Java entity instancesetter
- optional setter function to set the property of a Java entity instance. It is not needed for read-only propertiesreader
- extracts function to read and transform the set of TSV columns into a property value. Factory methods are provided to simplify the conversion in the case where only one TSV column is used.writer
- inserts function to transform a property value into a set of TSV columns and write them. Factory methods are provided to simplify the * definition of conversion in the case only one TSV column is used.
public record TsvProperty<T,U> (List<String> columns, Function<T,U> getter, BiConsumer<T,U> setter, Function<org.apache.commons.csv.CSVRecord,U> reader, BiConsumer<U,org.apache.commons.csv.CSVPrinter> writer)
extends Record
The TSV property defines the mapping between a Java property and one or multiple cells in a TSV file. Two scenarios are supported. The simple case is the mapping of a Java
property to exactly one cell in a TSV file. For example, the mapping of a local date property to the textual ISO conforms representation in one TSV cell. The more complex case
is the mapping of a Java property to multiple cells in a TSV file. For example, a Java address object has to be mapped so that each element of the address is stored in a
specific cell. Both scenarios are supported through the same abstraction.
The decision to use one or multiple cells is delegated to the developer. A TSV cell contains always either a string or a null value.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Function
<String, BigDecimal> static final Function
<String, LocalDateTime> -
Constructor Summary
ConstructorDescriptionTsvProperty
(List<String> columns, Function<T, U> getter, BiConsumer<T, U> setter, Function<org.apache.commons.csv.CSVRecord, U> reader, BiConsumer<U, org.apache.commons.csv.CSVPrinter> writer) Creates an instance of aTsvProperty
record class. -
Method Summary
Modifier and TypeMethodDescriptioncolumns()
Returns the value of thecolumns
record component.final boolean
Indicates whether some other object is "equal to" this one.void
Export the TSV value from the associated property after an optional conversion.getter()
Returns the value of thegetter
record component.final int
hashCode()
Returns a hash code value for this object.void
Import the TSV value and set the associated property after an optional conversion.static <T,
U> TsvProperty <T, U> of
(@NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter, @NotNull Function<String, U> convertFrom, @NotNull Function<U, Object> convertTo) Define a property mapped to one column with the transformations between string and property type.static <T,
U> TsvProperty <T, U> of
(@NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter, Function<String, U> convertFrom) Define a property mapped to one column with a transformation step from the string representation to the property type.static <T,
U> TsvProperty <T, U> of
(@NotNull List<String> columns, Function<T, U> getter, BiConsumer<T, U> setter, @NotNull Function<org.apache.commons.csv.CSVRecord, U> extractor, @NotNull BiConsumer<U, org.apache.commons.csv.CSVPrinter> writer) static <T,
U> TsvProperty <T, U> of
(@NotNull TsvEntity<U> entity, Function<T, U> getter, BiConsumer<T, U> setter) static <T> TsvProperty
<T, BigDecimal> ofBigDecimal
(@NotNull String column, Function<T, BigDecimal> getter, BiConsumer<T, BigDecimal> setter) static <T> TsvProperty
<T, LocalDate> static <T> TsvProperty
<T, Object> static <T,
U extends Enum<U>>
TsvProperty<T, U> ofEnum
(@NotNull Class<U> clazz, @NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter) static <T> TsvProperty
<T, Integer> static <T> TsvProperty
<T, Long> static <T> TsvProperty
<T, String> static void
Wrapper function to transformed checked exception to standard unchecked exception for usage in lambda expressionsreader()
Returns the value of thereader
record component.BiConsumer
<T, U> setter()
Returns the value of thesetter
record component.final String
toString()
Returns a string representation of this record class.static <T extends Enum<T>>
TReturn the enumeration value of the name if not null otherwise null.BiConsumer
<U, org.apache.commons.csv.CSVPrinter> writer()
Returns the value of thewriter
record component.
-
Field Details
-
CONVERT_BIG_DECIMAL_FROM
-
CONVERT_DATE_FROM
-
CONVERT_DATETIME_FROM
-
-
Constructor Details
-
TsvProperty
-
-
Method Details
-
of
public static <T,U> TsvProperty<T,U> of(@NotNull @NotNull TsvEntity<U> entity, Function<T, U> getter, BiConsumer<T, U> setter) -
ofEmpty
-
ofString
public static <T> TsvProperty<T,String> ofString(@NotNull @NotNull String column, Function<T, String> getter, BiConsumer<T, String> setter) -
ofDate
public static <T> TsvProperty<T,LocalDate> ofDate(@NotNull @NotNull String column, Function<T, LocalDate> getter, BiConsumer<T, LocalDate> setter) -
ofInt
public static <T> TsvProperty<T,Integer> ofInt(@NotNull @NotNull String column, Function<T, Integer> getter, BiConsumer<T, Integer> setter) -
ofLong
public static <T> TsvProperty<T,Long> ofLong(@NotNull @NotNull String column, Function<T, Long> getter, BiConsumer<T, Long> setter) -
ofBigDecimal
public static <T> TsvProperty<T,BigDecimal> ofBigDecimal(@NotNull @NotNull String column, Function<T, BigDecimal> getter, BiConsumer<T, BigDecimal> setter) -
ofEnum
public static <T,U extends Enum<U>> TsvProperty<T,U> ofEnum(@NotNull @NotNull Class<U> clazz, @NotNull @NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter) -
of
public static <T,U> TsvProperty<T,U> of(@NotNull @NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter, Function<String, U> convertFrom) Define a property mapped to one column with a transformation step from the string representation to the property type.- Type Parameters:
T
- entity typeU
- property type- Parameters:
column
- column in which the property will be stored in the TSV recordgetter
- getter method to read the property from the entitysetter
- setter method to write the property into the entityconvertFrom
- transforms a string into the property type representation- Returns:
- new TSV property
-
of
public static <T,U> TsvProperty<T,U> of(@NotNull @NotNull String column, Function<T, U> getter, BiConsumer<T, U> setter, @NotNull @NotNull Function<String, U> convertFrom, @NotNull @NotNull Function<U, Object> convertTo) Define a property mapped to one column with the transformations between string and property type.- Type Parameters:
T
- entity typeU
- property type- Parameters:
column
- column in which the property will be stored in the TSV recordgetter
- getter method to read the property from the entitysetter
- setter method to write the property into the entityconvertFrom
- transforms a string into the property type representationconvertTo
- transforms a property type representation into a string- Returns:
- new TSV property
-
of
public static <T,U> TsvProperty<T,U> of(@NotNull @NotNull List<String> columns, Function<T, U> getter, BiConsumer<T, U> setter, @NotNull @NotNull Function<org.apache.commons.csv.CSVRecord, U> extractor, @NotNull @NotNull BiConsumer<U, org.apache.commons.csv.CSVPrinter> writer) -
valueOf
Return the enumeration value of the name if not null otherwise null.- Type Parameters:
T
- The enum class whose constant is to be returned- Parameters:
enumClass
- the Class object of the enum class from which to return a constant.name
- the name of the constant to return- Returns:
- the enum constant of the specified enum class with the specified name
- See Also:
-
print
Wrapper function to transformed checked exception to standard unchecked exception for usage in lambda expressions- Parameters:
out
- printer to write valuesvalue
- value to be written
-
imports
Import the TSV value and set the associated property after an optional conversion.- Parameters:
entity
- entity which property will be imported and setdata
- record containing the TSV values- See Also:
-
exports
Export the TSV value from the associated property after an optional conversion.- Parameters:
entity
- entity which property will be exported as TSV valueout
- printer to write the TSV value(s)- See Also:
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
columns
-
getter
-
setter
-
reader
-
writer
-