Package org.javers.core.diff.custom
Class CustomBigDecimalComparator
- java.lang.Object
-
- org.javers.core.diff.custom.CustomBigDecimalComparator
-
- All Implemented Interfaces:
CustomValueComparator<java.math.BigDecimal>
public class CustomBigDecimalComparator extends java.lang.Object implements CustomValueComparator<java.math.BigDecimal>
Compares BigDecimals with custom precision. Before comparing, values are rounded (HALF_UP) to required scale.
Usage example:JaversBuilder.javers() .registerValue(BigDecimal.class, new CustomBigDecimalComparator(2)) .build();
-
-
Constructor Summary
Constructors Constructor Description CustomBigDecimalComparator(int significantDecimalPlaces)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.math.BigDecimal a, java.math.BigDecimal b)
Called by Javers to compare two Values.java.lang.String
toString(java.math.BigDecimal value)
This method has two roles.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.javers.core.diff.custom.CustomValueComparator
handlesNulls
-
-
-
-
Method Detail
-
equals
public boolean equals(java.math.BigDecimal a, java.math.BigDecimal b)
Description copied from interface:CustomValueComparator
Called by Javers to compare two Values.- Specified by:
equals
in interfaceCustomValueComparator<java.math.BigDecimal>
- Parameters:
a
- not null ifCustomValueComparator.handlesNulls()
returns falseb
- not null ifCustomValueComparator.handlesNulls()
returns false
-
toString
public java.lang.String toString(java.math.BigDecimal 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 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 creatingInstanceId
for Entities. If a Value doesn't have a customtoString()
, defaultReflectionUtil.reflectiveToString(Object)
) is used.
See full example CustomToStringExample.groovy.- Specified by:
toString
in interfaceCustomValueComparator<java.math.BigDecimal>
- Parameters:
value
- not null ifCustomValueComparator.handlesNulls()
returns false
-
-