From f1dcf0beba66948763f32d653d87d4bd35288e37 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 27 Jun 2023 01:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20NumberUtil=20=E4=B8=BA=20N?= =?UTF-8?q?umbers=E3=80=82=E6=B7=BB=E5=8A=A0=20between=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/Assert.java | 27 ++++++------------ .../util/{NumberUtil.java => Numbers.java} | 28 +++++++++++++++++-- 2 files changed, 35 insertions(+), 20 deletions(-) rename src/main/java/xyz/zhouxy/plusone/commons/util/{NumberUtil.java => Numbers.java} (72%) 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; + } }