[java-support] branch master updated: Add int versions of numeric constraints.

Scott Cantor cantor.2 at osu.edu
Tue Nov 19 08:21:34 EST 2019


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=8c835f7299787f6c33414380e254bdb6f408251b

The following commit(s) were added to refs/heads/master by this push:
       new  8c835f7   Add int versions of numeric constraints.
8c835f7 is described below

commit 8c835f7299787f6c33414380e254bdb6f408251b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Nov 19 08:21:27 2019 -0500

    Add int versions of numeric constraints.
---
 .../utilities/java/support/logic/Constraint.java   | 84 +++++++++++++++++++++-
 1 file changed, 82 insertions(+), 2 deletions(-)

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 2b9336b..22b88c0 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
@@ -101,7 +101,7 @@ public final class Constraint {
 
         return number;
     }
-
+    
     /**
      * Checks that the given number is less than a given threshold. If the number is not less than the threshold a
      * {@link ConstraintViolationException} is thrown.
@@ -139,6 +139,86 @@ public final class Constraint {
     }
 
     /**
+     * Checks that the given number is greater than a given threshold. If the number is not greater than the threshold
+     * a {@link ConstraintViolationException} is thrown.
+     *
+     * @param threshold the threshold
+     * @param number the number to be checked
+     * @param message message used in the {@link ConstraintViolationException}
+     *
+     * @return the checked input
+     * 
+     * @since 8.0.0
+     */
+    public static int isGreaterThan(final int threshold, final int number, @Nonnull final String message) {
+        if (number <= threshold) {
+            throw new ConstraintViolationException(message);
+        }
+
+        return number;
+    }
+
+    /**
+     * Checks that the given number is greater than, or equal to, a given threshold. If the number is not greater than,
+     * or equal to, the threshold a {@link ConstraintViolationException} is thrown.
+     * 
+     * @param threshold the threshold
+     * @param number the number to be checked
+     * @param message message used in the {@link ConstraintViolationException}
+     * 
+     * @return the checked input
+     * 
+     * @since 8.0.0
+     */
+    public static int isGreaterThanOrEqual(final int threshold, final int number, @Nonnull final String message) {
+        if (number < threshold) {
+            throw new ConstraintViolationException(message);
+        }
+
+        return number;
+    }
+
+    /**
+     * Checks that the given number is less than a given threshold. If the number is not less than the threshold a
+     * {@link ConstraintViolationException} is thrown.
+     *
+     * @param threshold the threshold
+     * @param number the number to be checked
+     * @param message message used in the {@link ConstraintViolationException}
+     *
+     * @return the checked input
+     * 
+     * @since 8.0.0
+     */
+    public static int isLessThan(final int threshold, final int number, @Nonnull final String message) {
+        if (number >= threshold) {
+            throw new ConstraintViolationException(message);
+        }
+
+        return number;
+    }
+
+    /**
+     * Checks that the given number is less than, or equal to, a given threshold. If the number is not less than, or
+     * equal to, the threshold a {@link ConstraintViolationException} is thrown.
+     *
+     * @param threshold the threshold
+     * @param number the number to be checked
+     * @param message message used in the {@link ConstraintViolationException}
+     *
+     * @return the checked input
+     * 
+     * @since 8.0.0
+     */
+    public static int isLessThanOrEqual(final int threshold, final int number, @Nonnull final String message) {
+        if(number > threshold){
+            throw new ConstraintViolationException(message);
+        }
+
+        return number;
+    }
+
+    /**
      * Checks that the given collection is not empty. If the collection is null or empty a
      * {@link ConstraintViolationException} is thrown.
      * 
@@ -351,4 +431,4 @@ public final class Constraint {
 
         return number;
     }
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list