Package org.jsoup.helper
Class Validate
java.lang.Object
org.jsoup.helper.Validate
Validators to check that method arguments meet expectations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
ensureNotNull
(Object obj) Verifies the input object is not null, and returns that object.static Object
ensureNotNull
(Object obj, String msg, Object... args) Verifies the input object is not null, and returns that object.static void
Cause a failure.static void
Cause a failure.static void
isFalse
(boolean val) Validates that the value is falsestatic void
Validates that the value is falsestatic void
isTrue
(boolean val) Validates that the value is truestatic void
Validates that the value is truestatic void
noNullElements
(Object[] objects) Validates that the array contains no null elementsstatic void
noNullElements
(Object[] objects, String msg) Validates that the array contains no null elementsstatic void
Validates that the string is not null and is not emptystatic void
Validates that the string is not null and is not emptystatic void
notEmptyParam
(String string, String param) Validates that the string parameter is not null and is not emptystatic void
Validates that the object is not nullstatic void
Validates that the object is not nullstatic void
notNullParam
(Object obj, String param) Validates that the parameter is not nullstatic void
Blow up if we reach an unexpected state.
-
Method Details
-
notNull
Validates that the object is not null- Parameters:
obj
- object to test- Throws:
ValidationException
- if the object is null
-
notNullParam
Validates that the parameter is not null- Parameters:
obj
- the parameter to testparam
- the name of the parameter, for presentation in the validation exception.- Throws:
ValidationException
- if the object is null
-
notNull
Validates that the object is not null- Parameters:
obj
- object to testmsg
- message to include in the Exception if validation fails- Throws:
ValidationException
- if the object is null
-
ensureNotNull
Verifies the input object is not null, and returns that object. Effectively this casts a nullable object to a non- null object. (Works around lack of Objects.requestNonNull in Android version.)- Parameters:
obj
- nullable object to case to not-null- Returns:
- the object, or throws an exception if it is null
- Throws:
ValidationException
- if the object is null
-
ensureNotNull
Verifies the input object is not null, and returns that object. Effectively this casts a nullable object to a non- null object. (Works around lack of Objects.requestNonNull in Android version.)- Parameters:
obj
- nullable object to case to not-nullmsg
- the String format message to include in the validation exception when thrownargs
- the arguments to the msg- Returns:
- the object, or throws an exception if it is null
- Throws:
ValidationException
- if the object is null
-
isTrue
public static void isTrue(boolean val) Validates that the value is true- Parameters:
val
- object to test- Throws:
ValidationException
- if the object is not true
-
isTrue
Validates that the value is true- Parameters:
val
- object to testmsg
- message to include in the Exception if validation fails- Throws:
ValidationException
- if the object is not true
-
isFalse
public static void isFalse(boolean val) Validates that the value is false- Parameters:
val
- object to test- Throws:
ValidationException
- if the object is not false
-
isFalse
Validates that the value is false- Parameters:
val
- object to testmsg
- message to include in the Exception if validation fails- Throws:
ValidationException
- if the object is not false
-
noNullElements
Validates that the array contains no null elements- Parameters:
objects
- the array to test- Throws:
ValidationException
- if the array contains a null element
-
noNullElements
Validates that the array contains no null elements- Parameters:
objects
- the array to testmsg
- message to include in the Exception if validation fails- Throws:
ValidationException
- if the array contains a null element
-
notEmpty
Validates that the string is not null and is not empty- Parameters:
string
- the string to test- Throws:
ValidationException
- if the string is null or empty
-
notEmptyParam
Validates that the string parameter is not null and is not empty- Parameters:
string
- the string to testparam
- the name of the parameter, for presentation in the validation exception.- Throws:
ValidationException
- if the string is null or empty
-
notEmpty
Validates that the string is not null and is not empty- Parameters:
string
- the string to testmsg
- message to include in the Exception if validation fails- Throws:
ValidationException
- if the string is null or empty
-
wtf
Blow up if we reach an unexpected state.- Parameters:
msg
- message to think about- Throws:
IllegalStateException
- if we reach this state
-
fail
Cause a failure.- Parameters:
msg
- message to output.- Throws:
IllegalStateException
- if we reach this state
-
fail
Cause a failure.- Parameters:
msg
- message to output.args
- the format arguments to the msg- Throws:
IllegalStateException
- if we reach this state
-