Package com.atlassian.crowd.common.util
Interface ThrowingFunction<T,R>
- Type Parameters:
T
- input parameter typeR
- result type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An alternative to Java's
Function
, that declares a checked exception.
This helps with handling checked exceptions in lambdas.-
Method Summary
Modifier and TypeMethodDescriptionCheckFunction.apply(Object)
static <T,
R> Function<T, R> unchecked
(ThrowingFunction<T, R> lambda) Wraps a lambda by handling checked Exception - converting it intoRuntimeException
static <T,
R> Function<T, R> unchecked
(ThrowingFunction<T, R> lambda, Function<Exception, ? extends RuntimeException> exceptionMapper) Wraps a lambda by handling checked Exception.
-
Method Details
-
apply
CheckFunction.apply(Object)
- Parameters:
input
- function input parameter of type T- Returns:
- function result
- Throws:
Exception
- a checked exception might be thrown
-
unchecked
Wraps a lambda by handling checked Exception - converting it intoRuntimeException
- Type Parameters:
T
- lambda input typeR
- lambda result type- Parameters:
lambda
- lambda function- Returns:
- function that does not declare checked exceptions
-
unchecked
static <T,R> Function<T,R> unchecked(ThrowingFunction<T, R> lambda, Function<Exception, ? extends RuntimeException> exceptionMapper) Wraps a lambda by handling checked Exception. A custom mapper should be provided for transforming the caught checked exception into aRuntimeException
- Type Parameters:
T
- lambda input typeR
- lambda result type- Parameters:
lambda
- lambda functionexceptionMapper
- mapper, transforming checked exception into runtime- Returns:
- function that does not declare checked exceptions
-