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 voidcheckNotEmptyString(String value) Ensures that a string passed as a parameter to the calling method is not empty.static voidcheckNotEmptyString(String value, String errorMessage) Ensures that a string passed as a parameter to the calling method is not empty.static voidcheckNotEmptyString(String value, String errorMessageTemplate, Object... errorMessageArgs) Ensures that a string passed as a parameter to the calling method is not empty.static voidcheckNotNullArgument(Object reference) Ensures that an object reference passed as a parameter to the calling method is not null.static voidcheckNotNullArgument(Object reference, String errorMessage) Ensures that an object reference passed as a parameter to the calling method is not null.static voidcheckNotNullArgument(Object reference, String errorMessageTemplate, Object... errorMessageArgs) Ensures that an object reference passed as a parameter to the calling method is not null.static StringformatExceptionArgs(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- ifvalueis 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- ifvalueis 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%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- ifvalueis 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- ifreferenceis 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- ifreferenceis 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%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- ifreferenceis null
-
formatExceptionArgs
-