优化功能

This commit is contained in:
2024-05-28 09:38:37 +08:00
parent 2297536307
commit 48bd4f1b31
4 changed files with 31 additions and 14 deletions

View File

@@ -6,7 +6,6 @@ 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 {
@@ -17,21 +16,26 @@ public class BigDecimals {
return (a == b) || (a != null && a.compareTo(b) == 0);
}
@Beta
public static boolean greaterThan(BigDecimal a, BigDecimal b) {
public static boolean gt(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) {
public static boolean ge(BigDecimal a, BigDecimal b) {
return gt(a, b) || equals(a, b);
}
public static boolean lt(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 le(BigDecimal a, BigDecimal b) {
return lt(a, b) || equals(a, b);
}
public static BigDecimal of(final String val) {
return (StringUtils.isBlank(val)) ? ZERO : new BigDecimal(val);
}

View File

@@ -85,9 +85,8 @@ public abstract class Enumeration<T extends Enumeration<T>> implements Comparabl
this.valueMap = valueMap;
}
@SafeVarargs
@StaticFactoryMethod(ValueSet.class)
public static <T extends Enumeration<T>> ValueSet<T> of(T... values) {
public static <T extends Enumeration<T>> ValueSet<T> of(T[] values) {
Map<Integer, T> temp = Arrays.stream(values)
.collect(Collectors.toMap(Enumeration::getId, Function.identity()));
return new ValueSet<>(Collections.unmodifiableMap(temp));

View File

@@ -16,6 +16,8 @@
package xyz.zhouxy.plusone.commons.util;
import java.math.BigDecimal;
/**
* Numbers
*
@@ -23,10 +25,6 @@ package xyz.zhouxy.plusone.commons.util;
*/
public class Numbers {
private Numbers() {
throw new IllegalStateException("Utility class");
}
// sum
public static int sum(final short... numbers) {
@@ -69,6 +67,14 @@ public class Numbers {
return result;
}
public static BigDecimal sum(final BigDecimal... numbers) {
BigDecimal result = BigDecimals.of("0.00");
for (BigDecimal number : numbers) {
result = result.add(number);
}
return result;
}
// between
public static boolean between(short value, short min, short max) {
@@ -90,4 +96,12 @@ public class Numbers {
public static boolean between(double value, double min, double max) {
return value >= min && value < max;
}
public static boolean between(BigDecimal value, BigDecimal min, BigDecimal max) {
return BigDecimals.ge(value, min) && BigDecimals.lt(value, max);
}
private Numbers() {
throw new IllegalStateException("Utility class");
}
}