net.shibboleth.utilities.java.support.logic
Class Constraint

java.lang.Object
  extended by net.shibboleth.utilities.java.support.logic.Constraint

public final class Constraint
extends Object

A helper class for evaluating certain constraints. Any violation will thrown a ConstraintViolationException.


Constructor Summary
private Constraint()
          Constructor.
 
Method Summary
static
<T> Collection<T>
isEmpty(Collection<T> collection, String message)
          Checks that the given collection is empty.
static boolean isFalse(boolean b, String message)
          Checks that the given boolean is false.
static long isGreaterThan(long threshold, long number, String message)
          Checks that the given number is greater than a given threshold.
static long isGreaterThanOrEqual(long threshold, long number, String message)
          Checks that the given number is greater than, or equal to, a given threshold.
static long isLessThan(long threshold, long number, String message)
          Checks that the given number is less than a given threshold.
static long isLessThanOrEqual(long threshold, long number, String message)
          Checks that the given number is less than, or equal to, a given threshold.
static
<T> Collection<T>
isNotEmpty(Collection<T> collection, String message)
          Checks that the given collection is not empty.
static
<T> T
isNotNull(T obj, String message)
          Checks that the given object is not null.
static
<T> T
isNull(T obj, String message)
          Checks that the given object is null.
static boolean isTrue(boolean b, String message)
          Checks that the given boolean is true.
static
<T> T[]
noNullItems(T[] array, String message)
          Checks that the array does not contain any null elements.
static long numberInRangeExclusive(long lowerTheshold, long upperThreshold, long number, String message)
          Checks that the given number is in the exclusive range.
static long numberInRangeInclusive(long lowerTheshold, long upperThreshold, long number, String message)
          Checks that the given number is in the inclusive range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Constraint

private Constraint()
Constructor.

Method Detail

isEmpty

@Nonnull
public static <T> Collection<T> isEmpty(@Nonnull
                                                Collection<T> collection,
                                                @Nonnull
                                                String message)
Checks that the given collection is empty. If the collection is not empty an ConstraintViolationException is thrown.

Type Parameters:
T - type of items in the collection
Parameters:
collection - collection check
message - message used in the ConstraintViolationException
Returns:
the checked input

isFalse

public static boolean isFalse(boolean b,
                              @Nonnull
                              String message)
Checks that the given boolean is false. If not an ConstraintViolationException is thrown.

Parameters:
b - boolean to check
message - message used in ConstraintViolationException
Returns:
the checked boolean

isGreaterThan

public static long isGreaterThan(long threshold,
                                 long number,
                                 @Nonnull
                                 String message)
Checks that the given number is greater than a given threshold. If the number is not greater than the threshold an ConstraintViolationException is thrown.

Parameters:
threshold - the threshold
number - the number to be checked
message - message used in the ConstraintViolationException
Returns:
the checked input

isGreaterThanOrEqual

public static long isGreaterThanOrEqual(long threshold,
                                        long number,
                                        @Nonnull
                                        String message)
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 an ConstraintViolationException is thrown.

Parameters:
threshold - the threshold
number - the number to be checked
message - message used in the ConstraintViolationException
Returns:
the checked input

isLessThan

public static long isLessThan(long threshold,
                              long number,
                              @Nonnull
                              String message)
Checks that the given number is less than a given threshold. If the number is not less than the threshold an ConstraintViolationException is thrown.

Parameters:
threshold - the threshold
number - the number to be checked
message - message used in the ConstraintViolationException
Returns:
the checked input

isLessThanOrEqual

public static long isLessThanOrEqual(long threshold,
                                     long number,
                                     @Nonnull
                                     String message)
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 an ConstraintViolationException is thrown.

Parameters:
threshold - the threshold
number - the number to be checked
message - message used in the ConstraintViolationException
Returns:
the checked input

isNotEmpty

@Nonnull
public static <T> Collection<T> isNotEmpty(@Nonnull
                                                   Collection<T> collection,
                                                   @Nonnull
                                                   String message)
Checks that the given collection is not empty. If the collection is empty an ConstraintViolationException is thrown.

Type Parameters:
T - type of items in the collection
Parameters:
collection - collection check
message - message used in the ConstraintViolationException
Returns:
the checked input

isNotNull

@Nonnull
public static <T> T isNotNull(@Nullable
                                      T obj,
                                      @Nonnull
                                      String message)
Checks that the given object is not null. If the object is null an ConstraintViolationException is thrown.

Type Parameters:
T - object type
Parameters:
obj - object to check
message - message used in ConstraintViolationException
Returns:
the checked input

isNull

@Nullable
public static <T> T isNull(@Nullable
                                    T obj,
                                    @Nonnull
                                    String message)
Checks that the given object is null. If the object is not null an ConstraintViolationException is thrown.

Type Parameters:
T - object type
Parameters:
obj - object to check
message - message used in ConstraintViolationException
Returns:
the checked input

isTrue

public static boolean isTrue(boolean b,
                             @Nonnull
                             String message)
Checks that the given boolean is true. If not an ConstraintViolationException is thrown.

Parameters:
b - boolean to check
message - message used in ConstraintViolationException
Returns:
the checked boolean

noNullItems

@Nonnull
public static <T> T[] noNullItems(@Nonnull
                                          T[] array,
                                          @Nonnull
                                          String message)
Checks that the array does not contain any null elements.

Type Parameters:
T - type of elements in the array
Parameters:
array - array to check
message - message used in the ConstraintViolationException
Returns:
the given array

numberInRangeExclusive

public static long numberInRangeExclusive(long lowerTheshold,
                                          long upperThreshold,
                                          long number,
                                          @Nonnull
                                          String message)
Checks that the given number is in the exclusive range. If the number is not in the range an ConstraintViolationException is thrown.

Parameters:
lowerTheshold - lower bound of the range
upperThreshold - upper bound of the range
number - number to check
message - message used in the ConstraintViolationException
Returns:
the checked input

numberInRangeInclusive

public static long numberInRangeInclusive(long lowerTheshold,
                                          long upperThreshold,
                                          long number,
                                          @Nonnull
                                          String message)
Checks that the given number is in the inclusive range. If the number is not in the range an ConstraintViolationException is thrown.

Parameters:
lowerTheshold - lower bound of the range
upperThreshold - upper bound of the range
number - number to check
message - message used in the ConstraintViolationException
Returns:
the checked input


Copyright © 1999-2012. All Rights Reserved.