Package it.tidalwave.util
Class FunctionalCheckedExceptionWrappers
- java.lang.Object
- 
- it.tidalwave.util.FunctionalCheckedExceptionWrappers
 
- 
 public final class FunctionalCheckedExceptionWrappers extends java.lang.ObjectA collections of utility methods for simplifying the syntax of lambda expressions with APIs that don't accept checked exceptions (such asStream): they provide wrapped functions that have no checked exception in the signature and whose implementation delegates to the original function wrapping an eventual checked exception into aRuntimeException. For instance, given the following method that could not be used as aStream.filter(Predicate)argument:private boolean matchEven (final int number) throws Exception { if (number == 13) { throw new Exception("13!"); } return number % 2 == 0; }working code can be written as:try { List<Integer> numbers = IntStream.rangeClosed(1, 20) .mapToObj(Integer::valueOf) .filter(_p(this::matchEven)) // note the wrapper here .collect(Collectors.toList()); ... } catch (RuntimeException e) { ... }Any checked exception is wrapped by aRuntimeException, butIOExceptionis wrapped by aUncheckedIOException.- Since:
- 3.2-ALPHA-1
- Author:
- Fabrizio Giudici
- Status: draft API
 
- 
- 
Constructor SummaryConstructors Constructor Description FunctionalCheckedExceptionWrappers()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.function.Consumer<T>_c(FunctionalCheckedExceptionWrappers.ConsumerWithException<T> consumer)A wrapper for aConsumerthat catches exceptions and wraps them intoRuntimeExceptions.static <T,R>
 java.util.function.Function<T,R>_f(FunctionalCheckedExceptionWrappers.FunctionWithException<T,R> function)A wrapper for aFunctionthat catches exceptions and wraps them intoRuntimeExceptions.static <T> java.util.function.Predicate<T>_p(FunctionalCheckedExceptionWrappers.PredicateWithException<T> predicate)A wrapper for aPredicatethat catches exceptions and wraps them intoRuntimeExceptions.static java.lang.Runnable_r(FunctionalCheckedExceptionWrappers.RunnableWithException runnable)A wrapper for an equivalent ofRunnablethat catches exceptions and wraps them intoRuntimeExceptions.static <T> java.util.function.Supplier<T>_s(FunctionalCheckedExceptionWrappers.SupplierWithException<T> supplier)A wrapper for aSupplierthat catches exceptions and wraps them intoRuntimeExceptions.static java.lang.RuntimeExceptionwrappedException(java.lang.Throwable e)Wraps a throwable with aRuntimeException.
 
- 
- 
- 
Method Detail- 
_f@Nonnull public static <T,R> java.util.function.Function<T,R> _f(@Nonnull FunctionalCheckedExceptionWrappers.FunctionWithException<T,R> function)A wrapper for aFunctionthat catches exceptions and wraps them intoRuntimeExceptions.- Type Parameters:
- T- the type of the function argument
- R- the type of the function return value
- Parameters:
- function- the- Functionto wrap.
- Returns:
- the wrapped Function
 
 - 
_c@Nonnull public static <T> java.util.function.Consumer<T> _c(@Nonnull FunctionalCheckedExceptionWrappers.ConsumerWithException<T> consumer)A wrapper for aConsumerthat catches exceptions and wraps them intoRuntimeExceptions.- Type Parameters:
- T- the type of the- Consumerargument
- Parameters:
- consumer- the- Consumerto wrap.
- Returns:
- the wrapped Consumer
 
 - 
_s@Nonnull public static <T> java.util.function.Supplier<T> _s(@Nonnull FunctionalCheckedExceptionWrappers.SupplierWithException<T> supplier)A wrapper for aSupplierthat catches exceptions and wraps them intoRuntimeExceptions.- Type Parameters:
- T- the type of the- Supplierargument
- Parameters:
- supplier- the- Supplierto wrap.
- Returns:
- the wrapped Supplier
 
 - 
_p@Nonnull public static <T> java.util.function.Predicate<T> _p(@Nonnull FunctionalCheckedExceptionWrappers.PredicateWithException<T> predicate)A wrapper for aPredicatethat catches exceptions and wraps them intoRuntimeExceptions.- Type Parameters:
- T- the type of the- Predicateargument
- Parameters:
- predicate- the- Predicateto wrap.
- Returns:
- the wrapped Predicate
 
 - 
_r@Nonnull public static java.lang.Runnable _r(@Nonnull FunctionalCheckedExceptionWrappers.RunnableWithException runnable)A wrapper for an equivalent ofRunnablethat catches exceptions and wraps them intoRuntimeExceptions.- Parameters:
- runnable- the- Runnableto wrap.
- Returns:
- the wrapped Predicate
- Since:
- 3.2-ALPHA-12
 
 - 
wrappedException@Nonnull public static java.lang.RuntimeException wrappedException(@Nonnull java.lang.Throwable e)Wraps a throwable with aRuntimeException. Unchecked exceptions are not wrapped;IOExceptionis wrapped withUncheckedIOException.- Parameters:
- e- the exception to wrap
- Returns:
- the wrapped exception
 
 
- 
 
-