public final class Assertions
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
checkArgument(boolean expression)
Ensures the truth of an expression involving one or more arguments passed to the calling
method.
|
static void |
checkArgument(boolean expression,
java.lang.Object errorMessage)
Ensures the truth of an expression involving one or more arguments passed to the calling
method.
|
static void |
checkMainThread()
Ensures that the calling thread is the application's main thread.
|
static java.lang.String |
checkNotEmpty(java.lang.String string)
Ensures that a string passed as an argument to the calling method is not null or 0-length.
|
static java.lang.String |
checkNotEmpty(java.lang.String string,
java.lang.Object errorMessage)
Ensures that a string passed as an argument to the calling method is not null or 0-length.
|
static <T> T |
checkNotNull(T reference)
Ensures that an object reference is not null.
|
static <T> T |
checkNotNull(T reference,
java.lang.Object errorMessage)
Ensures that an object reference is not null.
|
static void |
checkState(boolean expression)
Ensures the truth of an expression involving the state of the calling instance.
|
static void |
checkState(boolean expression,
java.lang.Object errorMessage)
Ensures the truth of an expression involving the state of the calling instance.
|
public static void checkArgument(boolean expression)
expression
- A boolean expression.java.lang.IllegalArgumentException
- If expression
is false.public static void checkArgument(boolean expression, java.lang.Object errorMessage)
expression
- A boolean expression.errorMessage
- The exception message to use if the check fails. The message is converted
to a String
using String.valueOf(Object)
.java.lang.IllegalArgumentException
- If expression
is false.public static void checkState(boolean expression)
expression
- A boolean expression.java.lang.IllegalStateException
- If expression
is false.public static void checkState(boolean expression, java.lang.Object errorMessage)
expression
- A boolean expression.errorMessage
- The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object)
.java.lang.IllegalStateException
- If expression
is false.public static <T> T checkNotNull(T reference)
reference
- An object reference.java.lang.NullPointerException
- If reference
is null.public static <T> T checkNotNull(T reference, java.lang.Object errorMessage)
reference
- An object reference.errorMessage
- The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object)
.java.lang.NullPointerException
- If reference
is null.public static java.lang.String checkNotEmpty(java.lang.String string)
string
- A string.java.lang.IllegalArgumentException
- If string
is null or 0-length.public static java.lang.String checkNotEmpty(java.lang.String string, java.lang.Object errorMessage)
string
- A string.errorMessage
- The exception message to use if the check fails. The message is converted
to a string using String.valueOf(Object)
.java.lang.IllegalArgumentException
- If string
is null or 0-length.public static void checkMainThread()
java.lang.IllegalStateException
- If the calling thread is not the application's main thread.