Package software.amazon.awssdk.utils
Class FunctionalUtils
- java.lang.Object
-
- software.amazon.awssdk.utils.FunctionalUtils
-
public final class FunctionalUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
FunctionalUtils.UnsafeConsumer<I>
Equivalent ofConsumer
that throws a checked exception.static interface
FunctionalUtils.UnsafeFunction<T,R>
Equivalent ofFunction
that throws a checked exception.static interface
FunctionalUtils.UnsafeRunnable
Equivalent ofRunnable
that throws a checked exception.static interface
FunctionalUtils.UnsafeSupplier<T>
Equivalent ofSupplier
that throws a checked exception.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
invokeSafely(FunctionalUtils.UnsafeRunnable unsafeRunnable)
static <T> T
invokeSafely(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
static <T> Consumer<T>
noOpConsumer()
static Runnable
noOpRunnable()
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 Detail
-
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
public static <T> Consumer<T> noOpConsumer()
- Type Parameters:
T
- Type of object to be consumed.- Returns:
- A
Consumer
that 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 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
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)
-
-