From a22d9171c9a93b511f3a0686d681e18908a21582 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 29 Apr 2023 15:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20guava=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/Assert.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 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 82d62c2..25ef053 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -6,6 +6,8 @@ import java.util.function.Supplier; import javax.annotation.Nullable; +import com.google.common.base.Strings; + public class Assert { // isTrue @@ -127,7 +129,7 @@ public class Assert { Assert.isTrue((arr == null || arr.length == 0), errorMessageTemplate, args); } - // isNotEmpty - Collection + // isNotEmpty - Array public static void isNotEmpty(@Nullable T[] arr, Supplier e) throws E { Assert.isFalse((arr == null || arr.length == 0), e); } @@ -140,30 +142,30 @@ public class Assert { Assert.isFalse((arr == null || arr.length == 0), errorMessageTemplate, args); } - // isEmpty - Array - public static void isEmpty(@Nullable String arr, Supplier e) throws E { - Assert.isTrue((arr == null || arr.length() == 0), e); + // isEmpty - String + public static void isEmpty(@Nullable String str, Supplier e) throws E { + Assert.isTrue((str == null || str.isEmpty()), e); } - public static void isEmpty(@Nullable String arr, String errorMessage) { - Assert.isTrue((arr == null || arr.length() == 0), errorMessage); + public static void isEmpty(@Nullable String str, String errorMessage) { + Assert.isTrue((str == null || str.isEmpty()), errorMessage); } - public static void isEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) { - Assert.isTrue((arr == null || arr.length() == 0), errorMessageTemplate, args); + public static void isEmpty(@Nullable String str, String errorMessageTemplate, Object... args) { + Assert.isTrue((str == null || str.isEmpty()), errorMessageTemplate, args); } - // isNotEmpty - Collection - public static void isNotEmpty(@Nullable String arr, Supplier e) throws E { - Assert.isFalse((arr == null || arr.length() == 0), e); + // isNotEmpty - String + public static void isNotEmpty(@Nullable String str, Supplier e) throws E { + Assert.isFalse(Strings.isNullOrEmpty(str), e); } - public static void isNotEmpty(@Nullable String arr, String errorMessage) { - Assert.isFalse((arr == null || arr.length() == 0), errorMessage); + public static void isNotEmpty(@Nullable String str, String errorMessage) { + Assert.isFalse(Strings.isNullOrEmpty(str), errorMessage); } - public static void isNotEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) { - Assert.isFalse((arr == null || arr.length() == 0), errorMessageTemplate, args); + public static void isNotEmpty(@Nullable String str, String errorMessageTemplate, Object... args) { + Assert.isFalse(Strings.isNullOrEmpty(str), errorMessageTemplate, args); } // private constructor