public final class Validate
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
private |
Validate() |
Modifier and Type | Method and Description |
---|---|
(package private) static boolean |
assertFail(java.lang.String msg)
Cause a failure, but return false so it can be used in an assert statement.
|
static java.lang.Object |
ensureNotNull(java.lang.Object obj)
Verifies the input object is not null, and returns that object.
|
static java.lang.Object |
ensureNotNull(java.lang.Object obj,
java.lang.String msg,
java.lang.Object... args)
Verifies the input object is not null, and returns that object.
|
static void |
fail(java.lang.String msg)
Cause a failure.
|
static void |
fail(java.lang.String msg,
java.lang.Object... args)
Cause a failure.
|
static void |
isFalse(boolean val)
Validates that the value is false
|
static void |
isFalse(boolean val,
java.lang.String msg)
Validates that the value is false
|
static void |
isTrue(boolean val)
Validates that the value is true
|
static void |
isTrue(boolean val,
java.lang.String msg)
Validates that the value is true
|
static void |
noNullElements(java.lang.Object[] objects)
Validates that the array contains no null elements
|
static void |
noNullElements(java.lang.Object[] objects,
java.lang.String msg)
Validates that the array contains no null elements
|
static void |
notEmpty(java.lang.String string)
Validates that the string is not null and is not empty
|
static void |
notEmpty(java.lang.String string,
java.lang.String msg)
Validates that the string is not null and is not empty
|
static void |
notEmptyParam(java.lang.String string,
java.lang.String param)
Validates that the string parameter is not null and is not empty
|
static void |
notNull(java.lang.Object obj)
Validates that the object is not null
|
static void |
notNull(java.lang.Object obj,
java.lang.String msg)
Validates that the object is not null
|
static void |
notNullParam(java.lang.Object obj,
java.lang.String param)
Validates that the parameter is not null
|
static void |
wtf(java.lang.String msg)
Blow up if we reach an unexpected state.
|
public static void notNull(@Nullable java.lang.Object obj)
obj
- object to testValidationException
- if the object is nullpublic static void notNullParam(@Nullable java.lang.Object obj, java.lang.String param)
obj
- the parameter to testparam
- the name of the parameter, for presentation in the validation exception.ValidationException
- if the object is nullpublic static void notNull(@Nullable java.lang.Object obj, java.lang.String msg)
obj
- object to testmsg
- message to include in the Exception if validation failsValidationException
- if the object is nullpublic static java.lang.Object ensureNotNull(@Nullable java.lang.Object obj)
obj
- nullable object to case to not-nullValidationException
- if the object is nullpublic static java.lang.Object ensureNotNull(@Nullable java.lang.Object obj, java.lang.String msg, java.lang.Object... args)
obj
- nullable object to case to not-nullmsg
- the String format message to include in the validation exception when thrownargs
- the arguments to the msgValidationException
- if the object is nullpublic static void isTrue(boolean val)
val
- object to testValidationException
- if the object is not truepublic static void isTrue(boolean val, java.lang.String msg)
val
- object to testmsg
- message to include in the Exception if validation failsValidationException
- if the object is not truepublic static void isFalse(boolean val)
val
- object to testValidationException
- if the object is not falsepublic static void isFalse(boolean val, java.lang.String msg)
val
- object to testmsg
- message to include in the Exception if validation failsValidationException
- if the object is not falsepublic static void noNullElements(java.lang.Object[] objects)
objects
- the array to testValidationException
- if the array contains a null elementpublic static void noNullElements(java.lang.Object[] objects, java.lang.String msg)
objects
- the array to testmsg
- message to include in the Exception if validation failsValidationException
- if the array contains a null elementpublic static void notEmpty(@Nullable java.lang.String string)
string
- the string to testValidationException
- if the string is null or emptypublic static void notEmptyParam(@Nullable java.lang.String string, java.lang.String param)
string
- the string to testparam
- the name of the parameter, for presentation in the validation exception.ValidationException
- if the string is null or emptypublic static void notEmpty(@Nullable java.lang.String string, java.lang.String msg)
string
- the string to testmsg
- message to include in the Exception if validation failsValidationException
- if the string is null or emptypublic static void wtf(java.lang.String msg)
msg
- message to think aboutjava.lang.IllegalStateException
- if we reach this statepublic static void fail(java.lang.String msg)
msg
- message to output.java.lang.IllegalStateException
- if we reach this statestatic boolean assertFail(java.lang.String msg)
msg
- message to output.java.lang.IllegalStateException
- if we reach this statepublic static void fail(java.lang.String msg, java.lang.Object... args)
msg
- message to output.args
- the format arguments to the msgjava.lang.IllegalStateException
- if we reach this state