public final class FunctionalUtils extends Object
| Modifier and Type | Class and Description | 
|---|---|
| static interface  | FunctionalUtils.UnsafeConsumer<I>Equivalent of  Consumerthat throws a checked exception. | 
| static interface  | FunctionalUtils.UnsafeFunction<T,R>Equivalent of  Functionthat throws a checked exception. | 
| static interface  | FunctionalUtils.UnsafeRunnableEquivalent of  Runnablethat throws a checked exception. | 
| static interface  | FunctionalUtils.UnsafeSupplier<T>Equivalent of  Supplierthat throws a checked exception. | 
| Modifier and Type | Method and 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 given  FunctionalUtils.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 a  Functionthat 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) | 
public static void runAndLogError(org.slf4j.Logger log,
                                  String errorMsg,
                                  FunctionalUtils.UnsafeRunnable runnable)
FunctionalUtils.UnsafeRunnable and logs an error without throwing.errorMsg - Message to log with exception thrown.runnable - Action to perform.public static <T> Consumer<T> noOpConsumer()
T - Type of object to be consumed.Consumer that does nothing.public static <I> Consumer<I> safeConsumer(FunctionalUtils.UnsafeConsumer<I> unsafeConsumer)
unsafeConsumer - - something that acts like a consumer but throws an exceptionpublic static <T,R> Function<T,R> safeFunction(FunctionalUtils.UnsafeFunction<T,R> unsafeFunction)
Function 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.T - InputR - OutputunsafeFunction - Functional interface that throws checked exception.Function that handles checked exception.public static <T> Supplier<T> safeSupplier(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
unsafeSupplier - - something that acts like a BiConsumer but throws an exceptionpublic static Runnable safeRunnable(FunctionalUtils.UnsafeRunnable unsafeRunnable)
unsafeRunnable - Something that acts like a Runnable but throws an exceptionpublic static <T> T invokeSafely(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
public static void invokeSafely(FunctionalUtils.UnsafeRunnable unsafeRunnable)
Copyright © 2020. All rights reserved.