Class CustomBigDecimalComparator

  • All Implemented Interfaces:
    CustomPropertyComparator<java.math.BigDecimal,​ValueChange>

    public class CustomBigDecimalComparator
    extends java.lang.Object
    implements CustomPropertyComparator<java.math.BigDecimal,​ValueChange>
    Compares BigDecimals with custom precision. Before comparing, values are rounded (HALF_UP) to required scale.

    Usage example:
     JaversBuilder.javers()
         .registerCustomComparator(new CustomBigDecimalComparator(2), BigDecimal.class).build();
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<ValueChange> compare​(java.math.BigDecimal left, java.math.BigDecimal right, GlobalId affectedId, Property property)
      Called by JaVers to calculate property-to-property diff between two Custom Type objects.
      boolean equals​(java.math.BigDecimal a, java.math.BigDecimal b)
      Called by JaVers to calculate collection-to-collection diff, when Custom Type objects are Collection items.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CustomBigDecimalComparator

        public CustomBigDecimalComparator​(int significantDecimalPlaces)
    • Method Detail

      • compare

        public java.util.Optional<ValueChange> compare​(java.math.BigDecimal left,
                                                       java.math.BigDecimal right,
                                                       GlobalId affectedId,
                                                       Property property)
        Description copied from interface: CustomPropertyComparator
        Called by JaVers to calculate property-to-property diff between two Custom Type objects.
        Specified by:
        compare in interface CustomPropertyComparator<java.math.BigDecimal,​ValueChange>
        Parameters:
        left - left (or old) value
        right - right (or current) value
        affectedId - Id of domain object being compared
        property - property being compared
        Returns:
        should return Optional.empty() if compared objects are the same
      • equals

        public boolean equals​(java.math.BigDecimal a,
                              java.math.BigDecimal b)
        Description copied from interface: CustomPropertyComparator
        Called by JaVers to calculate collection-to-collection diff, when Custom Type objects are Collection items.

        Both equals() and compare() should return consistent results. When compare() returns Optional.empty(), equals() should return false.
        Specified by:
        equals in interface CustomPropertyComparator<java.math.BigDecimal,​ValueChange>