Package net.openid.appauth
Class Preconditions
- java.lang.Object
-
- net.openid.appauth.Preconditions
-
public final class Preconditions extends 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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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, Object errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.static void
checkArgument(boolean expression, String errorTemplate, Object... params)
Ensures the truth of an expression involving one or more parameters to the calling method.static <T extends Collection<?>>
TcheckCollectionNotEmpty(T collection, Object errorMessage)
Ensures that a collection is not null or empty.static String
checkNotEmpty(String str, 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, Object errorMessage)
Ensures that an object reference passed as a parameter to the calling method is not null.static String
checkNullOrNotEmpty(String str, Object errorMessage)
Ensures that the string is either null, or a non-empty string.
-
-
-
Method Detail
-
checkNotNull
public static <T> T checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.- Parameters:
reference
- an object reference- Returns:
- the non-null reference that was validated
- Throws:
NullPointerException
- ifreference
isnull
-
checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
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)
- Returns:
- the non-null reference that was validated
- Throws:
NullPointerException
- ifreference
isnull
-
checkNotEmpty
@NonNull public static String checkNotEmpty(String str, @Nullable Object errorMessage)
Ensures that a string is not null or empty.
-
checkCollectionNotEmpty
@NonNull public static <T extends Collection<?>> T checkCollectionNotEmpty(T collection, @Nullable Object errorMessage)
Ensures that a collection is not null or empty.
-
checkNullOrNotEmpty
@NonNull public static String checkNullOrNotEmpty(String str, @Nullable Object errorMessage)
Ensures that the string is either null, or a non-empty string.
-
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
isfalse
-
checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression
- a boolean expressionerrorMessage
- the exception message to use if the check fails; will be converted to a string usingString.valueOf(Object)
- Throws:
IllegalArgumentException
- ifexpression
isfalse
-
checkArgument
public static void checkArgument(boolean expression, @NonNull String errorTemplate, Object... params)
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
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.
-
-