public final class Assertions extends Object
| Modifier and Type | Method | Description |
|---|---|---|
static void |
checkArgument(boolean expression) |
Throws
IllegalArgumentException if expression evaluates to false. |
static void |
checkArgument(boolean expression,
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 String |
checkNotEmpty(String string) |
Throws
IllegalArgumentException if string is null or zero length. |
static String |
checkNotEmpty(String string,
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,
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,
Object errorMessage) |
Throws
IllegalStateException if expression evaluates to false. |
static <T> T |
checkStateNotNull(T reference) |
Throws
IllegalStateException if reference is null. |
static <T> T |
checkStateNotNull(T reference,
Object errorMessage) |
Throws
IllegalStateException if reference is null. |
@Pure public static void checkArgument(boolean expression)
IllegalArgumentException if expression evaluates to false.expression - The expression to evaluate.IllegalArgumentException - If expression is false.@Pure
public static void checkArgument(boolean expression,
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).IllegalArgumentException - If expression is false.@Pure
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.IndexOutOfBoundsException - If index falls outside the specified bounds.@Pure public static void checkState(boolean expression)
IllegalStateException if expression evaluates to false.expression - The expression to evaluate.IllegalStateException - If expression is false.@Pure
public static void checkState(boolean expression,
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).IllegalStateException - If expression is false.@EnsuresNonNull("#1")
@Pure
public static <T> T checkStateNotNull(@Nullable
T reference)
IllegalStateException if reference is null.T - The type of the reference.reference - The reference.IllegalStateException - If reference is null.@EnsuresNonNull("#1")
@Pure
public static <T> T checkStateNotNull(@Nullable
T reference,
Object errorMessage)
IllegalStateException 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).IllegalStateException - If reference is null.@EnsuresNonNull("#1")
@Pure
public static <T> T checkNotNull(@Nullable
T reference)
NullPointerException if reference is null.T - The type of the reference.reference - The reference.NullPointerException - If reference is null.@EnsuresNonNull("#1")
@Pure
public static <T> T checkNotNull(@Nullable
T reference,
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).NullPointerException - If reference is null.@EnsuresNonNull("#1")
@Pure
public static String checkNotEmpty(@Nullable
String string)
IllegalArgumentException if string is null or zero length.string - The string to check.IllegalArgumentException - If string is null or 0-length.@EnsuresNonNull("#1")
@Pure
public static String checkNotEmpty(@Nullable
String string,
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).IllegalArgumentException - If string is null or 0-length.@Pure public static void checkMainThread()
IllegalStateException if the calling thread is not the application's main
thread.IllegalStateException - If the calling thread is not the application's main thread.