|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.common.util.CheckArg
@Immutable public final class CheckArg
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(Collection<?> argument,
Object value,
String name)
Check that the collection contains the value |
|
static void |
containsKey(Map<?,?> argument,
Object key,
String name)
Check that the map contains the key |
|
static void |
containsNoNulls(Iterable<?> argument,
String name)
Check that the collection is not null and contains no nulls |
|
static void |
containsNoNulls(Object[] argument,
String name)
Check that the array is not null and contains no nulls |
|
static
|
getInstanceOf(Object argument,
Class<C> expectedClass,
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,
String name)
Returns the specified argument if it is not null . |
|
protected static String |
getObjectName(Object obj)
|
|
static void |
hasSizeOfAtLeast(Collection<?> argument,
int minimumSize,
String name)
Check that the collection contains at least the supplied number of elements |
|
static void |
hasSizeOfAtLeast(Map<?,?> argument,
int minimumSize,
String name)
Check that the map contains at least the supplied number of entries |
|
static void |
hasSizeOfAtLeast(Object[] argument,
int minimumSize,
String name)
Check that the array contains at least the supplied number of elements |
|
static void |
hasSizeOfAtMost(Collection<?> argument,
int maximumSize,
String name)
Check that the collection contains no more than the supplied number of elements |
|
static void |
hasSizeOfAtMost(Map<?,?> argument,
int maximumSize,
String name)
Check that the map contains no more than the supplied number of entries |
|
static void |
hasSizeOfAtMost(Object[] argument,
int maximumSize,
String name)
Check that the array contains no more than the supplied number of elements |
|
static void |
isEmpty(Object[] argument,
String name)
Check that the array is empty |
|
static
|
isEquals(T argument,
String argumentName,
T object,
String objectName)
Asserts that the specified first object is equal to the specified second object. |
|
static void |
isGreaterThan(double argument,
double greaterThanValue,
String name)
Check that the argument is greater than the supplied value |
|
static void |
isGreaterThan(int argument,
int greaterThanValue,
String name)
Check that the argument is greater than the supplied value |
|
static void |
isGreaterThanOrEqualTo(int argument,
int greaterThanOrEqualToValue,
String name)
Check that the argument is greater than or equal to the supplied value |
|
static void |
isInstanceOf(Object argument,
Class<?> expectedClass,
String name)
Check that the object is an instance of the specified Class |
|
static void |
isLessThan(int argument,
int lessThanValue,
String name)
Check that the argument is less than the supplied value |
|
static void |
isLessThanOrEqualTo(int argument,
int lessThanOrEqualToValue,
String name)
Check that the argument is less than or equal to the supplied value |
|
static void |
isNegative(double argument,
String name)
Check that the argument is negative (<0). |
|
static void |
isNegative(int argument,
String name)
Check that the argument is negative (<0). |
|
static void |
isNegative(long argument,
String name)
Check that the argument is negative (<0). |
|
static void |
isNonNegative(double argument,
String name)
Check that the argument is non-negative (>=0). |
|
static void |
isNonNegative(int argument,
String name)
Check that the argument is non-negative (>=0). |
|
static void |
isNonNegative(long argument,
String name)
Check that the argument is non-negative (>=0). |
|
static void |
isNonPositive(double argument,
String name)
Check that the argument is non-positive (<=0). |
|
static void |
isNonPositive(int argument,
String name)
Check that the argument is non-positive (<=0). |
|
static void |
isNonPositive(long argument,
String name)
Check that the argument is non-positive (<=0). |
|
static void |
isNotEmpty(Collection<?> argument,
String name)
Check that the collection is not empty |
|
static void |
isNotEmpty(Iterator<?> argument,
String name)
Checks that the iterator is not empty, and throws an exception if it is. |
|
static void |
isNotEmpty(Map<?,?> argument,
String name)
Check that the map is not empty |
|
static void |
isNotEmpty(Object[] argument,
String name)
Check that the array is not empty |
|
static void |
isNotEmpty(String argument,
String name)
Check that the string is not empty, is not null, and does not contain only whitespace. |
|
static
|
isNotEquals(T argument,
String argumentName,
T object,
String objectName)
Asserts that the specified first object is not equal to the specified second object. |
|
static void |
isNotGreaterThan(int argument,
int notGreaterThanValue,
String name)
Check that the argument is not greater than the supplied value |
|
static void |
isNotLessThan(int argument,
int notLessThanValue,
String name)
Check that the argument is not less than the supplied value |
|
static void |
isNotNan(double argument,
String name)
Check that the argument is not NaN. |
|
static void |
isNotNull(Object argument,
String name)
Check that the specified argument is non-null |
|
static
|
isNotSame(T argument,
String argumentName,
T object,
String objectName)
Asserts that the specified first object is not the same as (==) the specified second object. |
|
static void |
isNotZeroLength(String argument,
String name)
Check that the string is non-null and has length > 0 |
|
static void |
isNull(Object argument,
String name)
Check that the argument is null |
|
static void |
isPositive(double argument,
String name)
Check that the argument is positive (>0). |
|
static void |
isPositive(int argument,
String name)
Check that the argument is positive (>0). |
|
static void |
isPositive(long argument,
String name)
Check that the argument is positive (>0). |
|
static
|
isSame(T argument,
String argumentName,
T object,
String objectName)
Asserts that the specified first object is the same as (==) the specified second object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void isNotLessThan(int argument, int notLessThanValue, String name)
argument
- The argumentnotLessThanValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument greater than or equal to the supplied vlauepublic static void isNotGreaterThan(int argument, int notGreaterThanValue, String name)
argument
- The argumentnotGreaterThanValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is less than or equal to the supplied valuepublic static void isGreaterThan(int argument, int greaterThanValue, String name)
argument
- The argumentgreaterThanValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is not greater than the supplied valuepublic static void isGreaterThan(double argument, double greaterThanValue, String name)
argument
- The argumentgreaterThanValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is not greater than the supplied valuepublic static void isLessThan(int argument, int lessThanValue, String name)
argument
- The argumentlessThanValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is not less than the supplied valuepublic static void isGreaterThanOrEqualTo(int argument, int greaterThanOrEqualToValue, String name)
argument
- The argumentgreaterThanOrEqualToValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is not greater than or equal to the supplied valuepublic static void isLessThanOrEqualTo(int argument, int lessThanOrEqualToValue, String name)
argument
- The argumentlessThanOrEqualToValue
- the value that is to be used to check the valuename
- The name of the argument
IllegalArgumentException
- If argument is not less than or equal to the supplied valuepublic static void isNonNegative(int argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(int argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is positive (>0)public static void isNegative(int argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(int argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-positive (<=0)public static void isNonNegative(long argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(long argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is positive (>0)public static void isNegative(long argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(long argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-positive (<=0)public static void isNonNegative(double argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is negative (<0)public static void isNonPositive(double argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is positive (>0)public static void isNegative(double argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-negative (>=0)public static void isPositive(double argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is non-positive (<=0)public static void isNotNan(double argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is NaNpublic static void isNotZeroLength(String argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If value is null or length == 0public static void isNotEmpty(String argument, String name)
argument
- Stringname
- The name of the argument
IllegalArgumentException
- If string is null or emptypublic static void isNotNull(Object argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is nullpublic static <T> T getNotNull(T argument, String name)
null
.
T
- argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If argument is null
public static void isNull(Object argument, String name)
argument
- The argumentname
- The name of the argument
IllegalArgumentException
- If value is non-nullpublic static void isInstanceOf(Object argument, Class<?> expectedClass, String name)
argument
- ValueexpectedClass
- Classname
- The name of the argument
IllegalArgumentException
- If value is nullpublic static <C> C getInstanceOf(Object argument, Class<C> expectedClass, String name)
C
- the class typeargument
- ValueexpectedClass
- Classname
- The name of the argument
IllegalArgumentException
- If value is not an instance of theClass.public static <T> void isSame(T argument, String argumentName, T object, 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.
IllegalArgumentException
- If the specified objects are not the same.public static <T> void isNotSame(T argument, String argumentName, T object, 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.
IllegalArgumentException
- If the specified objects are the same.public static <T> void isEquals(T argument, String argumentName, T object, String objectName)
equal to
the specified second object. This method
does take null references into consideration.
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.
IllegalArgumentException
- If the specified objects are not equal.public static <T> void isNotEquals(T argument, String argumentName, T object, String objectName)
equal to
the specified second object. This
method does take null references into consideration.
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.
IllegalArgumentException
- If the specified objects are equals.public static void isNotEmpty(Iterator<?> argument, String name)
argument
- the iterator to checkname
- The name of the argument
IllegalArgumentException
- If iterator is empty (i.e., iterator.hasNext() returns false)public static void isNotEmpty(Collection<?> argument, String name)
argument
- Collectionname
- The name of the argument
IllegalArgumentException
- If collection is null or emptypublic static void isNotEmpty(Map<?,?> argument, String name)
argument
- Mapname
- The name of the argument
IllegalArgumentException
- If map is null or emptypublic static void isEmpty(Object[] argument, String name)
argument
- Arrayname
- The name of the argument
IllegalArgumentException
- If array is not emptypublic static void isNotEmpty(Object[] argument, String name)
argument
- Arrayname
- The name of the argument
IllegalArgumentException
- If array is null or emptyprotected static String getObjectName(Object obj)
public static void contains(Collection<?> argument, Object value, String name)
argument
- Collection to checkvalue
- Value to check for, may be nullname
- The name of the argument
IllegalArgumentException
- If collection is null or doesn't contain valuepublic static void containsKey(Map<?,?> argument, Object key, String name)
argument
- Map to checkkey
- Key to check for, may be nullname
- The name of the argument
IllegalArgumentException
- If map is null or doesn't contain keypublic static void containsNoNulls(Iterable<?> argument, String name)
argument
- Arrayname
- The name of the argument
IllegalArgumentException
- If array is null or has null valuespublic static void containsNoNulls(Object[] argument, String name)
argument
- Arrayname
- The name of the argument
IllegalArgumentException
- If array is null or has null valuespublic static void hasSizeOfAtLeast(Collection<?> argument, int minimumSize, String name)
argument
- CollectionminimumSize
- the minimum sizename
- The name of the argument
IllegalArgumentException
- If collection has a size smaller than the supplied valuepublic static void hasSizeOfAtMost(Collection<?> argument, int maximumSize, String name)
argument
- CollectionmaximumSize
- the maximum sizename
- The name of the argument
IllegalArgumentException
- If collection has a size smaller than the supplied valuepublic static void hasSizeOfAtLeast(Map<?,?> argument, int minimumSize, String name)
argument
- the mapminimumSize
- the minimum sizename
- The name of the argument
IllegalArgumentException
- If the map has a size smaller than the supplied valuepublic static void hasSizeOfAtMost(Map<?,?> argument, int maximumSize, String name)
argument
- the mapmaximumSize
- the maximum sizename
- The name of the argument
IllegalArgumentException
- If the map has a size smaller than the supplied valuepublic static void hasSizeOfAtLeast(Object[] argument, int minimumSize, String name)
argument
- the arrayminimumSize
- the minimum sizename
- The name of the argument
IllegalArgumentException
- If the array has a size smaller than the supplied valuepublic static void hasSizeOfAtMost(Object[] argument, int maximumSize, String name)
argument
- the arraymaximumSize
- the maximum sizename
- The name of the argument
IllegalArgumentException
- If the array has a size smaller than the supplied value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |