com.kenshoo.pl.entity.equalityfunctions.ComparableEqualityFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity.equalityfunctions;
import org.apache.commons.lang3.ObjectUtils;
/**
* This Function overrides the default Bid Field comparison of using {@code equals()} with {@code compare()}.
* It is needed because BigDecimals' {@code equals()} takes into account the number's scale, which means
* {@code 0.0 != 0.00}
* This can cause strange behaviours, especially when comparing UI values against DB values.
* Using {@code compare()} instead solves this problem as it ignores scale when the values are the same.
*
* Created by yuvalr on 5/22/16.
*/
public class ComparableEqualityFunction> implements EntityValueEqualityFunction {
private static final ComparableEqualityFunction INSTANCE = new ComparableEqualityFunction();
private ComparableEqualityFunction() {
}
@Override
public Boolean apply(T bigDecimal, T bigDecimal2) {
return ObjectUtils.compare(bigDecimal, bigDecimal2) == 0;
}
public static > ComparableEqualityFunction getInstance() {
//noinspection unchecked
return INSTANCE;
}
}