Package org.javers.core.diff.custom
Class BigDecimalComparatorWithFixedEquals
- java.lang.Object
-
- org.javers.core.diff.custom.BigDecimalComparatorWithFixedEquals
-
- All Implemented Interfaces:
CustomValueComparator<java.math.BigDecimal>
public class BigDecimalComparatorWithFixedEquals extends java.lang.Object implements CustomValueComparator<java.math.BigDecimal>
Compares BigDecimals in the right way — ignoring trailing zeros.
Usage example:JaversBuilder.javers() .registerValue(BigDecimal.class, new BigDecimalComparatorWithFixedEquals()) .build();
-
-
Constructor Summary
Constructors Constructor Description BigDecimalComparatorWithFixedEquals()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.math.BigDecimal a, java.math.BigDecimal b)Called by JaVers to compare two Values.java.lang.StringtoString(java.math.BigDecimal value)This method has two roles.
-
-
-
Method Detail
-
equals
public boolean equals(java.math.BigDecimal a, java.math.BigDecimal b)Description copied from interface:CustomValueComparatorCalled by JaVers to compare two Values.- Specified by:
equalsin interfaceCustomValueComparator<java.math.BigDecimal>- Parameters:
a- not nullb- not null
-
toString
public java.lang.String toString(java.math.BigDecimal value)
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<java.math.BigDecimal>- Parameters:
value- not null
-
-