public final class Assertions extends Object
Design by contract assertions.
This class is not part of the public API and may be removed or changed at any time.
Modifier and Type | Method | Description |
---|---|---|
static <T> T |
convertToType(Class<T> clazz,
Object value,
String errorMessage) |
Cast an object to the given class and return it, or throw IllegalArgumentException if it's not assignable to that class.
|
static void |
isTrue(String name,
boolean condition) |
Throw IllegalStateException if the condition if false.
|
static void |
isTrueArgument(String name,
boolean condition) |
Throw IllegalArgumentException if the condition if false.
|
static <T> T |
notNull(String name,
T value) |
Throw IllegalArgumentException if the value is null.
|
public static <T> T notNull(String name, T value)
T
- the value typename
- the parameter namevalue
- the value that should not be nullIllegalArgumentException
- if value is nullpublic static void isTrue(String name, boolean condition)
name
- the name of the state that is being checkedcondition
- the condition about the parameter to checkIllegalStateException
- if the condition is falsepublic static void isTrueArgument(String name, boolean condition)
name
- the name of the state that is being checkedcondition
- the condition about the parameter to checkIllegalArgumentException
- if the condition is falsepublic static <T> T convertToType(Class<T> clazz, Object value, String errorMessage)
T
- the Class typeclazz
- the class to cast tovalue
- the value to casterrorMessage
- the error message to include in the exceptionIllegalArgumentException
- if value is not assignable to clazz