Package org.javers.core.diff.custom
Class CustomBigDecimalComparator
java.lang.Object
org.javers.core.diff.custom.CustomBigDecimalComparator
- All Implemented Interfaces:
CustomValueComparator<BigDecimal>
Compares BigDecimals with custom precision.
Before comparing, values are rounded (HALF_UP) to required scale.
Usage example:
Usage example:
JaversBuilder.javers()
.registerValue(BigDecimal.class, new CustomBigDecimalComparator(2))
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanequals(BigDecimal a, BigDecimal b) Called by Javers to compare two Values.toString(BigDecimal value) This method has two roles.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.javers.core.diff.custom.CustomValueComparator
handlesNulls
-
Constructor Details
-
CustomBigDecimalComparator
public CustomBigDecimalComparator(int significantDecimalPlaces)
-
-
Method Details
-
equals
Description copied from interface:CustomValueComparatorCalled by Javers to compare two Values.- Specified by:
equalsin interfaceCustomValueComparator<BigDecimal>- Parameters:
a- not null ifCustomValueComparator.handlesNulls()returns falseb- not null ifCustomValueComparator.handlesNulls()returns false
-
toString
Description copied from interface:CustomValueComparatorThis 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 customtoString(), it is used instead ofObject.hashCode()when comparing Values in hashing contexts, so:- Sets with Values
- Lists with Values compared as
ListCompareAlgorithm.AS_SET - Maps with Values as keys
toString()implementation should be aligned with customCustomValueComparator.equals(Object, Object)in the same way likeObject.hashCode()should be aligned withObject.equals(Object).
Entity Id role
Each Value can serve as an Entity Id.
When a Value has customtoString()function, it is used for creatingInstanceIdfor Entities. If a Value doesn't have a customtoString(), defaultReflectionUtil.reflectiveToString(Object)) is used.
See full example CustomToStringExample.groovy.- Specified by:
toStringin interfaceCustomValueComparator<BigDecimal>- Parameters:
value- not null ifCustomValueComparator.handlesNulls()returns false
-