edu.wisc.ssec.mcidasv.util
Class Contract

java.lang.Object
  extended by edu.wisc.ssec.mcidasv.util.Contract

public final class Contract
extends Object

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
<T> List<T>
noNulls(String message, T... objects)
           
static
<T> T
notNull(T object)
          Ensures that a parameter passed to the calling method is not null.
static
<T> T
notNull(T object, Object message)
          Ensures that a parameter passed to the calling method is not null.
static
<T> T
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

Contract

private Contract()
Method Detail

notNull

public static <T> T notNull(T object)
Ensures that a parameter passed to the calling method is not null.

Parameters:
object - Object to test.
Returns:
object, if it is not null.
Throws:
NullPointerException - if object is null.

notNull

public static <T> T notNull(T object,
                            Object message)
Ensures that a parameter passed to the calling method is not null.

Parameters:
object - Object to test.
message - Exception message to use if object is null.
Returns:
object, if it is not null.
Throws:
NullPointerException - if object is null.

notNull

public static <T> T notNull(T object,
                            String format,
                            Object... values)
Ensures that a parameter passed to the calling method is not null.

Parameters:
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.
Returns:
object, if it is not null.
Throws:
NullPointerException - if object is null.

noNulls

public static <T> List<T> noNulls(String message,
                                  T... objects)

checkArg

public static void checkArg(boolean expression)
Ensures the "truth" of an expression involving parameters passed to the calling method.

Parameters:
expression - A boolean expression to test.
Throws:
IllegalArgumentException - if expression is false.

checkArg

public static void checkArg(boolean expression,
                            Object message)
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 if expression is false.
Throws:
IllegalArgumentException - if expression is false.

checkArg

public static void checkArg(boolean expression,
                            String format,
                            Object... values)
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 if expression is false. Uses String.format(String, Object...).
values - Values to use within format.
Throws:
IllegalArgumentException - if expression is false.

instanceOf

public static void instanceOf(Object object,
                              Class<?> clazz)

instanceOf

public static void instanceOf(Object message,
                              Object object,
                              Class<?> clazz)

isInstanceOf

public static boolean isInstanceOf(Object object,
                                   Class<?> clazz)