Package org.faktorips.util
Class ArgumentCheck
java.lang.Object
org.faktorips.util.ArgumentCheck
A class that provides static methods to check method arguments, e.g. check if an argument is not
null or is an instance of a specific class.
All methods have an "optional" context parameter. If the check fails, the context's toString method is called and put into the IllegalArgumentException that is thrown. In this way you can provide some information in which context the check has failed and avoid to create a String object in the default case, when the check passes successfully.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final voidatLeast(Collection<?> c, int size) Checks if the given collection has at least the given size.static final voidChecks if the indicated arguments are equal.static final voidChecks if the indicated arguments are equal.static final voidisInstanceOf(Object arg, Class<?> clazz) Checks if the indicated argument is an instance of the indicated class.static final voidisInstanceOf(Object arg, Class<?> clazz, Object context) Checks if the indicated argument is an instance of the indicated class.static final voidisSubclassOf(Class<?> subclass, Class<?> superclass) Checks if the given subclass is a subclass of the given superclass.static final voidisTrue(boolean arg) Checks if the indicated argument is true.static final voidChecks if the indicated argument is true.static final voidChecks if the indicated array has the indicated length.static final voidChecks if the indicated array has the indicated length.static final voidChecks if the given xml node has the given name.static final voidChecks if the indicated argument is not null.static final voidChecks if the provided array or one of the objects at the array's positions is null.static final voidChecks if the provided array or the objects at the array positions are null.static final voidChecks if the indicated argument is not null.
-
Method Details
-
notNull
Checks if the indicated argument is not null.- Parameters:
arg- the argument to check.- Throws:
NullPointerException- if arg is null.
-
notNull
Checks if the provided array or one of the objects at the array's positions is null. If so a NullPointerException is thrown.- Parameters:
arg- the argument to check.
-
notNull
Checks if the provided array or the objects at the array positions are null. If so a NullPointerException is thrown.- Parameters:
arg- the argument to check.context- information, in case the test fails, the context's toString()
-
notNull
Checks if the indicated argument is not null.- Parameters:
arg- the argument to check.context- context information, in case the test fails, the context's toString() method is called and the result passed to the NullPointerException.- Throws:
NullPointerException- if arg is null.
-
isTrue
public static final void isTrue(boolean arg) Checks if the indicated argument is true.- Parameters:
arg- the argument to check.- Throws:
NullPointerException- if arg is null.
-
isTrue
Checks if the indicated argument is true.- Parameters:
arg- the argument to check.- Throws:
NullPointerException- if arg is null.
-
equals
Checks if the indicated arguments are equal.- Throws:
IllegalArgumentException- if arg1.equals(arg2) returns falls.
-
equals
Checks if the indicated arguments are equal.- Throws:
IllegalArgumentException- if arg1.equals(arg2) returns falls.
-
isInstanceOf
Checks if the indicated argument is an instance of the indicated class.- Parameters:
arg- the argument to check.- Throws:
IllegalArgumentException- if arg is null.
-
isInstanceOf
Checks if the indicated argument is an instance of the indicated class.- Parameters:
arg- the argument to check.- Throws:
IllegalArgumentException- if arg is null.
-
length
Checks if the indicated array has the indicated length.- Parameters:
arg- the array to check.length- the expected array length- Throws:
IllegalArgumentException- if the array has not the given length.
-
atLeast
Checks if the given collection has at least the given size.- Parameters:
c- the collection to check.size- the expected array length- Throws:
IllegalArgumentException- if the array has not the given length.
-
length
Checks if the indicated array has the indicated length.- Parameters:
a- the array to check.length- the expected array lengthcontext- an Object whosetoStringis used as the message for the IllegalArgumentException if it is thrown- Throws:
IllegalArgumentException- if the array has not the given length.
-
isSubclassOf
Checks if the given subclass is a subclass of the given superclass.- Throws:
IllegalArgumentException- if subclass is not a subclass of superclass.
-
nodeName
Checks if the given xml node has the given name.- Throws:
IllegalArgumentException- if the node has not the expected name.NullPointerException- if node isnull.
-