@Internal public final class Preconditions extends Object
This class is modelled after Google Guava's Preconditions class, and partly takes code from that class. We add this code to the Flink code base in order to reduce external dependencies.
Modifier and Type | Method and Description |
---|---|
static void |
checkArgument(boolean condition)
Checks the given boolean condition, and throws an
IllegalArgumentException if the
condition is not met (evaluates to false ). |
static void |
checkArgument(boolean condition,
Object errorMessage)
Checks the given boolean condition, and throws an
IllegalArgumentException if the
condition is not met (evaluates to false ). |
static void |
checkArgument(boolean condition,
String errorMessageTemplate,
Object... errorMessageArgs)
Checks the given boolean condition, and throws an
IllegalArgumentException if the
condition is not met (evaluates to false ). |
static void |
checkCompletedNormally(CompletableFuture<?> future)
Ensures that future has completed normally.
|
static void |
checkElementIndex(int index,
int size)
Ensures that the given index is valid for an array, list or string of the given size.
|
static void |
checkElementIndex(int index,
int size,
String errorMessage)
Ensures that the given index is valid for an array, list or string of the given size.
|
static <T> T |
checkNotNull(T reference)
Ensures that the given object reference is not null.
|
static <T> T |
checkNotNull(T reference,
String errorMessage)
Ensures that the given object reference is not null.
|
static <T> T |
checkNotNull(T reference,
String errorMessageTemplate,
Object... errorMessageArgs)
Ensures that the given object reference is not null.
|
static void |
checkState(boolean condition)
Checks the given boolean condition, and throws an
IllegalStateException if the
condition is not met (evaluates to false ). |
static void |
checkState(boolean condition,
Object errorMessage)
Checks the given boolean condition, and throws an
IllegalStateException if the
condition is not met (evaluates to false ). |
static void |
checkState(boolean condition,
String errorMessageTemplate,
Object... errorMessageArgs)
Checks the given boolean condition, and throws an
IllegalStateException if the
condition is not met (evaluates to false ). |
public static <T> T checkNotNull(@Nullable T reference)
NullPointerException
with no message is thrown.reference
- The object referenceNullPointerException
- Thrown, if the passed reference was null.public static <T> T checkNotNull(@Nullable T reference, @Nullable String errorMessage)
NullPointerException
with the given message is thrown.reference
- The object referenceerrorMessage
- The message for the NullPointerException
that is thrown if the
check fails.NullPointerException
- Thrown, if the passed reference was null.public static <T> T checkNotNull(T reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
NullPointerException
with the given message is thrown.
The error message is constructed from a template and an arguments array, after a similar
fashion as String.format(String, Object...)
, but supporting only %s
as a
placeholder.
reference
- The object referenceerrorMessageTemplate
- The message template for the NullPointerException
that is
thrown if the check fails. The template substitutes its %s
placeholders with the
error message arguments.errorMessageArgs
- The arguments for the error message, to be inserted into the message
template for the %s
placeholders.NullPointerException
- Thrown, if the passed reference was null.public static void checkArgument(boolean condition)
IllegalArgumentException
if the
condition is not met (evaluates to false
).condition
- The condition to checkIllegalArgumentException
- Thrown, if the condition is violated.public static void checkArgument(boolean condition, @Nullable Object errorMessage)
IllegalArgumentException
if the
condition is not met (evaluates to false
). The exception will have the given error
message.condition
- The condition to checkerrorMessage
- The message for the IllegalArgumentException
that is thrown if
the check fails.IllegalArgumentException
- Thrown, if the condition is violated.public static void checkArgument(boolean condition, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
IllegalArgumentException
if the
condition is not met (evaluates to false
).condition
- The condition to checkerrorMessageTemplate
- The message template for the IllegalArgumentException
that is thrown if the check fails. The template substitutes its %s
placeholders
with the error message arguments.errorMessageArgs
- The arguments for the error message, to be inserted into the message
template for the %s
placeholders.IllegalArgumentException
- Thrown, if the condition is violated.public static void checkState(boolean condition)
IllegalStateException
if the
condition is not met (evaluates to false
).condition
- The condition to checkIllegalStateException
- Thrown, if the condition is violated.public static void checkState(boolean condition, @Nullable Object errorMessage)
IllegalStateException
if the
condition is not met (evaluates to false
). The exception will have the given error
message.condition
- The condition to checkerrorMessage
- The message for the IllegalStateException
that is thrown if the
check fails.IllegalStateException
- Thrown, if the condition is violated.public static void checkState(boolean condition, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
IllegalStateException
if the
condition is not met (evaluates to false
).condition
- The condition to checkerrorMessageTemplate
- The message template for the IllegalStateException
that
is thrown if the check fails. The template substitutes its %s
placeholders with
the error message arguments.errorMessageArgs
- The arguments for the error message, to be inserted into the message
template for the %s
placeholders.IllegalStateException
- Thrown, if the condition is violated.public static void checkElementIndex(int index, int size)
index
- index to checksize
- size of the array, list or stringIllegalArgumentException
- Thrown, if size is negative.IndexOutOfBoundsException
- Thrown, if the index negative or greater than or equal to
sizepublic static void checkElementIndex(int index, int size, @Nullable String errorMessage)
index
- index to checksize
- size of the array, list or stringerrorMessage
- The message for the IndexOutOfBoundsException
that is thrown if
the check fails.IllegalArgumentException
- Thrown, if size is negative.IndexOutOfBoundsException
- Thrown, if the index negative or greater than or equal to
sizepublic static void checkCompletedNormally(CompletableFuture<?> future)
IllegalStateException
- Thrown, if future has not completed or it has completed
exceptionally.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.