Class Preconditions
- java.lang.Object
-
- com.amazonaws.kinesisvideo.common.preconditions.Preconditions
-
public final class Preconditions extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckArgument(boolean expression)Validates the expression is true.static voidcheckArgument(boolean expression, Object errorMessage)Validates the expression is true.static voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)Validates the expression is true.static <T> TcheckNotNull(T reference)Validates the object is not null.static <T> TcheckNotNull(T reference, Object errorMessage)Validates the object is not null.static <T> TcheckNotNull(T reference, String errorMessageTemplate, Object... errorMessageArgs)Validates the object is not null.static voidcheckState(boolean expression)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.static voidcheckState(boolean expression, Object errorMessage)Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
-
-
-
Method Detail
-
checkArgument
public static void checkArgument(boolean expression)
Validates the expression is true.- Parameters:
expression- a boolean expression- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)Validates the expression is true.- Parameters:
expression- a boolean expressionerrorMessage- Error message to use.- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
public static void checkArgument(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)Validates the expression is true.- Parameters:
expression- a boolean expressionerrorMessageTemplate- String templateerrorMessageArgs- Arguments for the string template- Throws:
IllegalArgumentException- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkNotNull
public static <T> T checkNotNull(T reference)
Validates the object is not null.- Parameters:
reference- an object reference- Returns:
- the non-null reference that was validated
- Throws:
NullPointerException- ifreferenceis null
-
checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)Validates the object 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- ifreferenceis null
-
checkNotNull
public static <T> T checkNotNull(T reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)Validates the object is not null.- Parameters:
reference- an object referenceerrorMessageTemplate- Template to be used in the message.errorMessageArgs- Arguments to be supplied to the message- Returns:
- the non-null reference that was validated
- Throws:
NullPointerException- ifreferenceis null
-
checkState
public static void checkState(boolean expression)
Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.- Parameters:
expression- a boolean expression- Throws:
IllegalStateException- ifexpressionis false
-
checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)Ensures the truth of an expression involving the state of the calling instance, but not involving any 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:
IllegalStateException- ifexpressionis false
-
-