org.jboss.dna.common.util
Class ArgCheck

java.lang.Object
  extended by org.jboss.dna.common.util.ArgCheck

public final class ArgCheck
extends java.lang.Object

Utility class that checks arguments to methods. This class is to be used only in API methods, where failure to supply correct arguments should result in a useful error message. In all cases, use the assert statement.


Method Summary
static void contains(java.util.Collection argument, java.lang.Object value, java.lang.String name)
          Check that the collection contains the value
static void containsKey(java.util.Map argument, java.lang.Object key, java.lang.String name)
          Check that the map contains the key
static void containsNoNulls(java.util.Collection argument, java.lang.String name)
          Check that the collection is not null and contains no nulls
static void containsNoNulls(java.lang.Object[] argument, java.lang.String name)
          Check that the array is not null and contains no nulls
static
<C> C
getInstanceOf(java.lang.Object argument, java.lang.Class<C> expectedClass, java.lang.String name)
          Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class
static
<T> T
getNotNull(T argument, java.lang.String name)
          Returns the specified argument if it is not null.
static
<T> void
isEquals(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
          Asserts that the specified first object is equal to the specified second object.
static void isInstanceOf(java.lang.Object argument, java.lang.Class expectedClass, java.lang.String name)
          Check that the object is an instance of the specified Class
static void isNegative(double argument, java.lang.String name)
          Check that the argument is negative (<0).
static void isNegative(int argument, java.lang.String name)
          Check that the argument is negative (<0).
static void isNegative(long argument, java.lang.String name)
          Check that the argument is negative (<0).
static void isNonNegative(double argument, java.lang.String name)
          Check that the argument is non-negative (>=0).
static void isNonNegative(int argument, java.lang.String name)
          Check that the argument is non-negative (>=0).
static void isNonNegative(long argument, java.lang.String name)
          Check that the argument is non-negative (>=0).
static void isNonPositive(double argument, java.lang.String name)
          Check that the argument is non-positive (<=0).
static void isNonPositive(int argument, java.lang.String name)
          Check that the argument is non-positive (<=0).
static void isNonPositive(long argument, java.lang.String name)
          Check that the argument is non-positive (<=0).
static void isNotEmpty(java.util.Collection argument, java.lang.String name)
          Check that the collection is not empty
static void isNotEmpty(java.util.Iterator argument, java.lang.String name)
          Checks that the iterator is not empty, and throws an exception if it is.
static void isNotEmpty(java.util.Map argument, java.lang.String name)
          Check that the map is not empty
static void isNotEmpty(java.lang.Object[] argument, java.lang.String name)
          Check that the array is not empty
static void isNotEmpty(java.lang.String argument, java.lang.String name)
          Check that the string is not empty, is not null, and does not contain only whitespace.
static
<T> void
isNotEquals(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
          Asserts that the specified first object is not equal to the specified second object.
static void isNotNan(double argument, java.lang.String name)
          Check that the argument is not NaN.
static void isNotNull(java.lang.Object argument, java.lang.String name)
          Check that the specified argument is non-null
static
<T> void
isNotSame(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
          Asserts that the specified first object is not the same as (==) the specified second object.
static void isNotZeroLength(java.lang.String argument, java.lang.String name)
          Check that the string is non-null and has length > 0
static void isNull(java.lang.Object argument, java.lang.String name)
          Check that the argument is null
static void isPositive(double argument, java.lang.String name)
          Check that the argument is positive (>0).
static void isPositive(int argument, java.lang.String name)
          Check that the argument is positive (>0).
static void isPositive(long argument, java.lang.String name)
          Check that the argument is positive (>0).
static
<T> void
isSame(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
          Asserts that the specified first object is the same as (==) the specified second object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isNonNegative

public static void isNonNegative(int argument,
                                 java.lang.String name)
Check that the argument is non-negative (>=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is negative (<0)

isNonPositive

public static void isNonPositive(int argument,
                                 java.lang.String name)
Check that the argument is non-positive (<=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is positive (>0)

isNegative

public static void isNegative(int argument,
                              java.lang.String name)
Check that the argument is negative (<0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-negative (>=0)

isPositive

public static void isPositive(int argument,
                              java.lang.String name)
Check that the argument is positive (>0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-positive (<=0)

isNonNegative

public static void isNonNegative(long argument,
                                 java.lang.String name)
Check that the argument is non-negative (>=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is negative (<0)

isNonPositive

public static void isNonPositive(long argument,
                                 java.lang.String name)
Check that the argument is non-positive (<=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is positive (>0)

isNegative

public static void isNegative(long argument,
                              java.lang.String name)
Check that the argument is negative (<0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-negative (>=0)

isPositive

public static void isPositive(long argument,
                              java.lang.String name)
Check that the argument is positive (>0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-positive (<=0)

isNonNegative

public static void isNonNegative(double argument,
                                 java.lang.String name)
Check that the argument is non-negative (>=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is negative (<0)

isNonPositive

public static void isNonPositive(double argument,
                                 java.lang.String name)
Check that the argument is non-positive (<=0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is positive (>0)

isNegative

public static void isNegative(double argument,
                              java.lang.String name)
Check that the argument is negative (<0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-negative (>=0)

isPositive

public static void isPositive(double argument,
                              java.lang.String name)
Check that the argument is positive (>0).

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is non-positive (<=0)

isNotNan

public static void isNotNan(double argument,
                            java.lang.String name)
Check that the argument is not NaN.

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is NaN

isNotZeroLength

public static void isNotZeroLength(java.lang.String argument,
                                   java.lang.String name)
Check that the string is non-null and has length > 0

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If value is null or length == 0

isNotEmpty

public static void isNotEmpty(java.lang.String argument,
                              java.lang.String name)
Check that the string is not empty, is not null, and does not contain only whitespace.

Parameters:
argument - String
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If string is null or empty

isNotNull

public static void isNotNull(java.lang.Object argument,
                             java.lang.String name)
Check that the specified argument is non-null

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If argument is null

getNotNull

public static <T> T getNotNull(T argument,
                               java.lang.String name)
Returns the specified argument if it is not null.

Type Parameters:
T -
Parameters:
argument - The argument
name - The name of the argument
Returns:
The argument
Throws:
java.lang.IllegalArgumentException - If argument is null

isNull

public static void isNull(java.lang.Object argument,
                          java.lang.String name)
Check that the argument is null

Parameters:
argument - The argument
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If value is non-null

isInstanceOf

public static void isInstanceOf(java.lang.Object argument,
                                java.lang.Class expectedClass,
                                java.lang.String name)
Check that the object is an instance of the specified Class

Parameters:
argument - Value
expectedClass - Class
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If value is null

getInstanceOf

public static <C> C getInstanceOf(java.lang.Object argument,
                                  java.lang.Class<C> expectedClass,
                                  java.lang.String name)
Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class

Type Parameters:
C -
Parameters:
argument - Value
expectedClass - Class
name - The name of the argument
Returns:
value cast to the specified Class
Throws:
java.lang.IllegalArgumentException - If value is not an instance of theClass.

isSame

public static <T> void isSame(T argument,
                              java.lang.String argumentName,
                              T object,
                              java.lang.String objectName)
Asserts that the specified first object is the same as (==) the specified second object.

Type Parameters:
T -
Parameters:
argument - The argument to assert as the same as object.
argumentName - The name that will be used within the exception message for the argument should an exception be thrown
object - The object to assert as the same as argument.
objectName - The name that will be used within the exception message for object should an exception be thrown; if null and object is not null, object.toString() will be used.
Throws:
java.lang.IllegalArgumentException - If the specified objects are not the same.

isNotSame

public static <T> void isNotSame(T argument,
                                 java.lang.String argumentName,
                                 T object,
                                 java.lang.String objectName)
Asserts that the specified first object is not the same as (==) the specified second object.

Type Parameters:
T -
Parameters:
argument - The argument to assert as not the same as object.
argumentName - The name that will be used within the exception message for the argument should an exception be thrown
object - The object to assert as not the same as argument.
objectName - The name that will be used within the exception message for object should an exception be thrown; if null and object is not null, object.toString() will be used.
Throws:
java.lang.IllegalArgumentException - If the specified objects are the same.

isEquals

public static <T> void isEquals(T argument,
                                java.lang.String argumentName,
                                T object,
                                java.lang.String objectName)
Asserts that the specified first object is equal to the specified second object.

Type Parameters:
T -
Parameters:
argument - The argument to assert equal to object.
argumentName - The name that will be used within the exception message for the argument should an exception be thrown
object - The object to assert as equal to argument.
objectName - The name that will be used within the exception message for object should an exception be thrown; if null and object is not null, object.toString() will be used.
Throws:
java.lang.IllegalArgumentException - If the specified objects are not equal.

isNotEquals

public static <T> void isNotEquals(T argument,
                                   java.lang.String argumentName,
                                   T object,
                                   java.lang.String objectName)
Asserts that the specified first object is not equal to the specified second object.

Type Parameters:
T -
Parameters:
argument - The argument to assert equal to object.
argumentName - The name that will be used within the exception message for the argument should an exception be thrown
object - The object to assert as equal to argument.
objectName - The name that will be used within the exception message for object should an exception be thrown; if null and object is not null, object.toString() will be used.
Throws:
java.lang.IllegalArgumentException - If the specified objects are equals.

isNotEmpty

public static void isNotEmpty(java.util.Iterator argument,
                              java.lang.String name)
Checks that the iterator is not empty, and throws an exception if it is.

Parameters:
argument - the iterator to check
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If iterator is empty (i.e., iterator.hasNext() returns false)

isNotEmpty

public static void isNotEmpty(java.util.Collection argument,
                              java.lang.String name)
Check that the collection is not empty

Parameters:
argument - Collection
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If collection is null or empty

isNotEmpty

public static void isNotEmpty(java.util.Map argument,
                              java.lang.String name)
Check that the map is not empty

Parameters:
argument - Map
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If map is null or empty

isNotEmpty

public static void isNotEmpty(java.lang.Object[] argument,
                              java.lang.String name)
Check that the array is not empty

Parameters:
argument - Array
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If array is null or empty

contains

public static void contains(java.util.Collection argument,
                            java.lang.Object value,
                            java.lang.String name)
Check that the collection contains the value

Parameters:
argument - Collection to check
value - Value to check for, may be null
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If collection is null or doesn't contain value

containsKey

public static void containsKey(java.util.Map argument,
                               java.lang.Object key,
                               java.lang.String name)
Check that the map contains the key

Parameters:
argument - Map to check
key - Key to check for, may be null
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If map is null or doesn't contain key

containsNoNulls

public static void containsNoNulls(java.util.Collection argument,
                                   java.lang.String name)
Check that the collection is not null and contains no nulls

Parameters:
argument - Array
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If array is null or has null values

containsNoNulls

public static void containsNoNulls(java.lang.Object[] argument,
                                   java.lang.String name)
Check that the array is not null and contains no nulls

Parameters:
argument - Array
name - The name of the argument
Throws:
java.lang.IllegalArgumentException - If array is null or has null values


Copyright © 2008. All Rights Reserved.