Package software.amazon.awssdk.utils
Class FunctionalUtils
java.lang.Object
software.amazon.awssdk.utils.FunctionalUtils
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Equivalent ofConsumer
that throws a checked exception.static interface
Equivalent ofFunction
that throws a checked exception.static interface
Equivalent ofRunnable
that throws a checked exception.static interface
Equivalent ofSupplier
that throws a checked exception. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
invokeSafely
(FunctionalUtils.UnsafeRunnable unsafeRunnable) static <T> T
invokeSafely
(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier) static <T> Consumer
<T> static Runnable
static void
runAndLogError
(org.slf4j.Logger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable) Runs a givenFunctionalUtils.UnsafeRunnable
and 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 aFunction
that deals with that exception by wrapping in a runtime exception.static Runnable
safeRunnable
(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 Details
-
runAndLogError
public static void runAndLogError(org.slf4j.Logger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable) Runs a givenFunctionalUtils.UnsafeRunnable
and logs an error without throwing.- Parameters:
errorMsg
- Message to log with exception thrown.runnable
- Action to perform.
-
noOpConsumer
- Type Parameters:
T
- Type of object to be consumed.- Returns:
- A
Consumer
that does nothing.
-
noOpRunnable
- Returns:
- A
Runnable
that does nothing.
-
safeConsumer
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
Takes a functional interface that throws an exception and returns aFunction
that 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
Function
that handles checked exception.
-
safeSupplier
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
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
-
toFunction
-
invokeSafely
-
invokeSafely
-