Top Description Constructors Methods
org.wildfly.common

public final Class Assert

extends Object
Class Inheritance
Imports
java.util.Collection, .Map, org.wildfly.common._private.CommonMessages, org.wildfly.common.annotation.NotNull

A set of assertions and checks.
Author
David M. Lloyd

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

the boolean expression
assertFalse
(boolean
the boolean expression
expr
)

Assert that the given expression is always false.

public static <
the monitor's type
T
>
T

Returns:

the value that was passed in
assertHoldsLock
(T
the monitor object
monitor
)

Assert that the given monitor is held by the current thread.

public static <
the monitor's type
T
>
T

Returns:

the value that was passed in
assertNotHoldsLock
(T
the monitor object
monitor
)

Assert that the given monitor is not held by the current thread.

public static <
the value type
T
>
T

Returns:

the value that was passed in
assertNotNull
(T
the not-null value
value
)

Assert that the value is not null.

public static boolean

Returns:

the boolean expression
assertTrue
(boolean
the boolean expression
expr
)

Assert that the given expression is always true.

public static void
checkArrayBounds(final Object[]
the array to check
array
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array.

public static void
checkArrayBounds(final byte[]
the array to check
array
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array.

public static void
checkArrayBounds(final char[]
the array to check
array
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array.

public static void
checkArrayBounds(final int[]
the array to check
array
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array.

public static void
checkArrayBounds(final long[]
the array to check
array
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array.

public static void
checkArrayBounds(final int
the array length to check against
arrayLength
,
final int
the array offset
offs
,
final int
the array length
len
)

Check that the given offset and length fall completely within the bounds of the given array length.

public static void
checkMaximumParameter(String
the parameter name
name
,
int
the maximum value
max
,
int
the actual parameter value
actual
)

Check that the named parameter is less than or equal to max.

public static void
checkMaximumParameter(String
the parameter name
name
,
long
the maximum value
max
,
long
the actual parameter value
actual
)

Check that the named parameter is less than or equal to max.

public static void
checkMaximumParameter(String
the parameter name
name
,
float
the maximum value
max
,
float
the actual parameter value
actual
)

Check that the named parameter is less than or equal to max.

public static void
checkMaximumParameter(String
the parameter name
name
,
double
the maximum value
max
,
double
the actual parameter value
actual
)

Check that the named parameter is less than or equal to max.

public static void
checkMinimumParameter(String
the parameter name
name
,
int
the minimum value
min
,
int
the actual parameter value
actual
)

Check that the named parameter is greater than or equal to min.

public static void
checkMinimumParameter(String
the parameter name
name
,
long
the minimum value
min
,
long
the actual parameter value
actual
)

Check that the named parameter is greater than or equal to min.

public static void
checkMinimumParameter(String
the parameter name
name
,
float
the minimum value
min
,
float
the actual parameter value
actual
)

Check that the named parameter is greater than or equal to min.

public static void
checkMinimumParameter(String
the parameter name
name
,
double
the minimum value
min
,
double
the actual parameter value
actual
)

Check that the named parameter is greater than or equal to min.

public static String

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
String
the parameter value
value
)

Check that the named parameter is not empty.

public static CharSequence

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
CharSequence
the parameter value
value
)

Check that the named parameter is not empty.

public static <E, T extends Collection<E>> T

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
T
the parameter value
value
)

Check that the named parameter is not empty.

public static <K, V, T extends Map<K, V>> T

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
T
the parameter value
value
)

Check that the named parameter is not empty.

public static <T> T[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
T[]
the parameter value
value
)

Check that the named parameter is not empty.

public static boolean[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
boolean[]
the parameter value
value
)

Check that the named parameter is not empty.

public static byte[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
byte[]
the parameter value
value
)

Check that the named parameter is not empty.

public static short[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
short[]
the parameter value
value
)

Check that the named parameter is not empty.

public static int[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
int[]
the parameter value
value
)

Check that the named parameter is not empty.

public static long[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
long[]
the parameter value
value
)

Check that the named parameter is not empty.

public static float[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
float[]
the parameter value
value
)

Check that the named parameter is not empty.

public static double[]

Returns:

the value that was passed in
checkNotEmptyParam
(String
the parameter name
name
,
double[]
the parameter value
value
)

Check that the named parameter is not empty.

public static <
the element value type
T
>
T

Returns:

the array element value that was passed in
checkNotNullArrayParam
(String
the parameter name
name
,
int
the array index
index
,
T
the array element value
value
)

Check that a value within the named array parameter is not null.

public static <
the value type
T
>
T

Returns:

the value that was passed in
checkNotNullParam
(String
the parameter name
name
,
T
the parameter value
value
)

Check that the named parameter is not null.

private static <T> void
checkNotNullParamChecked(final String name, final T value)

public static <
the value type
T
>
T

Returns:

the value that was passed in
checkNotNullParamWithNullPointerException
(String
the parameter name
name
,
T
the parameter value
value
)

Check that the named parameter is not null, using a NullPointerException as some specifications require.

public static IllegalStateException

Returns:

the exception which may be immediately thrown
impossibleSwitchCase
(Object
the switch case value
obj
)

Return an exception indicating that the current switch case was intended to be unreachable.

public static IllegalStateException

Returns:

the exception which may be immediately thrown
impossibleSwitchCase
(int
the switch case value
val
)

Return an exception indicating that the current switch case was intended to be unreachable.

public static IllegalStateException

Returns:

the exception which may be immediately thrown
impossibleSwitchCase
(long
the switch case value
val
)

Return an exception indicating that the current switch case was intended to be unreachable.

public static IllegalStateException

Returns:

the exception which may be immediately thrown
unreachableCode
()

Return an exception indicating that the current code was intended to be unreachable.

public static UnsupportedOperationException

Returns:

the exception
unsupported
()

Return an exception explaining that the caller's method is not supported.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Assertback to summary
private Assert()

Method Detail

assertFalseback to summary
public static boolean assertFalse(boolean expr)

Assert that the given expression is always false.

Parameters
expr:boolean

the boolean expression

Returns:boolean

the boolean expression

Annotations
@SuppressWarnings:ConstantConditions
assertHoldsLockback to summary
public static <T> T assertHoldsLock(T monitor)

Assert that the given monitor is held by the current thread. Use a standard assertion failure message if it is not. Only runs if assert is enabled.

Parameters
<T>
the monitor's type
monitor:T

the monitor object

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the monitor is null
assertNotHoldsLockback to summary
public static <T> T assertNotHoldsLock(T monitor)

Assert that the given monitor is not held by the current thread. Use a standard assertion failure message if it is. Only runs if assert is enabled.

Parameters
<T>
the monitor's type
monitor:T

the monitor object

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the monitor is null
assertNotNullback to summary
public static <T> T assertNotNull(T value)

Assert that the value is not null. Use a standard assertion failure message if it is. Only runs if assert is enabled.

Parameters
<T>
the value type
value:T

the not-null value

Returns:T

the value that was passed in

Annotations
@NotNull
assertTrueback to summary
public static boolean assertTrue(boolean expr)

Assert that the given expression is always true.

Parameters
expr:boolean

the boolean expression

Returns:boolean

the boolean expression

Annotations
@SuppressWarnings:ConstantConditions
checkArrayBoundsback to summary
public static void checkArrayBounds(final Object[] array, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array.

Parameters
array:Object[]

the array to check

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkArrayBoundsback to summary
public static void checkArrayBounds(final byte[] array, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array.

Parameters
array:byte[]

the array to check

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkArrayBoundsback to summary
public static void checkArrayBounds(final char[] array, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array.

Parameters
array:char[]

the array to check

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkArrayBoundsback to summary
public static void checkArrayBounds(final int[] array, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array.

Parameters
array:int[]

the array to check

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkArrayBoundsback to summary
public static void checkArrayBounds(final long[] array, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array.

Parameters
array:long[]

the array to check

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkArrayBoundsback to summary
public static void checkArrayBounds(final int arrayLength, final int offs, final int len) throws ArrayIndexOutOfBoundsException

Check that the given offset and length fall completely within the bounds of the given array length.

Parameters
arrayLength:int

the array length to check against

offs:int

the array offset

len:int

the array length

Exceptions
ArrayIndexOutOfBoundsException:
if the range of the offset and length do not fall within the array bounds
checkMaximumParameterback to summary
public static void checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException

Check that the named parameter is less than or equal to max.

Parameters
name:String

the parameter name

max:int

the maximum value

actual:int

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is greater than the minimum value
checkMaximumParameterback to summary
public static void checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException

Check that the named parameter is less than or equal to max.

Parameters
name:String

the parameter name

max:long

the maximum value

actual:long

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is greater than the minimum value
checkMaximumParameterback to summary
public static void checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException

Check that the named parameter is less than or equal to max.

Parameters
name:String

the parameter name

max:float

the maximum value

actual:float

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is greater than the minimum value
checkMaximumParameterback to summary
public static void checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException

Check that the named parameter is less than or equal to max.

Parameters
name:String

the parameter name

max:double

the maximum value

actual:double

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is greater than the minimum value
checkMinimumParameterback to summary
public static void checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException

Check that the named parameter is greater than or equal to min.

Parameters
name:String

the parameter name

min:int

the minimum value

actual:int

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is less than the minimum value
checkMinimumParameterback to summary
public static void checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException

Check that the named parameter is greater than or equal to min.

Parameters
name:String

the parameter name

min:long

the minimum value

actual:long

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is less than the minimum value
checkMinimumParameterback to summary
public static void checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException

Check that the named parameter is greater than or equal to min.

Parameters
name:String

the parameter name

min:float

the minimum value

actual:float

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is less than the minimum value
checkMinimumParameterback to summary
public static void checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException

Check that the named parameter is greater than or equal to min.

Parameters
name:String

the parameter name

min:double

the minimum value

actual:double

the actual parameter value

Exceptions
IllegalArgumentException:
if the actual value is less than the minimum value
checkNotEmptyParamback to summary
public static String checkNotEmptyParam(String name, String value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:String

the parameter value

Returns:String

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static CharSequence checkNotEmptyParam(String name, CharSequence value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:CharSequence

the parameter value

Returns:CharSequence

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static <E, T extends Collection<E>> T checkNotEmptyParam(String name, T value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:T

the parameter value

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static <K, V, T extends Map<K, V>> T checkNotEmptyParam(String name, T value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:T

the parameter value

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static <T> T[] checkNotEmptyParam(String name, T[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:T[]

the parameter value

Returns:T[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static boolean[] checkNotEmptyParam(String name, boolean[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:boolean[]

the parameter value

Returns:boolean[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static byte[] checkNotEmptyParam(String name, byte[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:byte[]

the parameter value

Returns:byte[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static short[] checkNotEmptyParam(String name, short[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:short[]

the parameter value

Returns:short[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static int[] checkNotEmptyParam(String name, int[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:int[]

the parameter value

Returns:int[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static long[] checkNotEmptyParam(String name, long[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:long[]

the parameter value

Returns:long[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static float[] checkNotEmptyParam(String name, float[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:float[]

the parameter value

Returns:float[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotEmptyParamback to summary
public static double[] checkNotEmptyParam(String name, double[] value)

Check that the named parameter is not empty. Use a standard exception message if it is.

Parameters
name:String

the parameter name

value:double[]

the parameter value

Returns:double[]

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is empty
checkNotNullArrayParamback to summary
public static <T> T checkNotNullArrayParam(String name, int index, T value) throws IllegalArgumentException

Check that a value within the named array parameter is not null. Use a standard exception message if it is.

Parameters
<T>
the element value type
name:String

the parameter name

index:int

the array index

value:T

the array element value

Returns:T

the array element value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is null
checkNotNullParamback to summary
public static <T> T checkNotNullParam(String name, T value) throws IllegalArgumentException

Check that the named parameter is not null. Use a standard exception message if it is.

Parameters
<T>
the value type
name:String

the parameter name

value:T

the parameter value

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the value is null
checkNotNullParamCheckedback to summary
private static <T> void checkNotNullParamChecked(final String name, final T value)
checkNotNullParamWithNullPointerExceptionback to summary
public static <T> T checkNotNullParamWithNullPointerException(String name, T value) throws NullPointerException

Check that the named parameter is not null, using a NullPointerException as some specifications require. Use a standard exception message if it is.

Parameters
<T>
the value type
name:String

the parameter name

value:T

the parameter value

Returns:T

the value that was passed in

Annotations
@NotNull
Exceptions
NullPointerException:
if the value is null
impossibleSwitchCaseback to summary
public static IllegalStateException impossibleSwitchCase(Object obj)

Return an exception indicating that the current switch case was intended to be unreachable.

Parameters
obj:Object

the switch case value

Returns:IllegalStateException

the exception which may be immediately thrown

Annotations
@NotNull
impossibleSwitchCaseback to summary
public static IllegalStateException impossibleSwitchCase(int val)

Return an exception indicating that the current switch case was intended to be unreachable.

Parameters
val:int

the switch case value

Returns:IllegalStateException

the exception which may be immediately thrown

Annotations
@NotNull
impossibleSwitchCaseback to summary
public static IllegalStateException impossibleSwitchCase(long val)

Return an exception indicating that the current switch case was intended to be unreachable.

Parameters
val:long

the switch case value

Returns:IllegalStateException

the exception which may be immediately thrown

Annotations
@NotNull
unreachableCodeback to summary
public static IllegalStateException unreachableCode()

Return an exception indicating that the current code was intended to be unreachable.

Returns:IllegalStateException

the exception which may be immediately thrown

unsupportedback to summary
public static UnsupportedOperationException unsupported()

Return an exception explaining that the caller's method is not supported.

Returns:UnsupportedOperationException

the exception

Annotations
@NotNull