|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.dna.common.util.ArgCheck
public final class ArgCheck
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
|
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
|
getNotNull(T argument,
java.lang.String name)
Returns the specified argument if it is not null . |
|
static
|
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
|
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
|
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
|
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 |
---|
public static void isNonNegative(int argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(int argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is positive (>0)public static void isNegative(int argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(int argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-positive (<=0)public static void isNonNegative(long argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(long argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is positive (>0)public static void isNegative(long argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(long argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-positive (<=0)public static void isNonNegative(double argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(double argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is positive (>0)public static void isNegative(double argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(double argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is non-positive (<=0)public static void isNotNan(double argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is NaNpublic static void isNotZeroLength(java.lang.String argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If value is null or length == 0public static void isNotEmpty(java.lang.String argument, java.lang.String name)
argument
- Stringname
- The name of the argument
java.lang.IllegalArgumentException
- If string is null or emptypublic static void isNotNull(java.lang.Object argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is nullpublic static <T> T getNotNull(T argument, java.lang.String name)
null
.
T
- argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If argument is null
public static void isNull(java.lang.Object argument, java.lang.String name)
argument
- The argumentname
- The name of the argument
java.lang.IllegalArgumentException
- If value is non-nullpublic static void isInstanceOf(java.lang.Object argument, java.lang.Class expectedClass, java.lang.String name)
argument
- ValueexpectedClass
- Classname
- The name of the argument
java.lang.IllegalArgumentException
- If value is nullpublic static <C> C getInstanceOf(java.lang.Object argument, java.lang.Class<C> expectedClass, java.lang.String name)
C
- argument
- ValueexpectedClass
- Classname
- The name of the argument
java.lang.IllegalArgumentException
- If value is not an instance of theClass.public static <T> void isSame(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
T
- 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 thrownobject
- 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.
java.lang.IllegalArgumentException
- If the specified objects are not the same.public static <T> void isNotSame(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
T
- 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 thrownobject
- 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.
java.lang.IllegalArgumentException
- If the specified objects are the same.public static <T> void isEquals(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
equal to
the specified second object.
T
- 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 thrownobject
- 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.
java.lang.IllegalArgumentException
- If the specified objects are not equal.public static <T> void isNotEquals(T argument, java.lang.String argumentName, T object, java.lang.String objectName)
equal to
the specified second object.
T
- 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 thrownobject
- 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.
java.lang.IllegalArgumentException
- If the specified objects are equals.public static void isNotEmpty(java.util.Iterator argument, java.lang.String name)
argument
- the iterator to checkname
- The name of the argument
java.lang.IllegalArgumentException
- If iterator is empty (i.e., iterator.hasNext() returns false)public static void isNotEmpty(java.util.Collection argument, java.lang.String name)
argument
- Collectionname
- The name of the argument
java.lang.IllegalArgumentException
- If collection is null or emptypublic static void isNotEmpty(java.util.Map argument, java.lang.String name)
argument
- Mapname
- The name of the argument
java.lang.IllegalArgumentException
- If map is null or emptypublic static void isNotEmpty(java.lang.Object[] argument, java.lang.String name)
argument
- Arrayname
- The name of the argument
java.lang.IllegalArgumentException
- If array is null or emptypublic static void contains(java.util.Collection argument, java.lang.Object value, java.lang.String name)
argument
- Collection to checkvalue
- Value to check for, may be nullname
- The name of the argument
java.lang.IllegalArgumentException
- If collection is null or doesn't contain valuepublic static void containsKey(java.util.Map argument, java.lang.Object key, java.lang.String name)
argument
- Map to checkkey
- Key to check for, may be nullname
- The name of the argument
java.lang.IllegalArgumentException
- If map is null or doesn't contain keypublic static void containsNoNulls(java.util.Collection argument, java.lang.String name)
argument
- Arrayname
- The name of the argument
java.lang.IllegalArgumentException
- If array is null or has null valuespublic static void containsNoNulls(java.lang.Object[] argument, java.lang.String name)
argument
- Arrayname
- The name of the argument
java.lang.IllegalArgumentException
- If array is null or has null values
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |