Package net.shibboleth.shared.logic
Class Constraint
java.lang.Object
net.shibboleth.shared.logic.Constraint
A helper class for evaluating certain constraints. Any violation will thrown a
ConstraintViolationException.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection<T>isEmpty(Collection<T> collection, String message) Checks that the given collection is null or empty.static booleanChecks that the given boolean is false.static intisGreaterThan(int threshold, int number, String message) Checks that the given number is greater than a given threshold.static longisGreaterThan(long threshold, long number, String message) Checks that the given number is greater than a given threshold.static intisGreaterThanOrEqual(int threshold, int number, String message) Checks that the given number is greater than, or equal to, a given threshold.static longisGreaterThanOrEqual(long threshold, long number, String message) Checks that the given number is greater than, or equal to, a given threshold.static intisLessThan(int threshold, int number, String message) Checks that the given number is less than a given threshold.static longisLessThan(long threshold, long number, String message) Checks that the given number is less than a given threshold.static intisLessThanOrEqual(int threshold, int number, String message) Checks that the given number is less than, or equal to, a given threshold.static longisLessThanOrEqual(long threshold, long number, String message) Checks that the given number is less than, or equal to, a given threshold.static byte[]isNotEmpty(byte[] array, String message) Checks that the given byte array is not empty.static StringisNotEmpty(String string, String message) Checks that the given string is not empty.static <T> Collection<T>isNotEmpty(Collection<T> collection, String message) Checks that the given collection is not empty.static <T> T[]isNotEmpty(T[] array, String message) Checks that the given array is not empty.static <T> TChecks that the given object is not null.static <T> TChecks that the given object is null.static booleanChecks that the given boolean is true.static <T> T[]noNullItems(T[] array, String message) Checks that the array is non null and does not contain any null elements.static <T extends Collection<?>>
TnoNullItems(T collection, String message) Checks that the collection is non null and does not contain any null elements.static longnumberInRangeExclusive(long lowerTheshold, long upperThreshold, long number, String message) Checks that the given number is in the exclusive range.static longnumberInRangeInclusive(long lowerTheshold, long upperThreshold, long number, String message) Checks that the given number is in the inclusive range.
-
Constructor Details
-
Constraint
private Constraint()Constructor.
-
-
Method Details
-
isEmpty
@Nullable public static <T> Collection<T> isEmpty(@Nullable @NullableElements Collection<T> collection, @Nonnull String message) Checks that the given collection is null or empty. If the collection is not empty aConstraintViolationExceptionis thrown.- Type Parameters:
T- type of items in the collection- Parameters:
collection- collection to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isFalse
Checks that the given boolean is false. If not aConstraintViolationExceptionis thrown.- Parameters:
b- boolean to checkmessage- message used inConstraintViolationException- Returns:
- the checked boolean
-
isGreaterThan
Checks that the given number is greater than a given threshold. If the number is not greater than the threshold aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isGreaterThanOrEqual
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 aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isLessThan
Checks that the given number is less than a given threshold. If the number is not less than the threshold aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isLessThanOrEqual
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 aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isGreaterThan
Checks that the given number is greater than a given threshold. If the number is not greater than the threshold aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
- Since:
- 8.0.0
-
isGreaterThanOrEqual
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 aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
- Since:
- 8.0.0
-
isLessThan
Checks that the given number is less than a given threshold. If the number is not less than the threshold aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
- Since:
- 8.0.0
-
isLessThanOrEqual
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 aConstraintViolationExceptionis thrown.- Parameters:
threshold- the thresholdnumber- the number to be checkedmessage- message used in theConstraintViolationException- Returns:
- the checked input
- Since:
- 8.0.0
-
isNotEmpty
@Nonnull public static <T> Collection<T> isNotEmpty(@Nullable @NullableElements Collection<T> collection, @Nonnull String message) Checks that the given collection is not empty. If the collection is null or empty aConstraintViolationExceptionis thrown.- Type Parameters:
T- type of items in the collection- Parameters:
collection- collection to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isNotEmpty
@Nonnull public static <T> T[] isNotEmpty(@Nullable @NullableElements T[] array, @Nonnull String message) Checks that the given array is not empty. If the array is null or empty aConstraintViolationExceptionis thrown.- Type Parameters:
T- type of items in the array- Parameters:
array- array to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isNotEmpty
@Nonnull public static byte[] isNotEmpty(@Nullable @NullableElements byte[] array, @Nonnull String message) Checks that the given byte array is not empty. If the array is null or empty aConstraintViolationExceptionis thrown.- Parameters:
array- array to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isNotEmpty
Checks that the given string is not empty. If the string is null or empty aConstraintViolationExceptionis thrown.- Parameters:
string- string to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-
isNotNull
Checks that the given object is not null. If the object is null aConstraintViolationExceptionis thrown.- Type Parameters:
T- object type- Parameters:
obj- object to checkmessage- message used inConstraintViolationException- Returns:
- the checked input
-
isNull
Checks that the given object is null. If the object is not null aConstraintViolationExceptionis thrown.- Type Parameters:
T- object type- Parameters:
obj- object to checkmessage- message used inConstraintViolationException- Returns:
- the checked input
-
isTrue
Checks that the given boolean is true. If not aConstraintViolationExceptionis thrown.- Parameters:
b- boolean to checkmessage- message used inConstraintViolationException- Returns:
- the checked boolean
-
noNullItems
Checks that the array is non null and does not contain any null elements.- Type Parameters:
T- type of elements in the array- Parameters:
array- array to checkmessage- message used in theConstraintViolationException- Returns:
- the given array
-
noNullItems
@Nonnull public static <T extends Collection<?>> T noNullItems(@Nullable @NullableElements T collection, @Nonnull String message) Checks that the collection is non null and does not contain any null elements.- Type Parameters:
T- type of collection to inspect.- Parameters:
collection- to check.message- message used in theConstraintViolationException- 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 aConstraintViolationExceptionis thrown.- Parameters:
lowerTheshold- lower bound of the rangeupperThreshold- upper bound of the rangenumber- number to checkmessage- message used in theConstraintViolationException- 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 aConstraintViolationExceptionis thrown.- Parameters:
lowerTheshold- lower bound of the rangeupperThreshold- upper bound of the rangenumber- number to checkmessage- message used in theConstraintViolationException- Returns:
- the checked input
-