Package com.atlassian.bamboo.utils
Class Validations
java.lang.Object
com.atlassian.bamboo.utils.Validations
Convenience methods that help a method or constructor check whether it was invoked correctly.
- Since:
- 10.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkArgument
(boolean expression) Ensures the truth of an expression involving one or more parameters to the calling method.static void
checkArgument
(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.static <T> T
checkNotNull
(T reference) Ensures that an object reference is not null.static <T> T
checkNotNull
(T reference, @NotNull String errorMessage) Ensures that an object reference is not null.static void
checkState
(boolean expression) Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.static void
checkState
(boolean expression, @NotNull String errorMessage) Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
-
Constructor Details
-
Validations
public Validations()
-
-
Method Details
-
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 expression representing the condition to be checkederrorMessageTemplate
- a template for the error message in case the check failerrorMessageArgs
- the arguments to be substituted into the message template- Throws:
IllegalArgumentException
- ifexpression
is false
-
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
- ifexpression
is false
-
checkNotNull
Ensures that an object reference is not null.- Type Parameters:
T
- the type of the reference- Parameters:
reference
- the object reference to check for nullityerrorMessage
- the error message to be used in the exception thrown whenreference
is null- Returns:
reference
if not null- Throws:
NullPointerException
- ifreference
is null
-
checkNotNull
public static <T> T checkNotNull(@Nullable T reference) Ensures that an object reference is not null.- Type Parameters:
T
- the type of the reference- Parameters:
reference
- the object reference to check for nullity- Returns:
reference
if not null- Throws:
NullPointerException
- ifreference
is null
-
checkState
Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.- Parameters:
expression
- a boolean expression representing the state that must be satisfiederrorMessage
- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)
- Throws:
IllegalStateException
- ifexpression
is false
-
checkState
public static void checkState(boolean expression) Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.- Parameters:
expression
- a boolean expression representing the state that must be satisfied- Throws:
IllegalStateException
- ifexpression
is false
-