Class Preconditions
- java.lang.Object
-
- org.apache.activemq.artemis.utils.Preconditions
-
public class Preconditions extends Object
-
-
Constructor Summary
Constructors Constructor Description Preconditions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckArgument(boolean expression)Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, Object errorMessage)Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)Ensures the truth of an expression involving one or more parameters to the calling method.static <T> TcheckNotNull(T reference)Ensures that an object reference passed as a parameter to the calling method is not null.
-
-
-
Method Detail
-
checkNotNull
public static <T> T checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference- an object reference- Returns:
- the non-null reference that was validated
- Throws:
NullPointerException- ifreferenceis null
-
checkArgument
public static void checkArgument(boolean expression, Object errorMessage)Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expressionerrorMessage- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expressionerrorMessageTemplate- a template for the exception message should the check fail. The message is formed by replacing each%splaceholder in the template with an argument. These are matched by position - the first%sgetserrorMessageArgs[0], etc. Unmatched arguments will be appended to the formatted message in square braces. Unmatched placeholders will be left as-is.errorMessageArgs- the arguments to be substituted into the message template. Arguments are converted to strings usingString.valueOf(Object).- Throws:
IllegalArgumentException- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkArgument
public static void checkArgument(boolean expression)
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expression- Throws:
IllegalArgumentException- ifexpressionis false
-
-