public final class Assertions
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArgument(boolean expression)
Throws
IllegalArgumentException if expression evaluates to false. |
static void |
checkArgument(boolean expression,
java.lang.Object errorMessage)
Throws
IllegalArgumentException if expression evaluates to false. |
static int |
checkIndex(int index,
int start,
int limit)
Throws
IndexOutOfBoundsException if index falls outside the specified bounds. |
static void |
checkMainThread()
Throws
IllegalStateException if the calling thread is not the application's main
thread. |
static java.lang.String |
checkNotEmpty(java.lang.String string)
Throws
IllegalArgumentException if string is null or zero length. |
static java.lang.String |
checkNotEmpty(java.lang.String string,
java.lang.Object errorMessage)
Throws
IllegalArgumentException if string is null or zero length. |
static <T> T |
checkNotNull(T reference)
Throws
NullPointerException if reference is null. |
static <T> T |
checkNotNull(T reference,
java.lang.Object errorMessage)
Throws
NullPointerException if reference is null. |
static void |
checkState(boolean expression)
Throws
IllegalStateException if expression evaluates to false. |
static void |
checkState(boolean expression,
java.lang.Object errorMessage)
Throws
IllegalStateException if expression evaluates to false. |
public static void checkArgument(boolean expression)
IllegalArgumentException if expression evaluates to false.expression - The expression to evaluate.java.lang.IllegalArgumentException - If expression is false.public static void checkArgument(boolean expression,
java.lang.Object errorMessage)
IllegalArgumentException if expression evaluates to false.expression - The expression to evaluate.errorMessage - The exception message if an exception is thrown. The message is converted
to a String using String.valueOf(Object).java.lang.IllegalArgumentException - If expression is false.public static int checkIndex(int index,
int start,
int limit)
IndexOutOfBoundsException if index falls outside the specified bounds.index - The index to test.start - The start of the allowed range (inclusive).limit - The end of the allowed range (exclusive).index that was validated.java.lang.IndexOutOfBoundsException - If index falls outside the specified bounds.public static void checkState(boolean expression)
IllegalStateException if expression evaluates to false.expression - The expression to evaluate.java.lang.IllegalStateException - If expression is false.public static void checkState(boolean expression,
java.lang.Object errorMessage)
IllegalStateException if expression evaluates to false.expression - The expression to evaluate.errorMessage - The exception message if an exception is thrown. The message is converted
to a String using String.valueOf(Object).java.lang.IllegalStateException - If expression is false.@EnsuresNonNull(value="#1")
public static <T> T checkNotNull(@Nullable
T reference)
NullPointerException if reference is null.T - The type of the reference.reference - The reference.java.lang.NullPointerException - If reference is null.@EnsuresNonNull(value="#1")
public static <T> T checkNotNull(@Nullable
T reference,
java.lang.Object errorMessage)
NullPointerException if reference is null.T - The type of the reference.reference - The 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.@EnsuresNonNull(value="#1")
public static java.lang.String checkNotEmpty(@Nullable
java.lang.String string)
IllegalArgumentException if string is null or zero length.string - The string to check.java.lang.IllegalArgumentException - If string is null or 0-length.@EnsuresNonNull(value="#1")
public static java.lang.String checkNotEmpty(@Nullable
java.lang.String string,
java.lang.Object errorMessage)
IllegalArgumentException if string is null or zero length.string - The string to check.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()
IllegalStateException if the calling thread is not the application's main
thread.java.lang.IllegalStateException - If the calling thread is not the application's main thread.