public final class Contract extends Object
if (str == null) {
throw new NullPointerException("null is bad");
}
can be replaced with
notNull(str, "null is bad");Remember that these methods are used to signal an error in the calling method!
| Modifier | Constructor and Description |
|---|---|
private |
Contract() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArg(boolean expression)
Ensures the "truth" of an expression involving parameters
passed to the calling method.
|
static void |
checkArg(boolean expression,
Object message)
Ensures the "truth" of an expression involving parameters
passed to the calling method.
|
static void |
checkArg(boolean expression,
String format,
Object... values)
Ensures the "truth" of an expression involving parameters
passed to the calling method.
|
static void |
instanceOf(Object object,
Class<?> clazz) |
static void |
instanceOf(Object message,
Object object,
Class<?> clazz) |
static boolean |
isInstanceOf(Object object,
Class<?> clazz) |
static <T> List<T> |
noNulls(String message,
T... objects) |
static <T> T |
notNull(T object)
Deprecated.
|
static <T> T |
notNull(T object,
Object message)
Deprecated.
|
static <T> T |
notNull(T object,
String format,
Object... values)
Ensures that a parameter passed to the calling method is not
null. |
private Contract()
@Deprecated public static <T> T notNull(T object)
null.object - Object to test.object, if it is not null.NullPointerException - if object is null.@Deprecated public static <T> T notNull(T object, Object message)
null.object - Object to test.message - Exception message to use if object is
null.object, if it is not null.NullPointerException - if object is null.public static <T> T notNull(T object, String format, Object... values)
null.object - Object to test.format - Template used to create an exception if object is
null. Uses String.format(String, Object...).values - Values to use within format.object, if it is not null.NullPointerException - if object is null.public static void checkArg(boolean expression)
expression - A boolean expression to test.IllegalArgumentException - if expression is false.public static void checkArg(boolean expression, Object message)
expression - A boolean expression to test.message - Exception message to use if expression is
false.IllegalArgumentException - if expression is false.public static void checkArg(boolean expression, String format, Object... values)
expression - A boolean expression to test.format - Template used to create an exception if expression is
false. Uses String.format(String, Object...).values - Values to use within format.IllegalArgumentException - if expression is false.public static void instanceOf(Object object, Class<?> clazz)
public static void instanceOf(Object message, Object object, Class<?> clazz)
public static boolean isInstanceOf(Object object, Class<?> clazz)