java.lang.Object
org.litebridgedb.commons.CollectionUtils
Utility class for working with collections.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the provided iterable is null or empty.static booleanChecks if the provided array is null or empty.static booleanisEmpty(@Nullable Collection<?> collection) Checks if the provided collection is null or empty.static booleanChecks if the provided map is null or empty.static <T extends Collection<U>,U>
TrequireNonEmpty(@Nullable T collection, String message) Ensures that the provided collection is not null or empty.static <T extends Collection<U>,U, X extends Throwable>
TrequireNonEmpty(@Nullable T collection, Supplier<? extends X> exceptionSupplier) Ensures that the provided collection is not null or empty.
-
Method Details
-
isEmpty
Checks if the provided array is null or empty.- Parameters:
array- the array to check; may be null- Returns:
- true if the array is null or empty; false otherwise
-
isEmpty
Checks if the provided iterable is null or empty.- Parameters:
iterable- the iterable to check; may be null- Returns:
- true if the iterable is null or empty; false otherwise
-
isEmpty
Checks if the provided collection is null or empty.- Parameters:
collection- the collection to check; may be null- Returns:
- true if the collection is null or empty; false otherwise
-
isEmpty
Checks if the provided map is null or empty.- Parameters:
map- the map to check; may be null- Returns:
- true if the map is null or empty; false otherwise
-
requireNonEmpty
public static <T extends Collection<U>,U> T requireNonEmpty(@Nullable T collection, String message) Ensures that the provided collection is not null or empty.If the collection is null or empty, an
IllegalArgumentExceptionis thrown with the given message.- Parameters:
collection- the collection to validate; may be nullmessage- the exception message to use if the validation fails- Returns:
- the validated non-null and non-empty collection
- Throws:
IllegalArgumentException- if the collection is null or empty
-
requireNonEmpty
Ensures that the provided map is not null or empty.If the map is null or empty, an
IllegalArgumentExceptionis thrown with the given message.- Parameters:
map- the map to validate; may be nullmessage- the exception message to use if the validation fails- Returns:
- the validated non-null and non-empty map
- Throws:
IllegalArgumentException- if the map is null or empty
-
requireNonEmpty
public static <T extends Collection<U>,U, T requireNonEmptyX extends Throwable> (@Nullable T collection, Supplier<? extends X> exceptionSupplier) throws X Ensures that the provided collection is not null or empty.If the collection is null or empty,the supplied exception is thrown.
- Type Parameters:
T- the type of the collectionU- the type of the elements in the collectionX- the type of exception to be thrown- Parameters:
collection- the collection to validate; may be nullexceptionSupplier- a supplier that provides the exception to be thrown if the validation fails- Returns:
- the validated non-null and non-empty collection
- Throws:
X- if the collection is null or empty
-