java.lang.Object
io.smallrye.common.constraint.Assert
A set of assertions and checks.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanassertFalse(boolean expr) Assert that the given expression is alwaysfalse.static <T> TassertHoldsLock(T monitor) Assert that the given monitor is held by the current thread.static <T> TassertNotHoldsLock(T monitor) Assert that the given monitor is not held by the current thread.static <T> TassertNotNull(T value) Assert that the value is notnull.static booleanassertTrue(boolean expr) Assert that the given expression is alwaystrue.static voidcheckArrayBounds(byte[] array, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array.static voidcheckArrayBounds(char[] array, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array.static voidcheckArrayBounds(int[] array, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array.static voidcheckArrayBounds(int arrayLength, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array length.static voidcheckArrayBounds(long[] array, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array.static voidcheckArrayBounds(Object[] array, int offs, int len) Check that the given offset and length fall completely within the bounds of the given array.static doublecheckMaximumParameter(String name, double max, double actual) Check that the named parameter is less than or equal tomax.static floatcheckMaximumParameter(String name, float max, float actual) Check that the named parameter is less than or equal tomax.static intcheckMaximumParameter(String name, int max, int actual) Check that the named parameter is less than or equal tomax.static longcheckMaximumParameter(String name, long max, long actual) Check that the named parameter is less than or equal tomax.static <T extends Comparable<T>>
TcheckMaximumParameter(String name, T max, T actual) Check that the named parameter is less than or equal tomax.static intcheckMaximumParameterUnsigned(String name, int max, int actual) Check that the named parameter is less than or equal tomaxusing unsigned comparison.static longcheckMaximumParameterUnsigned(String name, long max, long actual) Check that the named parameter is less than or equal tomaxusing unsigned comparison.static doublecheckMinimumParameter(String name, double min, double actual) Check that the named parameter is greater than or equal tomin.static floatcheckMinimumParameter(String name, float min, float actual) Check that the named parameter is greater than or equal tomin.static intcheckMinimumParameter(String name, int min, int actual) Check that the named parameter is greater than or equal tomin.static longcheckMinimumParameter(String name, long min, long actual) Check that the named parameter is greater than or equal tomin.static <T extends Comparable<T>>
TcheckMinimumParameter(String name, T min, T actual) Check that the named parameter is greater than or equal tomin.static intcheckMinimumParameterUnsigned(String name, int min, int actual) Check that the named parameter is greater than or equal tominusing unsigned comparison.static longcheckMinimumParameterUnsigned(String name, long min, long actual) Check that the named parameter is greater than or equal tominusing unsigned comparison.static boolean[]checkNotEmptyParam(String name, boolean[] value) Check that the named parameter is not empty.static byte[]checkNotEmptyParam(String name, byte[] value) Check that the named parameter is not empty.static double[]checkNotEmptyParam(String name, double[] value) Check that the named parameter is not empty.static float[]checkNotEmptyParam(String name, float[] value) Check that the named parameter is not empty.static int[]checkNotEmptyParam(String name, int[] value) Check that the named parameter is not empty.static long[]checkNotEmptyParam(String name, long[] value) Check that the named parameter is not empty.static short[]checkNotEmptyParam(String name, short[] value) Check that the named parameter is not empty.static CharSequencecheckNotEmptyParam(String name, CharSequence value) Check that the named parameter is not empty.static StringcheckNotEmptyParam(String name, String value) Check that the named parameter is not empty.static <E,T extends Collection<E>>
TcheckNotEmptyParam(String name, T value) Check that the named parameter is not empty.static <T> T[]checkNotEmptyParam(String name, T[] value) Check that the named parameter is not empty.static <T> TcheckNotNullArrayParam(String name, int index, T value) Check that a value within the named array parameter is notnull.static <T> TcheckNotNullParam(String name, T value) Check that the named parameter is notnull.static intcheckPow2Parameter(String name, int actual) Check that the named parameter is zero or a power of two (unsigned).static longcheckPow2Parameter(String name, long actual) Check that the named parameter is zero or a power of two (unsigned).static IllegalStateExceptionimpossibleSwitchCase(char val) Return an exception indicating that the current switch case was intended to be unreachable.static IllegalStateExceptionimpossibleSwitchCase(int val) Return an exception indicating that the current switch case was intended to be unreachable.static IllegalStateExceptionimpossibleSwitchCase(long val) Return an exception indicating that the current switch case was intended to be unreachable.static IllegalStateExceptionReturn an exception indicating that the current switch case was intended to be unreachable.static IllegalStateExceptionReturn an exception indicating that the current code was intended to be unreachable.Return an exception explaining that the caller's method is not supported.
-
Method Details
-
checkNotNullParam
@NotNull public static <T> T checkNotNullParam(String name, T value) throws IllegalArgumentException Check that the named parameter is notnull. Use a standard exception message if it is.- Type Parameters:
T- the value type- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value isnull
-
checkNotNullArrayParam
@NotNull public static <T> T checkNotNullArrayParam(String name, int index, T value) throws IllegalArgumentException Check that a value within the named array parameter is notnull. Use a standard exception message if it is.- Type Parameters:
T- the element value type- Parameters:
name- the parameter nameindex- the array indexvalue- the array element value- Returns:
- the array element value that was passed in
- Throws:
IllegalArgumentException- if the value isnull
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Type Parameters:
E- the element typeT- the collection type- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Type Parameters:
K- the map key typeV- the map value typeT- the map type- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Type Parameters:
T- the element type- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkNotEmptyParam
Check that the named parameter is not empty. Use a standard exception message if it is.- Parameters:
name- the parameter namevalue- the parameter value- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the value is empty
-
checkMinimumParameter
public static <T extends Comparable<T>> T checkMinimumParameter(String name, T min, T actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tomin.- Type Parameters:
T- the parameter type- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameter
public static int checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tomin.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameterUnsigned
public static int checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tominusing unsigned comparison.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameter
public static long checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tomin.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameterUnsigned
public static long checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tominusing unsigned comparison.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameter
public static float checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tomin.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMinimumParameter
public static double checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException Check that the named parameter is greater than or equal tomin.- Parameters:
name- the parameter namemin- the minimum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is less than the minimum value
-
checkMaximumParameter
public static <T extends Comparable<T>> T checkMaximumParameter(String name, T max, T actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomax.- Type Parameters:
T- the parameter type- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameter
public static int checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomax.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameterUnsigned
public static int checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomaxusing unsigned comparison.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameter
public static long checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomax.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameterUnsigned
public static long checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomaxusing unsigned comparison.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameter
public static float checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomax.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkMaximumParameter
public static double checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException Check that the named parameter is less than or equal tomax.- Parameters:
name- the parameter namemax- the maximum valueactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is greater than the maximum value
-
checkPow2Parameter
Check that the named parameter is zero or a power of two (unsigned). For a signed check, or to eliminate zero values, usecheckMinimumParameter(String, int, int).- Parameters:
name- the parameter nameactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is not zero or a power of two
-
checkPow2Parameter
Check that the named parameter is zero or a power of two (unsigned). For a signed check, or to eliminate zero values, usecheckMinimumParameter(String, long, long).- Parameters:
name- the parameter nameactual- the actual parameter value- Returns:
- the given actual value
- Throws:
IllegalArgumentException- if the actual value is not zero or a power of two
-
checkArrayBounds
public static void checkArrayBounds(Object[] array, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array.- Parameters:
array- the array to checkoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
checkArrayBounds
public static void checkArrayBounds(byte[] array, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array.- Parameters:
array- the array to checkoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
checkArrayBounds
public static void checkArrayBounds(char[] array, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array.- Parameters:
array- the array to checkoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
checkArrayBounds
public static void checkArrayBounds(int[] array, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array.- Parameters:
array- the array to checkoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
checkArrayBounds
public static void checkArrayBounds(long[] array, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array.- Parameters:
array- the array to checkoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
checkArrayBounds
public static void checkArrayBounds(int arrayLength, int offs, int len) throws ArrayIndexOutOfBoundsException Check that the given offset and length fall completely within the bounds of the given array length.- Parameters:
arrayLength- the array length to check againstoffs- the array offsetlen- the array length- Throws:
ArrayIndexOutOfBoundsException- if the range of the offset and length do not fall within the array bounds
-
assertNotNull
Assert that the value is notnull. Use a standard assertion failure message if it is. Only runs ifassertis enabled.- Type Parameters:
T- the value type- Parameters:
value- the not-nullvalue- Returns:
- the value that was passed in
-
assertHoldsLock
Assert that the given monitor is held by the current thread. Use a standard assertion failure message if it is not. Only runs ifassertis enabled.- Type Parameters:
T- the monitor's type- Parameters:
monitor- the monitor object- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the monitor isnull
-
assertNotHoldsLock
Assert that the given monitor is not held by the current thread. Use a standard assertion failure message if it is. Only runs ifassertis enabled.- Type Parameters:
T- the monitor's type- Parameters:
monitor- the monitor object- Returns:
- the value that was passed in
- Throws:
IllegalArgumentException- if the monitor isnull
-
assertTrue
public static boolean assertTrue(boolean expr) Assert that the given expression is alwaystrue.- Parameters:
expr- the boolean expression- Returns:
- the boolean expression
-
assertFalse
public static boolean assertFalse(boolean expr) Assert that the given expression is alwaysfalse.- Parameters:
expr- the boolean expression- Returns:
- the boolean expression
-
unreachableCode
Return an exception indicating that the current code was intended to be unreachable.- Returns:
- the exception which may be immediately thrown
-
impossibleSwitchCase
Return an exception indicating that the current switch case was intended to be unreachable.- Parameters:
obj- the switch case value- Returns:
- the exception which may be immediately thrown
-
impossibleSwitchCase
Return an exception indicating that the current switch case was intended to be unreachable.- Parameters:
val- the switch case value- Returns:
- the exception which may be immediately thrown
-
impossibleSwitchCase
Return an exception indicating that the current switch case was intended to be unreachable.- Parameters:
val- the switch case value- Returns:
- the exception which may be immediately thrown
-
impossibleSwitchCase
Return an exception indicating that the current switch case was intended to be unreachable.- Parameters:
val- the switch case value- Returns:
- the exception which may be immediately thrown
-
unsupported
Return an exception explaining that the caller's method is not supported.- Returns:
- the exception
-