public final class Assertions
extends java.lang.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 and Description |
---|---|
static <T> T |
convertToType(java.lang.Class<T> clazz,
java.lang.Object value,
java.lang.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(java.lang.String name,
boolean condition)
Throw IllegalStateException if the condition if false.
|
static void |
isTrueArgument(java.lang.String name,
boolean condition)
Throw IllegalArgumentException if the condition if false.
|
static <T> T |
notNull(java.lang.String name,
T value)
Throw IllegalArgumentException if the value is null.
|
public static <T> T notNull(java.lang.String name, T value)
T
- the value typename
- the parameter namevalue
- the value that should not be nulljava.lang.IllegalArgumentException
- if value is nullpublic static void isTrue(java.lang.String name, boolean condition)
name
- the name of the state that is being checkedcondition
- the condition about the parameter to checkjava.lang.IllegalStateException
- if the condition is falsepublic static void isTrueArgument(java.lang.String name, boolean condition)
name
- the name of the state that is being checkedcondition
- the condition about the parameter to checkjava.lang.IllegalArgumentException
- if the condition is falsepublic static <T> T convertToType(java.lang.Class<T> clazz, java.lang.Object value, java.lang.String errorMessage)
T
- the Class typeclazz
- the class to cast tovalue
- the value to casterrorMessage
- the error message to include in the exceptionjava.lang.IllegalArgumentException
- if value is not assignable to clazz