Class Assertions
- java.lang.Object
-
- com.mongodb.spark.sql.connector.assertions.Assertions
-
public final class Assertions extends java.lang.ObjectAssertions to validate inputs
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidensureArgument(java.util.function.Supplier<java.lang.Boolean> argumentCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Ensures the validity of argumentsstatic voidensureState(java.util.function.Supplier<java.lang.Boolean> stateCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Ensures the validity of statestatic <T> TvalidateConfig(java.util.function.Supplier<T> valueSupplier, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Checks the validity of a valuestatic <T> TvalidateConfig(T value, java.util.function.Predicate<T> predicate, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Checks the validity of a value
-
-
-
Method Detail
-
ensureState
public static void ensureState(java.util.function.Supplier<java.lang.Boolean> stateCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Ensures the validity of state- Parameters:
stateCheck- the supplier of the state checkerrorMessageSupplier- the supplier of the error message if the predicate- Throws:
java.lang.IllegalStateException- if the state check fails
-
ensureArgument
public static void ensureArgument(java.util.function.Supplier<java.lang.Boolean> argumentCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Ensures the validity of arguments- Parameters:
argumentCheck- the supplier of the argument checkerrorMessageSupplier- the supplier of the error message if the predicate fails- Throws:
java.lang.IllegalArgumentException- if the argument check fails
-
validateConfig
public static <T> T validateConfig(T value, java.util.function.Predicate<T> predicate, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Checks the validity of a value- Type Parameters:
T- the type of the value being checked- Parameters:
value- the value to checkpredicate- the predicateerrorMessageSupplier- the supplier of the error message if the predicate fails- Returns:
- the value or throw an
ConfigExceptionif the value is invalid - Throws:
ConfigException- if the predicate returns false
-
validateConfig
public static <T> T validateConfig(java.util.function.Supplier<T> valueSupplier, java.util.function.Supplier<java.lang.String> errorMessageSupplier)Checks the validity of a value- Type Parameters:
T- the type of the value being checked- Parameters:
valueSupplier- the supplier of the valueerrorMessageSupplier- the supplier of the error message if the predicate fails- Returns:
- the value or throw an
ConfigExceptionif the supplier throws an exception - Throws:
ConfigException- if the supplier throws an exception
-
-