Package software.amazon.awssdk.utils
Class FunctionalUtils
- java.lang.Object
-
- software.amazon.awssdk.utils.FunctionalUtils
-
@SdkProtectedApi public final class FunctionalUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFunctionalUtils.UnsafeConsumer<I>Equivalent ofConsumerthat throws a checked exception.static interfaceFunctionalUtils.UnsafeFunction<T,R>Equivalent ofFunctionthat throws a checked exception.static interfaceFunctionalUtils.UnsafeRunnableEquivalent ofRunnablethat throws a checked exception.static interfaceFunctionalUtils.UnsafeSupplier<T>Equivalent ofSupplierthat throws a checked exception.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidinvokeSafely(FunctionalUtils.UnsafeRunnable unsafeRunnable)static <T> TinvokeSafely(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)static <T> Consumer<T>noOpConsumer()static RunnablenoOpRunnable()static voidrunAndLogError(org.slf4j.Logger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable)Runs a givenFunctionalUtils.UnsafeRunnableand logs an error without throwing.static <I> Consumer<I>safeConsumer(FunctionalUtils.UnsafeConsumer<I> unsafeConsumer)A wrapper around a Consumer that throws a checked exception.static <T,R>
Function<T,R>safeFunction(FunctionalUtils.UnsafeFunction<T,R> unsafeFunction)Takes a functional interface that throws an exception and returns aFunctionthat deals with that exception by wrapping in a runtime exception.static RunnablesafeRunnable(FunctionalUtils.UnsafeRunnable unsafeRunnable)A wrapper around a Runnable that throws a checked exception.static <T> Supplier<T>safeSupplier(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)A wrapper around a BiConsumer that throws a checked exception.static <I,O>
Function<I,O>toFunction(Supplier<O> supplier)
-
-
-
Method Detail
-
runAndLogError
public static void runAndLogError(org.slf4j.Logger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable)Runs a givenFunctionalUtils.UnsafeRunnableand logs an error without throwing.- Parameters:
errorMsg- Message to log with exception thrown.runnable- Action to perform.
-
noOpConsumer
public static <T> Consumer<T> noOpConsumer()
- Type Parameters:
T- Type of object to be consumed.- Returns:
- A
Consumerthat does nothing.
-
safeConsumer
public static <I> Consumer<I> safeConsumer(FunctionalUtils.UnsafeConsumer<I> unsafeConsumer)
A wrapper around a Consumer that throws a checked exception.- Parameters:
unsafeConsumer- - something that acts like a consumer but throws an exception- Returns:
- a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
-
safeFunction
public static <T,R> Function<T,R> safeFunction(FunctionalUtils.UnsafeFunction<T,R> unsafeFunction)
Takes a functional interface that throws an exception and returns aFunctionthat deals with that exception by wrapping in a runtime exception. Useful for APIs that use the standard Java functional interfaces that don't throw checked exceptions.- Type Parameters:
T- InputR- Output- Parameters:
unsafeFunction- Functional interface that throws checked exception.- Returns:
- New
Functionthat handles checked exception.
-
safeSupplier
public static <T> Supplier<T> safeSupplier(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
A wrapper around a BiConsumer that throws a checked exception.- Parameters:
unsafeSupplier- - something that acts like a BiConsumer but throws an exception- Returns:
- a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
-
safeRunnable
public static Runnable safeRunnable(FunctionalUtils.UnsafeRunnable unsafeRunnable)
A wrapper around a Runnable that throws a checked exception.- Parameters:
unsafeRunnable- Something that acts like a Runnable but throws an exception- Returns:
- A Runnable that is wrapped in a try-catch converting the checked exception into a runtime exception
-
invokeSafely
public static <T> T invokeSafely(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
-
invokeSafely
public static void invokeSafely(FunctionalUtils.UnsafeRunnable unsafeRunnable)
-
-