public final class Assert
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
assertFalse(boolean expr)
Assert that the given expression is always
false. |
static <T> T |
assertHoldsLock(T monitor)
Assert that the given monitor is held by the current thread.
|
static <T> T |
assertNotHoldsLock(T monitor)
Assert that the given monitor is not held by the current thread.
|
static <T> T |
assertNotNull(T value)
Assert that the value is not
null. |
static boolean |
assertTrue(boolean expr)
Assert that the given expression is always
true. |
static void |
checkArrayBounds(byte[] array,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array.
|
static void |
checkArrayBounds(char[] array,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array.
|
static void |
checkArrayBounds(int[] array,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array.
|
static void |
checkArrayBounds(int arrayLength,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array length.
|
static void |
checkArrayBounds(long[] array,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array.
|
static void |
checkArrayBounds(java.lang.Object[] array,
int offs,
int len)
Check that the given offset and length fall completely within the bounds of the given array.
|
static void |
checkMaximumParameter(java.lang.String name,
int max,
int actual)
Check that the named parameter is less than or equal to
max. |
static void |
checkMaximumParameter(java.lang.String name,
long max,
long actual)
Check that the named parameter is less than or equal to
max. |
static void |
checkMinimumParameter(java.lang.String name,
int min,
int actual)
Check that the named parameter is greater than or equal to
min. |
static void |
checkMinimumParameter(java.lang.String name,
long min,
long actual)
Check that the named parameter is greater than or equal to
min. |
static java.lang.String |
checkNotEmptyParam(java.lang.String name,
java.lang.String value)
Check that the named parameter is not empty.
|
static <E,T extends java.util.Collection<E>> |
checkNotEmptyParam(java.lang.String name,
T value)
Check that the named parameter is not empty.
|
static <T> T |
checkNotNullArrayParam(java.lang.String name,
int index,
T value)
Check that a value within the named array parameter is not
null. |
static <T> T |
checkNotNullParam(java.lang.String name,
T value)
Check that the named parameter is not
null. |
static <T> T |
checkNotNullParamWithNullPointerException(java.lang.String name,
T value)
Check that the named parameter is not
null, using a NullPointerException as some specifications
require. |
static java.lang.IllegalStateException |
impossibleSwitchCase(int val)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static java.lang.IllegalStateException |
impossibleSwitchCase(long val)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static java.lang.IllegalStateException |
impossibleSwitchCase(java.lang.Object obj)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static java.lang.IllegalStateException |
unreachableCode()
Return an exception indicating that the current code was intended to be unreachable.
|
static java.lang.UnsupportedOperationException |
unsupported()
Return an exception explaining that the caller's method is not supported.
|
@NotNull public static <T> T checkNotNullParam(java.lang.String name, T value) throws java.lang.IllegalArgumentException
null. Use a standard exception message if it is.T - the value typename - the parameter namevalue - the parameter valuejava.lang.IllegalArgumentException - if the value is null@NotNull public static <T> T checkNotNullParamWithNullPointerException(java.lang.String name, T value) throws java.lang.NullPointerException
null, using a NullPointerException as some specifications
require. Use a standard exception message if it is.T - the value typename - the parameter namevalue - the parameter valuejava.lang.NullPointerException - if the value is null@NotNull public static <T> T checkNotNullArrayParam(java.lang.String name, int index, T value) throws java.lang.IllegalArgumentException
null. Use a standard exception message if it
is.T - the element value typename - the parameter nameindex - the array indexvalue - the array element valuejava.lang.IllegalArgumentException - if the value is null@NotNull public static java.lang.String checkNotEmptyParam(java.lang.String name, java.lang.String value)
name - the parameter namevalue - the parameter valuejava.lang.IllegalArgumentException - if the value is empty@NotNull public static <E,T extends java.util.Collection<E>> T checkNotEmptyParam(java.lang.String name, T value)
name - the parameter namevalue - the parameter valuejava.lang.IllegalArgumentException - if the value is emptypublic static void checkMinimumParameter(java.lang.String name,
int min,
int actual)
throws java.lang.IllegalArgumentException
min.name - the parameter namemin - the minimum valueactual - the actual parameter valuejava.lang.IllegalArgumentException - if the actual value is less than the minimum valuepublic static void checkMinimumParameter(java.lang.String name,
long min,
long actual)
throws java.lang.IllegalArgumentException
min.name - the parameter namemin - the minimum valueactual - the actual parameter valuejava.lang.IllegalArgumentException - if the actual value is less than the minimum valuepublic static void checkMaximumParameter(java.lang.String name,
int max,
int actual)
throws java.lang.IllegalArgumentException
max.name - the parameter namemax - the maximum valueactual - the actual parameter valuejava.lang.IllegalArgumentException - if the actual value is greater than the minimum valuepublic static void checkMaximumParameter(java.lang.String name,
long max,
long actual)
throws java.lang.IllegalArgumentException
max.name - the parameter namemax - the maximum valueactual - the actual parameter valuejava.lang.IllegalArgumentException - if the actual value is greater than the minimum valuepublic static void checkArrayBounds(java.lang.Object[] array,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
array - the array to checkoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array boundspublic static void checkArrayBounds(byte[] array,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
array - the array to checkoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array boundspublic static void checkArrayBounds(char[] array,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
array - the array to checkoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array boundspublic static void checkArrayBounds(int[] array,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
array - the array to checkoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array boundspublic static void checkArrayBounds(long[] array,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
array - the array to checkoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array boundspublic static void checkArrayBounds(int arrayLength,
int offs,
int len)
throws java.lang.ArrayIndexOutOfBoundsException
arrayLength - the array length to check againstoffs - the array offsetlen - the array lengthjava.lang.ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds@NotNull public static <T> T assertNotNull(T value)
null. Use a standard assertion failure message if it is. Only
runs if assert is enabled.T - the value typevalue - the not-null value@NotNull public static <T> T assertHoldsLock(@NotNull T monitor)
assert is enabled.T - the monitor's typemonitor - the monitor objectjava.lang.IllegalArgumentException - if the monitor is null@NotNull public static <T> T assertNotHoldsLock(@NotNull T monitor)
assert is enabled.T - the monitor's typemonitor - the monitor objectjava.lang.IllegalArgumentException - if the monitor is nullpublic static boolean assertTrue(boolean expr)
true.expr - the boolean expressionpublic static boolean assertFalse(boolean expr)
false.expr - the boolean expressionpublic static java.lang.IllegalStateException unreachableCode()
@NotNull public static java.lang.IllegalStateException impossibleSwitchCase(@NotNull java.lang.Object obj)
obj - the switch case value@NotNull public static java.lang.IllegalStateException impossibleSwitchCase(int val)
val - the switch case value@NotNull public static java.lang.IllegalStateException impossibleSwitchCase(long val)
val - the switch case value@NotNull public static java.lang.UnsupportedOperationException unsupported()
Copyright © 2015 JBoss, a division of Red Hat, Inc.