diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java index 8e06b29..fbfc17d 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -78,54 +78,45 @@ public class Assert { } // between - int - private static boolean between(int value, int min, int max) { - return value >= min && value < max; - } public static void between(int value, int min, int max, Supplier e) throws E { - Assert.isTrue(between(value, min, max), e); + Assert.isTrue(Numbers.between(value, min, max), e); } public static void between(int value, int min, int max, String errorMessage) { - Assert.isTrue(between(value, min, max), errorMessage); + Assert.isTrue(Numbers.between(value, min, max), errorMessage); } public static void between(int value, int min, int max, String errorMessageTemplate, Object... args) { - Assert.isTrue(between(value, min, max), errorMessageTemplate, args); + Assert.isTrue(Numbers.between(value, min, max), errorMessageTemplate, args); } // between - long - private static boolean between(long value, long min, long max) { - return value >= min && value < max; - } public static void between(long value, long min, long max, Supplier e) throws E { - Assert.isTrue(between(value, min, max), e); + Assert.isTrue(Numbers.between(value, min, max), e); } public static void between(long value, long min, long max, String errorMessage) { - Assert.isTrue(between(value, min, max), errorMessage); + Assert.isTrue(Numbers.between(value, min, max), errorMessage); } public static void between(long value, long min, long max, String errorMessageTemplate, Object... args) { - Assert.isTrue(between(value, min, max), errorMessageTemplate, args); + Assert.isTrue(Numbers.between(value, min, max), errorMessageTemplate, args); } // between - double - private static boolean between(double value, double min, double max) { - return value >= min && value < max; - } public static void between(double value, double min, double max, Supplier e) throws E { - Assert.isTrue(between(value, min, max), e); + Assert.isTrue(Numbers.between(value, min, max), e); } public static void between(double value, double min, double max, String errorMessage) { - Assert.isTrue(between(value, min, max), errorMessage); + Assert.isTrue(Numbers.between(value, min, max), errorMessage); } public static void between(double value, double min, double max, String errorMessageTemplate, Object... args) { - Assert.isTrue(between(value, min, max), errorMessageTemplate, args); + Assert.isTrue(Numbers.between(value, min, max), errorMessageTemplate, args); } // notNull diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Numbers.java similarity index 72% rename from src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java rename to src/main/java/xyz/zhouxy/plusone/commons/util/Numbers.java index 7d8a9a4..365e0fd 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Numbers.java @@ -21,12 +21,14 @@ package xyz.zhouxy.plusone.commons.util; * * @author ZhouXY */ -public class NumberUtil { +public class Numbers { - private NumberUtil() { + private Numbers() { throw new IllegalStateException("Utility class"); } + // sum + public static int sum(final short... numbers) { int result = 0; for (short number : numbers) { @@ -66,4 +68,26 @@ public class NumberUtil { } return result; } + + // between + + public static boolean between(short value, short min, short max) { + return value >= min && value < max; + } + + public static boolean between(int value, int min, int max) { + return value >= min && value < max; + } + + public static boolean between(long value, long min, long max) { + return value >= min && value < max; + } + + public static boolean between(float value, float min, float max) { + return value >= min && value < max; + } + + public static boolean between(double value, double min, double max) { + return value >= min && value < max; + } }