Package ru.ilb.jfunction.exception
Class ExceptionalFunctionUtils
- java.lang.Object
-
- ru.ilb.jfunction.exception.ExceptionalFunctionUtils
-
public abstract class ExceptionalFunctionUtils extends Object
Utility class for functional extensions- Author:
- Peter Kurfer
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R extends AutoCloseable>
TtryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer)Functional try-with-resources with default exception translator functionstatic <T,R extends AutoCloseable>
TtryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer, Supplier<T> fallbackSupplier)Functional try-with-resourcesstatic <T,R extends AutoCloseable>
TtryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer, RuntimeExceptionFunction runtimeExceptionFunction)Functional try-with-resources with exception translator function
-
-
-
Method Detail
-
tryWithResources
public static <T,R extends AutoCloseable> T tryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer, Supplier<T> fallbackSupplier)
Functional try-with-resources- Type Parameters:
T- Type of the resultR- Type of the AutoCloseable resource- Parameters:
resourceSupplier- supplier for the AutoCloseable resourceconsumer- function that consumes the resource and returns a valuefallbackSupplier- supplier for a fallback value- Returns:
- instance of T supplied by the consumer or fallback value if exception occurred
-
tryWithResources
public static <T,R extends AutoCloseable> T tryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer, RuntimeExceptionFunction runtimeExceptionFunction)
Functional try-with-resources with exception translator function- Type Parameters:
T- Type of the resultR- Type of the AutoCloseable resource- Parameters:
resourceSupplier- supplier for the AutoCloseable resourceconsumer- function that consumes the resource and returns a valueruntimeExceptionFunction- function that converts Exception to RuntimeException- Returns:
- instance of T supplied by the consumer
-
tryWithResources
public static <T,R extends AutoCloseable> T tryWithResources(ExceptionalResourceSupplier<R> resourceSupplier, ExceptionalFunction<R,T,Exception> consumer)
Functional try-with-resources with default exception translator function- Type Parameters:
T- Type of the resultR- Type of the AutoCloseable resource- Parameters:
resourceSupplier- supplier for the AutoCloseable resourceconsumer- function that consumes the resource and returns a value- Returns:
- instance of T supplied by the consumer
-
-