From c4dd542ff40fa1d21dbd193d77cd433fcc2bba37 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Fri, 18 Jul 2025 15:52:03 +0800 Subject: [PATCH 1/2] feat: check whether a collection is empty or not --- .../onixbyte/common/util/CollectionUtil.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java b/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java index 615f1ee..a1c7c67 100644 --- a/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java +++ b/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java @@ -112,4 +112,25 @@ public final class CollectionUtil { return result; } + /** + * Check whether a given collection is not empty. + * + * @param collection the collection to be checked + * @return {@code true} if provided collection is not null and not empty, + * {@code false} otherwise + */ + public static boolean notEmpty(Collection collection) { + return Objects.nonNull(collection) && !collection.isEmpty(); + } + + /** + * Check whether a given collection is empty. + * + * @param collection the collection to be checked + * @return {@code true} if provided collection is null or is empty, {@code false} otherwise + */ + public static boolean isEmpty(Collection collection) { + return Objects.isNull(collection) || collection.isEmpty(); + } + } From 25279ae8bab6aa17f107a6d08ff977a03b5abfa5 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Fri, 18 Jul 2025 16:34:37 +0800 Subject: [PATCH 2/2] feat: check whether a collection is empty or not --- .../com/onixbyte/common/util/CollectionUtil.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java b/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java index a1c7c67..2303b72 100644 --- a/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java +++ b/common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java @@ -113,21 +113,20 @@ public final class CollectionUtil { } /** - * Check whether a given collection is not empty. + * Check if a collection is not null and not empty. * - * @param collection the collection to be checked - * @return {@code true} if provided collection is not null and not empty, - * {@code false} otherwise + * @param collection the collection to check + * @return {@code true} if the collection is not null and not empty, {@code false} otherwise */ public static boolean notEmpty(Collection collection) { return Objects.nonNull(collection) && !collection.isEmpty(); } /** - * Check whether a given collection is empty. + * Check if a collection is null or empty. * - * @param collection the collection to be checked - * @return {@code true} if provided collection is null or is empty, {@code false} otherwise + * @param collection the collection to check + * @return {@code true} if the collection is null or empty, {@code false} otherwise */ public static boolean isEmpty(Collection collection) { return Objects.isNull(collection) || collection.isEmpty();