public final class Preconditions
extends java.lang.Object
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.String errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static void |
checkArgument(boolean expression,
java.lang.String errorMessageTemplate,
java.lang.Object... errorMessageArgs)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static void |
checkArgument(boolean expression,
java.util.function.Supplier<java.lang.String> messageSupplier)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static void |
checkElementIndex(int index,
int size)
Ensures that an index is appropriate for a list or array of given size.
|
static void |
checkElementIndex(int index,
int size,
java.lang.String errorMessageTemplate,
java.lang.Object... errorMessageArgs)
Ensures that an index is appropriate for a list or array of given size.
|
static void |
checkElementIndex(int index,
int size,
java.util.function.Supplier<java.lang.String> messageSupplier)
Ensures that an index is appropriate for a list or array of given size.
|
static void |
checkState(boolean expression)
Ensures the truth of an expression involving one or more fields of a class.
|
static void |
checkState(boolean expression,
java.lang.String errorMessage)
Ensures the truth of an expression involving one or more fields of a class.
|
static void |
checkState(boolean expression,
java.lang.String errorMessageTemplate,
java.lang.Object... errorMessageArgs)
Ensures the truth of an expression involving one or more fields of a class.
|
static void |
checkState(boolean expression,
java.util.function.Supplier<java.lang.String> messageSupplier)
Ensures the truth of an expression involving one or more fields of a class.
|
public static void checkArgument(boolean expression)
expression
- a boolean expressionjava.lang.IllegalArgumentException
- if expression
is falsepublic static void checkArgument(boolean expression, java.lang.String errorMessage)
expression
- a boolean expressionerrorMessage
- the exception message to use if the check failsjava.lang.IllegalArgumentException
- if expression
is falsepublic static void checkArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
expression
- a boolean expressionerrorMessageTemplate
- a template for the exception message should the check fail using the Java Formatter syntax; the same
as used by String.format(String, Object...)
.errorMessageArgs
- the arguments to be substituted into the message template.java.lang.IllegalArgumentException
- if expression
is falsejava.lang.NullPointerException
- if the check fails and either errorMessageTemplate
or errorMessageArgs
is null (don't
let this happen)public static void checkArgument(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
expression
- a boolean expressionmessageSupplier
- a supplier that is called to calculate the error message if necessaryjava.lang.IllegalArgumentException
- if expression
is falsepublic static void checkState(boolean expression)
expression
- a boolean expressionjava.lang.IllegalStateException
- if expression
is falsepublic static void checkState(boolean expression, java.lang.String errorMessage)
expression
- a boolean expressionerrorMessage
- the exception message to use if the check failsjava.lang.IllegalStateException
- if expression
is falsepublic static void checkState(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
expression
- a boolean expressionerrorMessageTemplate
- a template for the exception message should the check fail using the Java Formatter syntax; the same
as used by String.format(String, Object...)
.errorMessageArgs
- the arguments to be substituted into the message template.java.lang.IllegalStateException
- if expression
is falsejava.lang.NullPointerException
- if the check fails and either errorMessageTemplate
or errorMessageArgs
is null (don't
let this happen)public static void checkState(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
expression
- a boolean expressionmessageSupplier
- a supplier that is called to calculate the error message if necessaryjava.lang.IllegalStateException
- if expression
is falsepublic static void checkElementIndex(int index, int size)
index
- size
- java.lang.IndexOutOfBoundsException
- if index is negative or is greater or equal to sizepublic static void checkElementIndex(int index, int size, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)
index
- size
- errorMessageTemplate
- a template for the exception message should the check fail using the Java Formatter syntax; the same
as used by String.format(String, Object...)
.errorMessageArgs
- the arguments to be substituted into the message template.java.lang.IndexOutOfBoundsException
- if index is negative or is greater or equal to sizepublic static void checkElementIndex(int index, int size, java.util.function.Supplier<java.lang.String> messageSupplier)
index
- size
- messageSupplier
- a supplier that is called to calculate the error message if necessaryjava.lang.IndexOutOfBoundsException
- if index is negative or is greater or equal to size