Skip to content

Commit cde824f

Browse files
author
zihluwang
committed
Merge branch 'feature/collection-checker' into develop
2 parents f8bce22 + 25279ae commit cde824f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,24 @@ public static <T, C extends Collection<T>> List<C> chunk(
112112
return result;
113113
}
114114

115+
/**
116+
* Check if a collection is not null and not empty.
117+
*
118+
* @param collection the collection to check
119+
* @return {@code true} if the collection is not null and not empty, {@code false} otherwise
120+
*/
121+
public static boolean notEmpty(Collection<?> collection) {
122+
return Objects.nonNull(collection) && !collection.isEmpty();
123+
}
124+
125+
/**
126+
* Check if a collection is null or empty.
127+
*
128+
* @param collection the collection to check
129+
* @return {@code true} if the collection is null or empty, {@code false} otherwise
130+
*/
131+
public static boolean isEmpty(Collection<?> collection) {
132+
return Objects.isNull(collection) || collection.isEmpty();
133+
}
134+
115135
}

0 commit comments

Comments
 (0)