Package edu.wisc.ssec.mcidasv.util
Class Contract
java.lang.Object
edu.wisc.ssec.mcidasv.util.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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkArg
(boolean expression) Ensures the "truth" of an expression involving parameters passed to the calling method.static void
Ensures the "truth" of an expression involving parameters passed to the calling method.static void
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> static <T> T
notNull
(T object) Deprecated.static <T> T
Deprecated.static <T> T
Ensures that a parameter passed to the calling method is notnull
.
-
Constructor Details
-
Contract
private Contract()
-
-
Method Details
-
notNull
Deprecated.Ensures that a parameter passed to the calling method is notnull
.- Type Parameters:
T
- Type of object to test.- Parameters:
object
- Object to test.- Returns:
object
, if it is notnull
.- Throws:
NullPointerException
- ifobject
isnull
.
-
notNull
Deprecated.Ensures that a parameter passed to the calling method is notnull
.- Type Parameters:
T
- Type of object to test.- Parameters:
object
- Object to test.message
- Exception message to use ifobject
isnull
.- Returns:
object
, if it is notnull
.- Throws:
NullPointerException
- ifobject
isnull
.
-
notNull
Ensures that a parameter passed to the calling method is notnull
.- Type Parameters:
T
- Type of object to test.- Parameters:
object
- Object to test.format
- Template used to create an exception ifobject
isnull
. UsesString.format(String, Object...)
.values
- Values to use withinformat
.- Returns:
object
, if it is notnull
.- Throws:
NullPointerException
- ifobject
isnull
.
-
noNulls
-
checkArg
Ensures the "truth" of an expression involving parameters passed to the calling method.- Parameters:
expression
- A boolean expression to test.- Throws:
IllegalArgumentException
- ifexpression
isfalse
.
-
checkArg
Ensures the "truth" of an expression involving parameters passed to the calling method.- Parameters:
expression
- A boolean expression to test.message
- Exception message to use ifexpression
isfalse
.- Throws:
IllegalArgumentException
- ifexpression
isfalse
.
-
checkArg
Ensures the "truth" of an expression involving parameters passed to the calling method.- Parameters:
expression
- A boolean expression to test.format
- Template used to create an exception ifexpression
isfalse
. UsesString.format(String, Object...)
.values
- Values to use withinformat
.- Throws:
IllegalArgumentException
- ifexpression
isfalse
.
-
instanceOf
-
instanceOf
-
isInstanceOf
-