2023-05-27 04:09:46 +08:00
|
|
|
package xyz.zhouxy.plusone.commons.util;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
2023-06-20 20:07:40 +08:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import com.google.common.annotations.Beta;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
2023-05-27 04:09:46 +08:00
|
|
|
public class BigDecimals {
|
|
|
|
|
2023-06-20 20:07:40 +08:00
|
|
|
public static final BigDecimal ZERO = new BigDecimal("0.00");
|
|
|
|
|
|
|
|
public static boolean equals(@Nullable BigDecimal a, @Nullable BigDecimal b) {
|
2023-05-27 04:09:46 +08:00
|
|
|
return (a == b) || (a != null && a.compareTo(b) == 0);
|
|
|
|
}
|
|
|
|
|
2023-06-20 20:07:40 +08:00
|
|
|
@Beta
|
|
|
|
public static boolean greaterThan(BigDecimal a, BigDecimal b) {
|
|
|
|
Preconditions.checkNotNull(a, "Parameter could not be null.");
|
|
|
|
Preconditions.checkNotNull(b, "Parameter could not be null.");
|
|
|
|
return (a != b) && (a.compareTo(b) > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Beta
|
|
|
|
public static boolean lessThan(BigDecimal a, BigDecimal b) {
|
|
|
|
Preconditions.checkNotNull(a, "Parameter could not be null.");
|
|
|
|
Preconditions.checkNotNull(b, "Parameter could not be null.");
|
|
|
|
return (a != b) && (a.compareTo(b) < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Beta
|
|
|
|
public static BigDecimal of(final String val) {
|
|
|
|
return (StringUtils.isBlank(val)) ? ZERO : new BigDecimal(val);
|
|
|
|
}
|
|
|
|
|
2023-05-27 04:09:46 +08:00
|
|
|
private BigDecimals() {
|
|
|
|
throw new IllegalStateException("Utility class");
|
|
|
|
}
|
|
|
|
}
|