public final class Preconditions
extends java.lang.Object
Utility class for guava style pre-condition checks. Not an official part of the AppAuth API; only intended for internal use and no guarantees are given on source or binary compatibility for this class between versions of AppAuth.
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArgument(boolean expression)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static void |
checkArgument(boolean expression,
java.lang.Object errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static void |
checkArgument(boolean expression,
java.lang.String errorTemplate,
java.lang.Object... params)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static <T extends java.util.Collection<?>> |
checkCollectionNotEmpty(T collection,
java.lang.Object errorMessage)
Ensures that a collection is not null or empty.
|
static java.lang.String |
checkNotEmpty(java.lang.String str,
java.lang.Object errorMessage)
Ensures that a string is not null or empty.
|
static <T> T |
checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static <T> T |
checkNotNull(T reference,
java.lang.Object errorMessage)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static java.lang.String |
checkNullOrNotEmpty(java.lang.String str,
java.lang.Object errorMessage)
Ensures that the string is either null, or a non-empty string.
|
public static <T> T checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.
reference - an object referencejava.lang.NullPointerException - if reference is nullpublic static <T> T checkNotNull(T reference,
@Nullable
java.lang.Object errorMessage)
Ensures that an object reference passed as a parameter to the calling method is not null.
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.NullPointerException - if reference is null@NonNull
public static java.lang.String checkNotEmpty(java.lang.String str,
@Nullable
java.lang.Object errorMessage)
Ensures that a string is not null or empty.
@NonNull
public static <T extends java.util.Collection<?>> T checkCollectionNotEmpty(T collection,
@Nullable
java.lang.Object errorMessage)
Ensures that a collection is not null or empty.
@NonNull
public static java.lang.String checkNullOrNotEmpty(java.lang.String str,
@Nullable
java.lang.Object errorMessage)
Ensures that the string is either null, or a non-empty string.
public static void checkArgument(boolean expression)
Ensures the truth of an expression involving one or more parameters to the calling method.
expression - a boolean expressionjava.lang.IllegalArgumentException - if expression is falsepublic static void checkArgument(boolean expression,
@Nullable
java.lang.Object errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.
expression - a boolean expressionerrorMessage - the exception message to use if the check fails; will be converted to a
string using String.valueOf(Object)java.lang.IllegalArgumentException - if expression is falsepublic static void checkArgument(boolean expression,
@NonNull
java.lang.String errorTemplate,
java.lang.Object... params)
Ensures the truth of an expression involving one or more parameters to the calling method.
expression - a boolean expressionerrorTemplate - the exception message to use if the check fails; this is used
as the template for String.format.params - the parameters to the exception message.