org.javers.core.diff.custom.CustomPropertyComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.core.diff.custom;
import org.javers.core.diff.changetype.PropertyChange;
import org.javers.core.diff.changetype.PropertyChangeMetadata;
import org.javers.core.diff.changetype.ValueChange;
import org.javers.core.metamodel.property.Property;
import org.javers.core.metamodel.type.CustomType;
import org.javers.core.metamodel.type.ValueType;
import java.util.Optional;
/**
* Property-scope comparator bounded to {@link CustomType}.
*
*
*
* 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()
*
*
* @param Custom Type
* @param Concrete type of PropertyChange returned by a comparator
* @see https://javers.org/documentation/diff-configuration/#custom-comparators
* @see CustomValueComparator
*/
public interface CustomPropertyComparator extends CustomValueComparator {
/**
* Called by JaVers to calculate property-to-property diff
* between two Custom Type objects. Can calculate any of concrete {@link PropertyChange}.
*
*
* Implementation of compare()
should be consistent with
* {@link #equals(Object, Object)}.
* When compare()
returns Optional.empty()
,
* equals()
should return false.
*
* @param left left (or old) value
* @param right right (or current) value
* @param metadata call {@link PropertyChangeMetadata#getAffectedCdoId()} to get
* Id of domain object being compared
* @param property property being compared
*
* @return should return Optional.empty() if compared objects are the same
*/
Optional compare(T left, T right, PropertyChangeMetadata metadata, Property property);
}