优化功能

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

@@ -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");
}
}