Interface CustomPropertyComparator<T,​C extends PropertyChange>

    • 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 concrete PropertyChange.

        Implementation of compare() should be consistent with CustomValueComparator.equals(Object, Object). When compare() returns Optional.empty(), equals() should return false.
        Parameters:
        left - left (or old) value
        right - right (or current) value
        metadata - call PropertyChangeMetadata.getAffectedCdoId() to get Id of domain object being compared
        property - 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: CustomValueComparator
        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 custom toString(), it is used instead of Object.hashCode() when comparing Values in hashing contexts, so: Custom toString() implementation should be aligned with custom CustomValueComparator.equals(Object, Object) in the same way like Object.hashCode() should be aligned with Object.equals(Object).

        Entity Id role

        Each Value can serve as an Entity Id.
        When a Value has custom toString() function, it is used for creating InstanceId for Entities. If a Value doesn't have a custom toString() , default ReflectionUtil.reflectiveToString(Object)) is used.

        See full example CustomToStringExample.groovy.
        Specified by:
        toString in interface CustomValueComparator<T>
        Parameters:
        value - not null