From 625dd01e6314f8c6575b0c8adfe9d995edd1fc21 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 30 Apr 2023 22:11:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E8=BD=BD=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=9B=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/Assert.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) 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 3fb524b..782b192 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -11,39 +11,51 @@ import com.google.common.base.Strings; public class Assert { // isTrue - public static void isTrue(@Nullable Boolean conditions, Supplier e) throws E { - if (!Boolean.TRUE.equals(conditions)) { + public static void isTrue(@Nullable Boolean condition, Supplier e) throws E { + if (!Boolean.TRUE.equals(condition)) { throw e.get(); } } - public static void isTrue(@Nullable Boolean conditions, String errorMessage) { - if (!Boolean.TRUE.equals(conditions)) { + public static void isTrue(@Nullable Boolean condition) { + if (!Boolean.TRUE.equals(condition)) { + throw new IllegalArgumentException(); + } + } + + public static void isTrue(@Nullable Boolean condition, String errorMessage) { + if (!Boolean.TRUE.equals(condition)) { throw new IllegalArgumentException(errorMessage); } } - public static void isTrue(@Nullable Boolean conditions, String errorMessageTemplate, Object... args) { - if (!Boolean.TRUE.equals(conditions)) { + public static void isTrue(@Nullable Boolean condition, String errorMessageTemplate, Object... args) { + if (!Boolean.TRUE.equals(condition)) { throw new IllegalArgumentException(String.format(errorMessageTemplate, args)); } } // isFalse - public static void isFalse(@Nullable Boolean conditions, Supplier e) throws E { - if (!Boolean.FALSE.equals(conditions)) { + public static void isFalse(@Nullable Boolean condition, Supplier e) throws E { + if (!Boolean.FALSE.equals(condition)) { throw e.get(); } } - public static void isFalse(@Nullable Boolean conditions, String errorMessage) { - if (!Boolean.FALSE.equals(conditions)) { + public static void isFalse(@Nullable Boolean condition) { + if (!Boolean.FALSE.equals(condition)) { + throw new IllegalArgumentException(); + } + } + + public static void isFalse(@Nullable Boolean condition, String errorMessage) { + if (!Boolean.FALSE.equals(condition)) { throw new IllegalArgumentException(errorMessage); } } - public static void isFalse(@Nullable Boolean conditions, String errorMessageTemplate, Object... args) { - if (!Boolean.FALSE.equals(conditions)) { + public static void isFalse(@Nullable Boolean condition, String errorMessageTemplate, Object... args) { + if (!Boolean.FALSE.equals(condition)) { throw new IllegalArgumentException(String.format(errorMessageTemplate, args)); } }