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 b1abfac..a009e66 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Assert.java @@ -113,71 +113,56 @@ public class Assert { } // isEmpty - Collection - private static boolean isEmpty(@Nullable Collection collection) { - return collection == null || collection.isEmpty(); + public static void isEmpty(@Nullable Collection collection, Supplier e) throws E { + Assert.isTrue(MoreCollections.isEmpty(collection), e); } - public static void isEmpty(@Nullable Collection collection, Supplier e) throws E { - Assert.isTrue(isEmpty(collection), e); + public static void isEmpty(@Nullable Collection collection, String errorMessage) { + Assert.isTrue(MoreCollections.isEmpty(collection), errorMessage); } - public static void isEmpty(@Nullable Collection collection, String errorMessage) { - Assert.isTrue(isEmpty(collection), errorMessage); - } - - public static void isEmpty(@Nullable Collection collection, String errorMessageTemplate, Object... args) { - Assert.isTrue(isEmpty(collection), errorMessageTemplate, args); + public static void isEmpty(@Nullable Collection collection, String errorMessageTemplate, Object... args) { + Assert.isTrue(MoreCollections.isEmpty(collection), errorMessageTemplate, args); } // isNotEmpty - Collection - private static boolean isNotEmpty(@Nullable Collection collection) { - return collection != null && !collection.isEmpty(); + public static void isNotEmpty(@Nullable Collection collection, Supplier e) throws E { + Assert.isTrue(MoreCollections.isNotEmpty(collection), e); } - public static void isNotEmpty(@Nullable Collection collection, Supplier e) throws E { - Assert.isTrue(isNotEmpty(collection), e); + public static void isNotEmpty(@Nullable Collection collection, String errorMessage) { + Assert.isTrue(MoreCollections.isNotEmpty(collection), errorMessage); } - public static void isNotEmpty(@Nullable Collection collection, String errorMessage) { - Assert.isTrue(isNotEmpty(collection), errorMessage); - } - - public static void isNotEmpty(@Nullable Collection collection, String errorMessageTemplate, Object... args) { - Assert.isTrue(isNotEmpty(collection), errorMessageTemplate, args); + public static void isNotEmpty(@Nullable Collection collection, String errorMessageTemplate, Object... args) { + Assert.isTrue(MoreCollections.isNotEmpty(collection), errorMessageTemplate, args); } // isEmpty - Array - private static boolean isEmpty(@Nullable T[] arr) { - return arr == null || arr.length == 0; - } - public static void isEmpty(@Nullable T[] arr, Supplier e) throws E { - Assert.isTrue(isEmpty(arr), e); + Assert.isTrue(MoreArrays.isEmpty(arr), e); } public static void isEmpty(@Nullable T[] arr, String errorMessage) { - Assert.isTrue(isEmpty(arr), errorMessage); + Assert.isTrue(MoreArrays.isEmpty(arr), errorMessage); } public static void isEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) { - Assert.isTrue(isEmpty(arr), errorMessageTemplate, args); + Assert.isTrue(MoreArrays.isEmpty(arr), errorMessageTemplate, args); } // isNotEmpty - Array - private static boolean isNotEmpty(@Nullable T[] arr) { - return arr != null && arr.length > 0; - } - + // TODO int[] long[] double[] public static void isNotEmpty(@Nullable T[] arr, Supplier e) throws E { - Assert.isTrue(isNotEmpty(arr), e); + Assert.isTrue(MoreArrays.isNotEmpty(arr), e); } public static void isNotEmpty(@Nullable T[] arr, String errorMessage) { - Assert.isTrue(isNotEmpty(arr), errorMessage); + Assert.isTrue(MoreArrays.isNotEmpty(arr), errorMessage); } public static void isNotEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) { - Assert.isTrue(isNotEmpty(arr), errorMessageTemplate, args); + Assert.isTrue(MoreArrays.isNotEmpty(arr), errorMessageTemplate, args); } // isEmpty - String diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java new file mode 100644 index 0000000..810b0cd --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java @@ -0,0 +1,42 @@ +package xyz.zhouxy.plusone.commons.util; + +import javax.annotation.Nullable; + +public class MoreArrays { + + public static boolean isEmpty(@Nullable int[] arr) { + return arr == null || arr.length == 0; + } + + public static boolean isNotEmpty(@Nullable int[] arr) { + return arr != null && arr.length > 0; + } + + public static boolean isEmpty(@Nullable long[] arr) { + return arr == null || arr.length == 0; + } + + public static boolean isNotEmpty(@Nullable long[] arr) { + return arr != null && arr.length > 0; + } + + public static boolean isEmpty(@Nullable double[] arr) { + return arr == null || arr.length == 0; + } + + public static boolean isNotEmpty(@Nullable double[] arr) { + return arr != null && arr.length > 0; + } + + public static boolean isEmpty(@Nullable T[] arr) { + return arr == null || arr.length == 0; + } + + public static boolean isNotEmpty(@Nullable T[] arr) { + return arr != null && arr.length > 0; + } + + private MoreArrays() { + throw new IllegalStateException("Utility class"); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreCollections.java b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreCollections.java new file mode 100644 index 0000000..f63f987 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreCollections.java @@ -0,0 +1,19 @@ +package xyz.zhouxy.plusone.commons.util; + +import java.util.Collection; + +import javax.annotation.Nullable; + +public class MoreCollections { + public static boolean isEmpty(@Nullable Collection collection) { + return collection == null || collection.isEmpty(); + } + + public static boolean isNotEmpty(@Nullable Collection collection) { + return collection != null && !collection.isEmpty(); + } + + private MoreCollections() { + throw new IllegalStateException("Utility class"); + } +}