package org.javers.core.diff.custom;

import org.javers.core.diff.changetype.ValueChange;
import org.javers.core.metamodel.object.GlobalId;
import org.javers.core.metamodel.property.Property;
import java.math.BigDecimal;
import java.util.Optional;
import static java.math.BigDecimal.ROUND_HALF_UP;

/**
 * Compares BigDecimals with custom precision.
 * Before comparing, values are rounded (HALF_UP) to required scale.
 * <br/><br/>
 *
 * Usage example:
 * <pre>
 * JaversBuilder.javers()
 *     .registerCustomComparator(new CustomBigDecimalComparator(2), BigDecimal).build();
 * </pre>
 *
 * @author bartosz walacik
 */
public class CustomBigDecimalComparator implements CustomPropertyComparator<BigDecimal, ValueChange>{
    private int significantDecimalPlaces;

    public CustomBigDecimalComparator(int significantDecimalPlaces) {
        this.significantDecimalPlaces = significantDecimalPlaces;
    }

    @Override
    public Optional<ValueChange> compare(BigDecimal left, BigDecimal right, GlobalId affectedId, Property property)
    {
        if (equals(left, right)){
            return Optional.empty();
        }

        return Optional.of(new ValueChange(affectedId, property.getName(), left, right));
    }

    @Override
    public boolean equals(BigDecimal a, BigDecimal b) {
        BigDecimal aRounded = a.setScale(significantDecimalPlaces, ROUND_HALF_UP);
        BigDecimal bRounded = b.setScale(significantDecimalPlaces, ROUND_HALF_UP);

        return aRounded.equals(bRounded);
    }
}

@@ -5,35 +5,166 @@
 age 
-org.javers.core.diff.custom
+at.aztec.dispatcher.base.session.core.diff.service;%0A%0Aimport static java.math.BigDecimal.ROUND_HALF_UP;%0A%0Aimport java.math.BigDecimal;%0Aimport java.util.Optional
 ;%0A%0Ai
@@ -214,16 +214,77 @@
 Change;%0A
+import org.javers.core.diff.custom.CustomPropertyComparator;%0A
 import o
@@ -380,114 +380,8 @@
 rty;
-%0Aimport java.math.BigDecimal;%0Aimport java.util.Optional;%0Aimport static java.math.BigDecimal.ROUND_HALF_UP;
 %0A%0A/*
@@ -646,16 +646,22 @@
 gDecimal
+.class
 ).build(
@@ -807,17 +807,19 @@
 eChange%3E
-%7B
+ %7B%0A
 %0A    pri
@@ -1126,20 +1126,16 @@
 roperty)
-%0A   
  %7B%0A     
@@ -1161,16 +1161,17 @@
  right))
+ 
 %7B%0A      
@@ -1375,24 +1375,152 @@
 ecimal b) %7B%0A
+        if (a == null) %7B%0A            return b == null;%0A        %7D%0A%0A        if (b == null) %7B%0A            return false;%0A        %7D%0A%0A
         BigD
@@ -1723,9 +1723,8 @@
 %0A    %7D%0A%7D
-%0A

Add null checks to the CustomBigDecimalComparator