public final class Assert extends Object
Modifier and Type | Method and Description |
---|---|
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 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(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(String name,
int max,
int actual)
Check that the named parameter is less than or equal to
max . |
static void |
checkMaximumParameter(String name,
long max,
long actual)
Check that the named parameter is less than or equal to
max . |
static void |
checkMinimumParameter(String name,
int min,
int actual)
Check that the named parameter is greater than or equal to
min . |
static void |
checkMinimumParameter(String name,
long min,
long actual)
Check that the named parameter is greater than or equal to
min . |
static <T> T |
checkNotNullArrayParam(String name,
int index,
T value)
Check that a value within the named array parameter is not
null . |
static <T> T |
checkNotNullParam(String name,
T value)
Check that the named parameter is not
null . |
static IllegalStateException |
impossibleSwitchCase(int val)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static IllegalStateException |
impossibleSwitchCase(long val)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static IllegalStateException |
impossibleSwitchCase(Object obj)
Return an exception indicating that the current switch case was intended to be unreachable.
|
static IllegalStateException |
unreachableCode()
Return an exception indicating that the current code was intended to be unreachable.
|
static UnsupportedOperationException |
unsupported()
Return an exception explaining that the caller's method is not supported.
|
@NotNull public static <T> T checkNotNullParam(String name, T value) throws IllegalArgumentException
null
. Use a standard exception message if it is.T
- the value typename
- the parameter namevalue
- the parameter valueIllegalArgumentException
- if the value is null
@NotNull public static <T> T checkNotNullArrayParam(String name, int index, T value) throws IllegalArgumentException
null
. Use a standard exception message if it
is.T
- the element value typename
- the parameter nameindex
- the array indexvalue
- the array element valueIllegalArgumentException
- if the value is null
public static void checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException
min
.name
- the parameter namemin
- the minimum valueactual
- the actual parameter valueIllegalArgumentException
- if the actual value is less than the minimum valuepublic static void checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException
min
.name
- the parameter namemin
- the minimum valueactual
- the actual parameter valueIllegalArgumentException
- if the actual value is less than the minimum valuepublic static void checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException
max
.name
- the parameter namemax
- the maximum valueactual
- the actual parameter valueIllegalArgumentException
- if the actual value is greater than the minimum valuepublic static void checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException
max
.name
- the parameter namemax
- the maximum valueactual
- the actual parameter valueIllegalArgumentException
- if the actual value is greater than the minimum valuepublic static void checkArrayBounds(Object[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
array
- the array to checkoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 ArrayIndexOutOfBoundsException
array
- the array to checkoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 ArrayIndexOutOfBoundsException
array
- the array to checkoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 ArrayIndexOutOfBoundsException
array
- the array to checkoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 ArrayIndexOutOfBoundsException
array
- the array to checkoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 ArrayIndexOutOfBoundsException
arrayLength
- the array length to check againstoffs
- the array offsetlen
- the array lengthArrayIndexOutOfBoundsException
- 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 objectIllegalArgumentException
- if the monitor is null
@NotNull public static <T> T assertNotHoldsLock(@NotNull T monitor)
assert
is enabled.T
- the monitor's typemonitor
- the monitor objectIllegalArgumentException
- if the monitor is null
public static IllegalStateException unreachableCode()
@NotNull public static IllegalStateException impossibleSwitchCase(@NotNull Object obj)
obj
- the switch case value@NotNull public static IllegalStateException impossibleSwitchCase(int val)
val
- the switch case value@NotNull public static IllegalStateException impossibleSwitchCase(long val)
val
- the switch case value@NotNull public static UnsupportedOperationException unsupported()
Copyright © 2015 JBoss, a division of Red Hat, Inc.