BigDecimals:修复 equalsValue 方法第二个参数为 null 报空指针的问题;补充单元测试

This commit is contained in:
2024-12-04 01:16:00 +08:00
parent 65f0bb062c
commit 10761e92ec
2 changed files with 185 additions and 77 deletions

View File

@@ -21,19 +21,27 @@ import java.math.BigDecimal;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
/**
* BigDecimals
*
* <p>
* BigDecimal 工具类
* </p>
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @since 0.1.0
*/
public class BigDecimals {
public static boolean equalsValue(@Nullable BigDecimal a, @Nullable BigDecimal b) {
return (a == b) || (a != null && a.compareTo(b) == 0);
return (a == b) || (a != null && b != null && a.compareTo(b) == 0);
}
public static boolean gt(BigDecimal a, BigDecimal b) {
Preconditions.checkNotNull(a, "Parameter could not be null.");
Preconditions.checkNotNull(b, "Parameter could not be null.");
AssertTools.checkNotNull(a, "Parameter could not be null.");
AssertTools.checkNotNull(b, "Parameter could not be null.");
return (a != b) && (a.compareTo(b) > 0);
}
@@ -42,8 +50,8 @@ public class BigDecimals {
}
public static boolean lt(BigDecimal a, BigDecimal b) {
Preconditions.checkNotNull(a, "Parameter could not be null.");
Preconditions.checkNotNull(b, "Parameter could not be null.");
AssertTools.checkNotNull(a, "Parameter could not be null.");
AssertTools.checkNotNull(b, "Parameter could not be null.");
return (a != b) && (a.compareTo(b) < 0);
}