forked from plusone/plusone-commons
添加比较方法。
parent
7d4ae57842
commit
e61a393b93
|
@ -2,12 +2,40 @@ package xyz.zhouxy.plusone.commons.util;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
public class BigDecimals {
|
public class BigDecimals {
|
||||||
|
|
||||||
public static boolean equals(BigDecimal a, BigDecimal b) {
|
public static final BigDecimal ZERO = new BigDecimal("0.00");
|
||||||
|
|
||||||
|
public static boolean equals(@Nullable BigDecimal a, @Nullable BigDecimal b) {
|
||||||
return (a == b) || (a != null && a.compareTo(b) == 0);
|
return (a == b) || (a != null && a.compareTo(b) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
private BigDecimals() {
|
private BigDecimals() {
|
||||||
throw new IllegalStateException("Utility class");
|
throw new IllegalStateException("Utility class");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue