|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.wisc.ssec.mcidasv.util.Contract
public final class Contract
This is a "convenience" class--use these methods to reduce boilerplate parameter verification. For example:
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!
| Constructor Summary | |
|---|---|
private |
Contract()
|
| Method Summary | ||
|---|---|---|
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
|
noNulls(String message,
T... objects)
|
|
static
|
notNull(T object)
Ensures that a parameter passed to the calling method is not null. |
|
static
|
notNull(T object,
Object message)
Ensures that a parameter passed to the calling method is not null. |
|
static
|
notNull(T object,
String format,
Object... values)
Ensures that a parameter passed to the calling method is not null. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
private Contract()
| Method Detail |
|---|
public static <T> T notNull(T object)
null.
object - Object to test.
object, if it is not null.
NullPointerException - if object is null.
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 <T> List<T> noNulls(String message,
T... objects)
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)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||