From f4da6b6ca16d13f5e0aaf0403e307dfa414b1927 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 21 Apr 2023 03:21:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20Assert=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/Assert.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 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 d7f0bf4..ee35e8c 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -88,7 +88,7 @@ public class Assert { Assert.isTrue(Objects.nonNull(value), errorMessageTemplate, args); } - // isEmpty + // isEmpty - Collection public static void isEmpty(@Nullable Collection collection, Supplier e) throws E { Assert.isTrue((collection == null || collection.isEmpty()), e); } @@ -101,7 +101,7 @@ public class Assert { Assert.isTrue((collection == null || collection.isEmpty()), errorMessageTemplate, args); } - // isNotEmpty + // isNotEmpty - Collection public static void isNotEmpty(@Nullable Collection collection, Supplier e) throws E { Assert.isFalse((collection == null || collection.isEmpty()), e); } @@ -114,6 +114,58 @@ public class Assert { Assert.isFalse((collection == null || collection.isEmpty()), errorMessageTemplate, args); } + // isEmpty - Array + public static void isEmpty(@Nullable T[] arr, Supplier e) throws E { + Assert.isTrue((arr == null || arr.length == 0), e); + } + + public static void isEmpty(@Nullable T[] arr, String errorMessage) { + Assert.isTrue((arr == null || arr.length == 0), errorMessage); + } + + public static void isEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) { + Assert.isTrue((arr == null || arr.length == 0), errorMessageTemplate, args); + } + + // isNotEmpty - Collection + public static void isNotEmpty(@Nullable T[] arr, Supplier e) throws E { + Assert.isFalse((arr == null || arr.length == 0), e); + } + + public static void isNotEmpty(@Nullable T[] arr, String errorMessage) { + Assert.isFalse((arr == null || arr.length == 0), errorMessage); + } + + public static void isNotEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) { + 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); + } + + public static void isEmpty(@Nullable String arr, String errorMessage) { + Assert.isTrue((arr == null || arr.length() == 0), errorMessage); + } + + public static void isEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) { + Assert.isTrue((arr == null || arr.length() == 0), errorMessageTemplate, args); + } + + // isNotEmpty - Collection + public static void isNotEmpty(@Nullable String arr, Supplier e) throws E { + Assert.isFalse((arr == null || arr.length() == 0), e); + } + + public static void isNotEmpty(@Nullable String arr, String errorMessage) { + Assert.isFalse((arr == null || arr.length() == 0), errorMessage); + } + + public static void isNotEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) { + Assert.isFalse((arr == null || arr.length() == 0), errorMessageTemplate, args); + } + // private consrtuctor private Assert() { throw new IllegalStateException("Utility class");