com.metamatrix.core.util
Class ArgCheck

java.lang.Object
  extended by com.metamatrix.core.util.ArgCheck

public class ArgCheck
extends java.lang.Object

This class contains a set of static utility methods for checking method arguments. It contains many of the common checks that are done, such as checking that an Object is non-null, checking the range of a value, etc. All of these methods throw #java.lang.IllegalArgumentException.


Method Summary
static void contains(java.util.Collection collection, java.lang.Object value)
          Check that the collection contains the value
static void contains(java.util.Collection collection, java.lang.Object value, java.lang.String message)
          Check that the collection contains the value
static void containsKey(java.util.Map map, java.lang.Object key)
          Check that the map contains the key
static void containsKey(java.util.Map map, java.lang.Object key, java.lang.String message)
          Check that the map contains the key
static void isInstanceOf(java.lang.Class theClass, java.lang.Object value)
          Check that the object is an instance of the specified Class
static void isInstanceOf(java.lang.Class theClass, java.lang.Object value, java.lang.String message)
          Check that the object is an instance of the specified Class
static void isNegative(int value)
          Check that the value is negative (<0).
static void isNegative(int value, java.lang.String message)
          Check that the value is negative (<0).
static void isNegative(long value)
          Check that the value is negative (<0).
static void isNegative(long value, java.lang.String message)
          Check that the value is negative (<0).
static void isNonNegative(int value)
          Check that the value is non-negative (>=0).
static void isNonNegative(int value, java.lang.String message)
          Check that the value is non-negative (>=0).
static void isNonNegative(long value)
          Check that the value is non-negative (>=0).
static void isNonNegative(long value, java.lang.String message)
          Check that the value is non-negative (>=0).
static void isNonPositive(int value)
          Check that the value is non-positive (<=0).
static void isNonPositive(int value, java.lang.String message)
          Check that the value is non-positive (<=0).
static void isNonPositive(long value)
          Check that the value is non-positive (<=0).
static void isNonPositive(long value, java.lang.String message)
          Check that the value is non-positive (<=0).
static void isNotEmpty(java.util.Collection collection)
          Check that the collection is not empty
static void isNotEmpty(java.util.Collection collection, java.lang.String message)
          Check that the collection is not empty
static void isNotEmpty(java.util.Map map)
          Check that the map is not empty
static void isNotEmpty(java.util.Map map, java.lang.String message)
          Check that the map is not empty
static void isNotEmpty(java.lang.Object[] array)
          Check that the array is not empty
static void isNotEmpty(java.lang.Object[] array, java.lang.String message)
          Check that the array is not empty
static void isNotEmpty(java.lang.String string)
          Check that the string is not empty
static void isNotEmpty(java.lang.String string, java.lang.String message)
          Check that the string is not empty
static void isNotNull(java.lang.Object value)
          Check that the object is non-null
static void isNotNull(java.lang.Object value, java.lang.String message)
          Check that the object is non-null
static void isNotSame(java.lang.Object firstObject, java.lang.String firstName, java.lang.Object secondObject, java.lang.String secondName)
          Asserts that the specified first object is not the same as (==) the specified second object.
static void isNotZeroLength(java.lang.String value)
          Check that the string is non-null and has length > 0
static void isNotZeroLength(java.lang.String value, java.lang.String message)
          Check that the string is non-null and has length > 0
static void isNull(java.lang.Object value)
          Check that the object is null
static void isNull(java.lang.Object value, java.lang.String message)
          Check that the object is null
static void isPositive(int value)
          Check that the value is positive (>0).
static void isPositive(int value, java.lang.String message)
          Check that the value is positive (>0).
static void isPositive(long value)
          Check that the value is positive (>0).
static void isPositive(long value, java.lang.String message)
          Check that the value is positive (>0).
static void isTrue(boolean condition, java.lang.String message)
          Check that the boolean condition is true; throw an IllegalArgumentException if not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isTrue

public static final void isTrue(boolean condition,
                                java.lang.String message)
Check that the boolean condition is true; throw an IllegalArgumentException if not.

Parameters:
condition - The boolean condition to check
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - if condition is false

isNonNegative

public static final void isNonNegative(int value)
Check that the value is non-negative (>=0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is negative (<0)

isNonNegative

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

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is negative (<0)

isNonPositive

public static final void isNonPositive(int value)
Check that the value is non-positive (<=0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is positive (>0)

isNonPositive

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

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is positive (>0)

isNegative

public static final void isNegative(int value)
Check that the value is negative (<0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is non-negative (>=0)

isNegative

public static final void isNegative(int value,
                                    java.lang.String message)
Check that the value is negative (<0).

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is non-negative (>=0)

isPositive

public static final void isPositive(int value)
Check that the value is positive (>0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is non-positive (<=0)

isPositive

public static final void isPositive(int value,
                                    java.lang.String message)
Check that the value is positive (>0).

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is non-positive (<=0)

isNonNegative

public static final void isNonNegative(long value)
Check that the value is non-negative (>=0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is negative (<0)

isNonNegative

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

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is negative (<0)

isNonPositive

public static final void isNonPositive(long value)
Check that the value is non-positive (<=0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is positive (>0)

isNonPositive

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

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is positive (>0)

isNegative

public static final void isNegative(long value)
Check that the value is negative (<0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is non-negative (>=0)

isNegative

public static final void isNegative(long value,
                                    java.lang.String message)
Check that the value is negative (<0).

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is non-negative (>=0)

isPositive

public static final void isPositive(long value)
Check that the value is positive (>0).

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is non-positive (<=0)

isPositive

public static final void isPositive(long value,
                                    java.lang.String message)
Check that the value is positive (>0).

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is non-positive (<=0)

isNotZeroLength

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

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is null or length == 0

isNotZeroLength

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

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is null or length == 0

isNotNull

public static final void isNotNull(java.lang.Object value)
Check that the object is non-null

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is null

isNotNull

public static final void isNotNull(java.lang.Object value,
                                   java.lang.String message)
Check that the object is non-null

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is null

isNull

public static final void isNull(java.lang.Object value)
Check that the object is null

Parameters:
value - Value
Throws:
java.lang.IllegalArgumentException - If value is non-null

isNull

public static final void isNull(java.lang.Object value,
                                java.lang.String message)
Check that the object is null

Parameters:
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is non-null

isInstanceOf

public static final void isInstanceOf(java.lang.Class theClass,
                                      java.lang.Object value)
Check that the object is an instance of the specified Class

Parameters:
theClass - Class
value - Value
Throws:
java.lang.IllegalArgumentException - If value is null

isInstanceOf

public static final void isInstanceOf(java.lang.Class theClass,
                                      java.lang.Object value,
                                      java.lang.String message)
Check that the object is an instance of the specified Class

Parameters:
theClass - Class
value - Value
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If value is null

isNotEmpty

public static final void isNotEmpty(java.util.Collection collection)
Check that the collection is not empty

Parameters:
collection - Collection
Throws:
java.lang.IllegalArgumentException - If collection is null or empty

isNotEmpty

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

Parameters:
collection - Collection
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If collection is null or empty

isNotEmpty

public static final void isNotEmpty(java.util.Map map)
Check that the map is not empty

Parameters:
map - Map
Throws:
java.lang.IllegalArgumentException - If map is null or empty

isNotEmpty

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

Parameters:
map - Map
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If map is null or empty

isNotEmpty

public static final void isNotEmpty(java.lang.Object[] array)
Check that the array is not empty

Parameters:
array - Array
Throws:
java.lang.IllegalArgumentException - If array is null or empty
Since:
3.1

isNotEmpty

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

Parameters:
array - Array
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If array is null or empty
Since:
3.1

isNotEmpty

public static final void isNotEmpty(java.lang.String string)
Check that the string is not empty

Parameters:
string - String
Throws:
java.lang.IllegalArgumentException - If string is null or empty
Since:
3.1

isNotEmpty

public static final void isNotEmpty(java.lang.String string,
                                    java.lang.String message)
Check that the string is not empty

Parameters:
string - String
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If string is null or empty
Since:
3.1

isNotSame

public static void isNotSame(java.lang.Object firstObject,
                             java.lang.String firstName,
                             java.lang.Object secondObject,
                             java.lang.String secondName)
Asserts that the specified first object is not the same as (==) the specified second object.

Parameters:
firstObject - The first object to assert as not the same as the second object.
firstName - The name that will be used within the exception message for the first object, should an exception be thrown; if null and firstObject is not null, firstObject.toString() will be used.
secondObject - The second object to assert as not the same as the first object.
secondName - The name that will be used within the exception message for the second object, should an exception be thrown; if null and secondObject is not null, secondObject.toString() will be used.
Throws:
java.lang.IllegalArgumentException - If the specified objects are the same.
Since:
3.1

contains

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

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

contains

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

Parameters:
collection - Collection to check
value - Value to check for, may be null
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If collection is null or doesn't contain value

containsKey

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

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

containsKey

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

Parameters:
map - Map to check
key - Key to check for, may be null
message - Exception message if check fails
Throws:
java.lang.IllegalArgumentException - If map is null or doesn't contain key


Copyright © 2009. All Rights Reserved.