Package org.javers.core.diff.custom
Class CustomBigDecimalComparator
- java.lang.Object
-
- org.javers.core.diff.custom.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();
-
-
Constructor Summary
Constructors Constructor Description CustomBigDecimalComparator(int significantDecimalPlaces)
-
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.
-
-
-
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 interfaceCustomPropertyComparator<java.math.BigDecimal,ValueChange>
- Parameters:
left
- left (or old) valueright
- right (or current) valueaffectedId
- Id of domain object being comparedproperty
- 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 interfaceCustomPropertyComparator<java.math.BigDecimal,ValueChange>
-
-