public final class Require extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
condition(boolean condition,
String message,
Object... format)
Asserts that the given condition holds
true. |
static <T> T |
nonNull(T obj)
Asserts that the given object is non null.
|
static <T> T |
nonNull(T obj,
String paramName)
Asserts that the given object is non null.
|
static <T> T |
nonNullResult(T result,
String call)
Asserts that a method call yielded a non-null result.
|
static <T extends Exception> |
state(boolean state,
Function<String,T> excpetionCtor,
String message,
Object format)
Asserts that the given condition holds
true and throws a
custom exception if not. |
static void |
state(boolean state,
String message,
Object... format)
Asserts that the given condition holds
true. |
public static <T> T nonNull(T obj,
String paramName)
T - Type of the object to test.obj - The object to test.paramName - The name of the parameter (used for exception message).IllegalArgumentException - If obj is null.public static <T> T nonNull(T obj)
T - Type of the object to test.obj - The object to test.public static void condition(boolean condition,
String message,
Object... format)
true.condition - The condition to check.message - String for the exception message.format - Formatting parameters for the exception message.IllegalArgumentException - If condition is
false.public static void state(boolean state,
String message,
Object... format)
true.state - The condition to check.message - String for the exception message.format - Formatting parameters for the exception message.IllegalStateException - If condition is false.public static <T extends Exception> void state(boolean state, Function<String,T> excpetionCtor, String message, Object format) throws T extends Exception
true and throws a
custom exception if not.state - The condition to check.excpetionCtor - Constructor of the exception to throw.message - String for exception message.format - Formatting parameters for the exception message.T - If condition is false.T extends Exceptionpublic static <T> T nonNullResult(T result,
String call)
T - Type of the object to test.result - The result object.call - A String description of the call, like "Object.calledMethod".IllegalStateException - If result is null.Copyright © 2014–2015. All rights reserved.