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 ObjectensureNotNull(@Nullable Object obj) Deprecated.static ObjectensureNotNull(@Nullable Object obj, String msg, Object... args) Deprecated.prefer to useexpectNotNull(Object, String, Object...)instead; will be removed in jsoup 1.24.1static <T> TexpectNotNull(@Nullable T obj) Verifies the input object is not null, and returns that object, maintaining its type.static <T> TexpectNotNull(@Nullable T obj, String msg, Object... args) Verifies the input object is not null, and returns that object, maintaining its type.static voidCause a failure.static voidCause a failure.static voidisFalse(boolean val) Validates that the value is falsestatic voidValidates that the value is falsestatic voidisTrue(boolean val) Validates that the value is truestatic voidValidates that the value is truestatic voidnoNullElements(Object[] objects) Validates that the array contains no null elementsstatic voidnoNullElements(Object[] objects, String msg) Validates that the array contains no null elementsstatic voidValidates that the string is not null and is not emptystatic voidValidates that the string is not null and is not emptystatic voidnotEmptyParam(@Nullable String string, String param) Validates that the string parameter is not null and is not emptystatic voidValidates that the object is not nullstatic voidValidates that the object is not nullstatic voidnotNullParam(@Nullable Object obj, String param) Validates that the parameter is not nullstatic voidBlow 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
Deprecated.prefer to useexpectNotNull(Object, String, Object...)instead; will be removed in jsoup 1.24.1Verifies 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 cast to not-null- Returns:
- the object, or throws an exception if it is null
- Throws:
ValidationException- if the object is null
-
ensureNotNull
Deprecated.prefer to useexpectNotNull(Object, String, Object...)instead; will be removed in jsoup 1.24.1Verifies 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 cast 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
-
expectNotNull
Verifies the input object is not null, and returns that object, maintaining its type. Effectively this casts a nullable object to a non-null object.- Parameters:
obj- nullable object to cast to not-null- Returns:
- the object, or throws an exception if it is null
- Throws:
ValidationException- if the object is null
-
expectNotNull
Verifies the input object is not null, and returns that object, maintaining its type. Effectively this casts a nullable object to a non-null object.- Parameters:
obj- nullable object to cast 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
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
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
-
expectNotNull(Object, String, Object...)instead; will be removed in jsoup 1.24.1