public final class SanityCheck
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T,K> T |
isA(T value,
java.lang.Class<K> clazz,
java.lang.String paramName)
Checks that value is of type K.
|
static <T,K> T |
isA(T value,
java.lang.Class<K> clazz,
java.lang.String customMessage,
java.lang.Object... params)
Checks that value is of type K.
|
static java.lang.String |
nonEmpty(java.lang.String value,
boolean trim,
java.lang.String customMessage,
java.lang.Object... params)
Checks if the passed in value is an empty String.
|
static java.lang.String |
nonEmpty(java.lang.String value,
java.lang.String paramName)
Checks if the passed in value is an empty string.
|
static java.lang.String |
nonEmpty(java.lang.String value,
java.lang.String paramName,
boolean trim)
Checks if the passed in value is an empty string.
|
static java.lang.String |
nonEmpty(java.lang.String value,
java.lang.String customMessage,
java.lang.Object... params)
Checks if the passed in value is an empty String.
|
static <T> T |
nonNull(T value,
java.lang.String paramName)
Checks that the passed in value is not null.
|
static <T> T |
nonNull(T value,
java.lang.String customMessage,
java.lang.Object... params)
Checks that the passed in value is not null.
|
public static <T> T nonNull(T value,
java.lang.String paramName)
NullPointerException is
thrown with a message specifying that the parameter can't be null.T - the type parameter of the value under testvalue - current valueparamName - parameter namepublic static <T> T nonNull(T value,
java.lang.String customMessage,
java.lang.Object... params)
NullPointerException is
thrown with message customMessage. If the custom message is a pattern, params will be applied
to that patternT - the type parameter of the value under testvalue - current valuecustomMessage - message to be put inside the NullPointerException. Can be a pattern.params - parameters to be applied to the customMessage patternString.format(String, Object...)public static java.lang.String nonEmpty(java.lang.String value,
java.lang.String paramName)
value - string to be checkedparamName - parameter name to be used in the error messagepublic static java.lang.String nonEmpty(java.lang.String value,
java.lang.String paramName,
boolean trim)
trim is true, the string
gets trimmed. If it is empty, an IllegalArgumentException gets thrown with an appropriate
error message.value - string to be checkedparamName - parameter name to be used in the error messagetrim - whether the string must be trimmed or notpublic static java.lang.String nonEmpty(java.lang.String value,
java.lang.String customMessage,
java.lang.Object... params)
IllegalArgumentException is thrown with the passed in custom message. The params are
applied to the customMessage according to String.formatvalue - string to be checkedcustomMessage - custom message to be put into the exceptionparams - parameters to be applied to the custom messageString.format(String, Object...)public static java.lang.String nonEmpty(java.lang.String value,
boolean trim,
java.lang.String customMessage,
java.lang.Object... params)
IllegalArgumentException is thrown with the passed in custom message. The params are
applied to the customMessage according to String.formatvalue - string to be checkedtrim - whether the string must be trimmed prior checking or notcustomMessage - custom message to be put into the exceptionparams - parameters to be applied to the custom messageString.format(String, Object...)public static <T,K> T isA(T value,
java.lang.Class<K> clazz,
java.lang.String paramName)
IllegalArgumentException is thrown
with an appropriate message.T - current value typeK - expected value typevalue - current valueclazz - expected classparamName - name of the parameter to be used inside the message put into the exceptionpublic static <T,K> T isA(T value,
java.lang.Class<K> clazz,
java.lang.String customMessage,
java.lang.Object... params)
IllegalArgumentException is thrown
with an appropriate message.T - current value typeK - expected value typevalue - current valueclazz - expected classcustomMessage - Custom message to be put inside the IllegalArgumentExceptionparams - parameters to be applied to customMessage
(String.format(String, Object...))