Package io.jmix.core.common.util
Class Preconditions
java.lang.Object
io.jmix.core.common.util.Preconditions
Simple static methods to be called at the start of your own methods to verify correct arguments and state.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkNotEmptyString
(String value) Ensures that a string passed as a parameter to the calling method is not empty.static void
checkNotEmptyString
(String value, String errorMessage) Ensures that a string passed as a parameter to the calling method is not empty.static void
checkNotEmptyString
(String value, String errorMessageTemplate, Object... errorMessageArgs) Ensures that a string passed as a parameter to the calling method is not empty.static void
checkNotNullArgument
(Object reference) Ensures that an object reference passed as a parameter to the calling method is not null.static void
checkNotNullArgument
(Object reference, String errorMessage) Ensures that an object reference passed as a parameter to the calling method is not null.static void
checkNotNullArgument
(Object reference, String errorMessageTemplate, Object... errorMessageArgs) Ensures that an object reference passed as a parameter to the calling method is not null.static String
formatExceptionArgs
(String template, Object... args)
-
Method Details
-
checkNotEmptyString
Ensures that a string passed as a parameter to the calling method is not empty.- Parameters:
value
- string value- Throws:
IllegalArgumentException
- ifvalue
is empty
-
checkNotEmptyString
Ensures that a string passed as a parameter to the calling method is not empty.- Parameters:
value
- string valueerrorMessage
- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)
- Throws:
IllegalArgumentException
- ifvalue
is empty
-
checkNotEmptyString
public static void checkNotEmptyString(@Nullable String value, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) Ensures that a string passed as a parameter to the calling method is not empty.- Parameters:
value
- string valueerrorMessageTemplate
- a template for the exception message should the check fail. The message is formed by replacing each%s
placeholder in the template with an argument. These are matched by position - the first%s
getserrorMessageArgs[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
- ifvalue
is empty
-
checkNotNullArgument
Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference
- an object reference- Throws:
IllegalArgumentException
- ifreference
is null
-
checkNotNullArgument
Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference
- an object referenceerrorMessage
- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)
- Throws:
IllegalArgumentException
- ifreference
is null
-
checkNotNullArgument
public static void checkNotNullArgument(@Nullable Object reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference
- an object referenceerrorMessageTemplate
- a template for the exception message should the check fail. The message is formed by replacing each%s
placeholder in the template with an argument. These are matched by position - the first%s
getserrorMessageArgs[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
- ifreference
is null
-
formatExceptionArgs
-