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 voidcheckArg(boolean expression) Ensures the "truth" of an expression involving parameters passed to the calling method.static voidEnsures the "truth" of an expression involving parameters passed to the calling method.static voidEnsures the "truth" of an expression involving parameters passed to the calling method.static voidinstanceOf(Object object, Class<?> clazz) static voidinstanceOf(Object message, Object object, Class<?> clazz) static booleanisInstanceOf(Object object, Class<?> clazz) static <T> List<T> static <T> TnotNull(T object) Deprecated.static <T> TDeprecated.static <T> TEnsures 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- ifobjectisnull.
-
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 ifobjectisnull.- Returns:
object, if it is notnull.- Throws:
NullPointerException- ifobjectisnull.
-
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 ifobjectisnull. UsesString.format(String, Object...).values- Values to use withinformat.- Returns:
object, if it is notnull.- Throws:
NullPointerException- ifobjectisnull.
-
noNulls
-
checkArg
Ensures the "truth" of an expression involving parameters passed to the calling method.- Parameters:
expression- A boolean expression to test.- Throws:
IllegalArgumentException- ifexpressionisfalse.
-
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 ifexpressionisfalse.- Throws:
IllegalArgumentException- ifexpressionisfalse.
-
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 ifexpressionisfalse. UsesString.format(String, Object...).values- Values to use withinformat.- Throws:
IllegalArgumentException- ifexpressionisfalse.
-
instanceOf
-
instanceOf
-
isInstanceOf
-