Package org.javers.core.diff.custom
Interface CustomPropertyComparator<T,C extends PropertyChange>
-
- Type Parameters:
T- Custom TypeC- Concrete type of PropertyChange returned by a comparator
- All Superinterfaces:
CustomValueComparator<T>
public interface CustomPropertyComparator<T,C extends PropertyChange> extends CustomValueComparator<T>
Property-scope comparator bounded toCustomType.
Custom Types are not easy to manage, use it as a last resort,
only for corner cases like comparing custom Collection types.
Typically, Custom Types are large structures (like Multimap).
Implementation should calculate diff between two objects of given Custom Type.
Usage:JaversBuilder.javers() .registerCustomType( Multimap.class, new GuavaCustomComparator()) .build()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Optional<C>compare(T left, T right, PropertyChangeMetadata metadata, Property property)Called by JaVers to calculate property-to-property diff between two Custom Type objects.default java.lang.StringtoString(T value)This method has two roles.-
Methods inherited from interface org.javers.core.diff.custom.CustomValueComparator
equals
-
-
-
-
Method Detail
-
compare
java.util.Optional<C> compare(T left, T right, PropertyChangeMetadata metadata, Property property)
Called by JaVers to calculate property-to-property diff between two Custom Type objects. Can calculate any of concretePropertyChange.
Implementation ofcompare()should be consistent withCustomValueComparator.equals(Object, Object). Whencompare()returnsOptional.empty(),equals()should return false.- Parameters:
left- left (or old) valueright- right (or current) valuemetadata- callPropertyChangeMetadata.getAffectedCdoId()to get Id of domain object being comparedproperty- property being compared- Returns:
- should return Optional.empty() if compared objects are the same
-
toString
default java.lang.String toString(T value)
Description copied from interface:CustomValueComparatorThis 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 customCustomValueComparator.equals(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 creatingInstanceIdfor Entities. If a Value doesn't have a customtoString(), defaultReflectionUtil.reflectiveToString(Object)) is used.
See full example CustomToStringExample.groovy.- Specified by:
toStringin interfaceCustomValueComparator<T>- Parameters:
value- not null
-
-