[java-support] branch master updated: Add null element check for collections.
Marvin S. Addison
marvin.addison at gmail.com
Fri Oct 9 14:56:29 EDT 2015
This is an automated email from the git hooks/post-receive script.
serac pushed a commit to branch master
in repository java-support.
The following commit(s) were added to refs/heads/master by this push:
new 373d4d8 Add null element check for collections.
373d4d8 is described below
commit 373d4d8a7244c14badf883c5c0e3cc995ff212f6
Author: Marvin S. Addison <marvin.addison at gmail.com>
AuthorDate: Fri Oct 9 14:19:27 2015 -0400
Add null element check for collections.
---
.../utilities/java/support/logic/Constraint.java | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java b/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java
index 3b40044..958043b 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java
@@ -289,6 +289,30 @@ public final class Constraint {
}
/**
+ * Checks that the collection does not contain any null elements.
+ *
+ * @param <T> type of collection to inspect.
+ * @param collection to check.
+ * @param message message used in the {@link ConstraintViolationException}
+ *
+ * @return the given array
+ */
+ @Nonnull public static <T extends Collection<?>> T noNullItems(
+ @Nonnull final T collection, @Nonnull String message) {
+ if (collection == null) {
+ throw new ConstraintViolationException(message);
+ }
+
+ for (Object element : collection) {
+ if (element == null) {
+ throw new ConstraintViolationException(message);
+ }
+ }
+
+ return collection;
+ }
+
+ /**
* Checks that the given number is in the exclusive range. If the number is not in the range an
* {@link ConstraintViolationException} is thrown.
*
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list