almost.functional.utils
public final class Preconditions extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
checkNonEmptyString(java.lang.String reference,
java.lang.String errorMessage)
Check that a String is not empty after removing whitespace.
|
static <T> T |
checkNotNull(T reference,
java.lang.String errorMessage)
Check that a reference is not null, throwing a IllegalArgumentException if it is.
|
static java.lang.Class |
isAssignableTo(java.lang.Class<?> reference,
java.lang.Class<?> toValue,
java.lang.String message)
Check that one class is assignable to another.
|
static <T> T |
precondition(T reference,
Predicate<T> predicate,
java.lang.Class<? extends java.lang.RuntimeException> ex,
java.lang.String msg)
Test a Predicate against a reference value, and if it fails throw a runtime exception with a message.
|
public static <T> T precondition(T reference, Predicate<T> predicate, java.lang.Class<? extends java.lang.RuntimeException> ex, java.lang.String msg) throws java.lang.RuntimeException
T
- The type of the reference valuereference
- the value to testpredicate
- the predicate test to invokeex
- The RuntimeException to usemsg
- The message to add to the exceptionjava.lang.RuntimeException
- An instance of ex if the predicate failspublic static <T> T checkNotNull(T reference, java.lang.String errorMessage)
T
- the type of the referencereference
- The reference to checkerrorMessage
- the message for the exception if the reference is nulljava.lang.IllegalArgumentException
- if the reference is nullpublic static java.lang.String checkNonEmptyString(java.lang.String reference, java.lang.String errorMessage)
reference
- the stringerrorMessage
- the message for the exceptionjava.lang.NullPointerException
- if the String is nulljava.lang.IllegalArgumentException
- if the string is non-null but zero lengthpublic static java.lang.Class isAssignableTo(java.lang.Class<?> reference, java.lang.Class<?> toValue, java.lang.String message)
reference
- the class to testtoValue
- the class assigning tomessage
- the message used in the exception if thrownjava.lang.ClassCastException
- if the assignment can not be made