[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java

noreply at shibboleth.net noreply at shibboleth.net
Wed Dec 26 23:05:22 EST 2012


Author: scantor
Date: Wed Dec 26 23:05:22 2012
New Revision: 315

URL: http://svn.shibboleth.net/view/utilities?rev=315&view=rev
Log:
Add overrides to check for empty arrays.

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java?rev=315&r1=314&r2=315&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/logic/Constraint.java Wed Dec 26 23:05:22 2012
@@ -36,7 +36,7 @@
      * is thrown.
      * 
      * @param <T> type of items in the collection
-     * @param collection collection check
+     * @param collection collection to check
      * @param message message used in the {@link ConstraintViolationException}
      * 
      * @return the checked input
@@ -49,7 +49,7 @@
 
         return collection;
     }
-
+    
     /**
      * Checks that the given boolean is false. If not an {@link ConstraintViolationException} is thrown.
      * 
@@ -143,7 +143,7 @@
      * is thrown.
      * 
      * @param <T> type of items in the collection
-     * @param collection collection check
+     * @param collection collection to check
      * @param message message used in the {@link ConstraintViolationException}
      * 
      * @return the checked input
@@ -157,6 +157,44 @@
         return collection;
     }
 
+    /**
+     * Checks that the given array is not empty. If the array is empty an {@link ConstraintViolationException}
+     * is thrown.
+     * 
+     * @param <T> type of items in the array
+     * @param array array to check
+     * @param message message used in the {@link ConstraintViolationException}
+     * 
+     * @return the checked input
+     */
+    @Nonnull public static <T> T[] isNotEmpty(@Nonnull final T[] array,
+            @Nonnull final String message) {
+        if (array == null || array.length == 0) {
+            throw new ConstraintViolationException(message);
+        }
+
+        return array;
+    }
+
+
+    /**
+     * Checks that the given byte array is not empty. If the array is empty an {@link ConstraintViolationException}
+     * is thrown.
+     * 
+     * @param array array to check
+     * @param message message used in the {@link ConstraintViolationException}
+     * 
+     * @return the checked input
+     */
+    @Nonnull public static byte[] isNotEmpty(@Nonnull final byte[] array,
+            @Nonnull final String message) {
+        if (array == null || array.length == 0) {
+            throw new ConstraintViolationException(message);
+        }
+
+        return array;
+    }    
+    
     /**
      * Checks that the given object is not null. If the object is null an {@link ConstraintViolationException} is
      * thrown.



More information about the commits mailing list