Package org.javers.core.diff.custom
Interface CustomValueComparator<T>
-
- Type Parameters:
T
- Value Type
- All Known Subinterfaces:
CustomPropertyComparator<T,C>
- All Known Implementing Classes:
BigDecimalComparatorWithFixedEquals
,CustomBigDecimalComparator
public interface CustomValueComparator<T>
A custom comparator forValueType
classes to be used instead of defaultObject.equals(Object)
.
Example implementation:CustomBigDecimalComparator
Usage:JaversBuilder.javers() .registerValue(BigDecimal.class, new CustomBigDecimalComparator(2)) .build()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
equals(T a, T b)
Called by JaVers to compare two Values.java.lang.String
toString(T value)
This method has two roles.
-
-
-
Method Detail
-
equals
boolean equals(T a, T b)
Called by JaVers to compare two Values.- Parameters:
a
- not nullb
- not null
-
toString
java.lang.String toString(T value)
This method has two roles. First, it is used when Values are compared in hashing contexts. Second, it is used to build Entity Ids from Values.
Hashcode role
When a Value class has customtoString()
, it is used instead ofObject.hashCode()
when comparing Values in hashing contexts, so:- Sets with Values
- Lists with Values compared as
ListCompareAlgorithm.AS_SET
- Maps with Values as keys
toString()
implementation should be aligned with customequals(Object, Object)
in the same way likeObject.hashCode()
should be aligned withObject.equals(Object)
.
Entity Id role
Each Value can serve as an Entity Id.
When a Value has customtoString()
function, it is used for creatingInstanceId
for Entities. If a Value doesn't have a customtoString()
, defaultReflectionUtil.reflectiveToString(Object)
) is used.
See full example CustomToStringExample.groovy.- Parameters:
value
- not null
-
-