com.kenshoo.pl.entity.spi.audit.DefaultAuditFieldValueFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity.spi.audit;
import com.kenshoo.pl.entity.EntityField;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
/**
* This is the default formatter for field values to be included in an AuditRecord.
* It formats values using the {@code String} {@link com.kenshoo.pl.entity.ValueConverter} defined for a given field.
* If no such converter is defined, the default string representation of the value is returned.
*
* @see EntityField#getStringValueConverter()
*/
public class DefaultAuditFieldValueFormatter implements AuditFieldValueFormatter {
public static final AuditFieldValueFormatter INSTANCE = new DefaultAuditFieldValueFormatter();
private DefaultAuditFieldValueFormatter() {
// singleton
}
@Override
public String format(final EntityField, T> field, final T value) {
requireNonNull(field, "A field is required");
requireNonNull(value, "A value is required");
return Optional.ofNullable(field.getStringValueConverter())
.map(converter -> converter.convertTo(value))
.orElse(String.valueOf(value));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy