public final class Preconditions
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
checkNotEmptyString(java.lang.String value)
Ensures that a string passed as a parameter to the calling method is not empty.
|
static void |
checkNotEmptyString(java.lang.String value,
java.lang.String errorMessage)
Ensures that a string passed as a parameter to the calling method is not empty.
|
static void |
checkNotEmptyString(java.lang.String value,
java.lang.String errorMessageTemplate,
java.lang.Object... errorMessageArgs)
Ensures that a string passed as a parameter to the calling method is not empty.
|
static void |
checkNotNullArgument(java.lang.Object reference)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static void |
checkNotNullArgument(java.lang.Object reference,
java.lang.String errorMessage)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static void |
checkNotNullArgument(java.lang.Object reference,
java.lang.String errorMessageTemplate,
java.lang.Object... errorMessageArgs)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static java.lang.String |
formatExceptionArgs(java.lang.String template,
java.lang.Object... args) |
public static void checkNotEmptyString(java.lang.String value)
value
- string valuejava.lang.IllegalArgumentException
- if value
is emptypublic static void checkNotEmptyString(java.lang.String value, @Nullable java.lang.String errorMessage)
value
- string valueerrorMessage
- the exception message to use if the check fails; will be converted to a string using
String.valueOf(Object)
java.lang.IllegalArgumentException
- if value
is emptypublic static void checkNotEmptyString(java.lang.String value, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object... errorMessageArgs)
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
gets
errorMessageArgs[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 using
String.valueOf(Object)
.java.lang.IllegalArgumentException
- if value
is emptypublic static void checkNotNullArgument(java.lang.Object reference)
reference
- an object referencejava.lang.IllegalArgumentException
- if reference
is nullpublic static void checkNotNullArgument(java.lang.Object reference, @Nullable java.lang.String errorMessage)
reference
- an object referenceerrorMessage
- the exception message to use if the check fails; will
be converted to a string using String.valueOf(Object)
java.lang.IllegalArgumentException
- if reference
is nullpublic static void checkNotNullArgument(java.lang.Object reference, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object... errorMessageArgs)
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
gets errorMessageArgs[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 using
String.valueOf(Object)
.java.lang.IllegalArgumentException
- if reference
is nullpublic static java.lang.String formatExceptionArgs(java.lang.String template, @Nullable java.lang.Object... args)