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 CDC code base in order to reduce external dependencies.
| 构造器和说明 |
|---|
Preconditions() |
| 限定符和类型 | 方法和说明 |
|---|---|
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,
String errorMessageTemplate,
Object... errorMessageArgs)
Checks the given boolean condition, and throws an
IllegalArgumentException if the
condition is not met (evaluates to false). |
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). |
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
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.Copyright © 2025 The Apache Software Foundation. All rights reserved.