Interface DoubleFunctionWithException<R,E extends Exception>
-
- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunctionWithException<R,E>>
,ObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E>>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface DoubleFunctionWithException<R,E extends Exception> extends ObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E>>
Represents a function that accepts a double-valued argument, may throw exception and produces a result. This is thedouble
-consuming primitive specialization forFunctionWithException
.General contract
R apply(double value) throws E
- The functional method.- uncheck - Return a
DoubleFunction<R>
- lift - Return a
DoubleFunction<Optional<R>>
- ignore - Return a
DoubleFunction<R>
- See Also:
DoubleFunction
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description R
apply(double value)
Applies this function to the given argument.static <R,E extends Exception>
DoubleFunctionWithException<R,E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.default DoubleFunction<R>
ignore()
Converts thisDoubleFunctionWithException
to a liftedDoubleFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <R,E extends Exception>
DoubleFunction<R>ignored(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
returningnull
in case of exception.static <R,E extends Exception>
DoubleFunction<R>ignored(DoubleFunctionWithException<R,E> function, R defaultValue)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
returning a default value in case of exception.default DoubleFunction<Optional<R>>
lift()
Converts thisDoubleFunctionWithException
to a liftedDoubleFunction
usingOptional
as return value.static <R,E extends Exception>
DoubleFunction<Optional<R>>lifted(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
usingOptional
as return value.default DoubleFunction<CompletionStage<R>>
stage()
Convert thisDoubleFunctionWithException
to a liftedDoubleFunction
returningCompletionStage
as return value.static <R,E extends Exception>
DoubleFunction<CompletionStage<R>>staged(DoubleFunctionWithException<R,E> function)
Convert thisDoubleFunctionWithException
to a liftedDoubleFunction
returnCompletionStage
as return value.default DoubleFunction<R>
uncheck()
Converts thisDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
.static <R,E extends Exception>
DoubleFunction<R>unchecked(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
.static <R,E extends Exception>
DoubleFunction<R>unchecked(DoubleFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ObjectReturnExceptionHandlerSupport
defaultValue, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
apply
R apply(double value) throws E extends Exception
Applies this function to the given argument.- Parameters:
value
- the function argument- Returns:
- the function result
- Throws:
E
- any exceptionE extends Exception
- See Also:
DoubleFunction.apply(double)
-
uncheck
default DoubleFunction<R> uncheck()
Converts thisDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunctionWithException<R,E extends Exception>>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(DoubleFunctionWithException)
,unchecked(DoubleFunctionWithException, Function)
-
lift
default DoubleFunction<Optional<R>> lift()
Converts thisDoubleFunctionWithException
to a liftedDoubleFunction
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunctionWithException<R,E extends Exception>>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
lifted(DoubleFunctionWithException)
-
ignore
default DoubleFunction<R> ignore()
Converts thisDoubleFunctionWithException
to a liftedDoubleFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunctionWithException<R,E extends Exception>>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(DoubleFunctionWithException)
-
stage
default DoubleFunction<CompletionStage<R>> stage()
Convert thisDoubleFunctionWithException
to a liftedDoubleFunction
returningCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<DoubleFunction<R>,DoubleFunction<Optional<R>>,DoubleFunction<CompletionStage<R>>,R,DoubleFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
staged(DoubleFunctionWithException)
-
failing
static <R,E extends Exception> DoubleFunctionWithException<R,E> failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.- Type Parameters:
R
- the type of the result of the functionE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a function that always throw exception
-
unchecked
static <R,E extends Exception> DoubleFunction<R> unchecked(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if function is null- See Also:
uncheck()
,unchecked(DoubleFunctionWithException, Function)
-
unchecked
static <R,E extends Exception> DoubleFunction<R> unchecked(DoubleFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aDoubleFunctionWithException
to aDoubleFunction
that wraps toRuntimeException
by using the provided mapping function.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked function
- Throws:
NullPointerException
- if function or exceptionMapper is null- See Also:
uncheck()
,unchecked(DoubleFunctionWithException)
-
lifted
static <R,E extends Exception> DoubleFunction<Optional<R>> lifted(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
usingOptional
as return value.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
lift()
-
ignored
static <R,E extends Exception> DoubleFunction<R> ignored(DoubleFunctionWithException<R,E> function)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
returningnull
in case of exception.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
ignore()
-
ignored
static <R,E extends Exception> DoubleFunction<R> ignored(DoubleFunctionWithException<R,E> function, R defaultValue)
Converts aDoubleFunctionWithException
to a liftedDoubleFunction
returning a default value in case of exception.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifteddefaultValue
- the default value in case of error.- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- Since:
- 3.0.0
- See Also:
ignore()
,ignored(DoubleFunctionWithException)
-
staged
static <R,E extends Exception> DoubleFunction<CompletionStage<R>> staged(DoubleFunctionWithException<R,E> function)
Convert thisDoubleFunctionWithException
to a liftedDoubleFunction
returnCompletionStage
as return value.- Type Parameters:
R
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
stage()
-
-