Interface LongFunctionWithException<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<LongFunction<R>,LongFunction<Optional<R>>,LongFunctionWithException<R,E>>
,ObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<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 LongFunctionWithException<R,E extends Exception> extends ObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<R,E>>
Represents a function that accepts a long-valued argument, may throw exception and produces a result. This is thelong
-consuming primitive specialization forFunctionWithException
.General contract
R apply(long value) throws E
- The functional method.- uncheck - Return a
LongFunction<R>
- lift - Return a
LongFunction<Optional<R>>
- ignore - Return a
LongFunction<R>
- See Also:
LongFunction
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description R
apply(long value)
Applies this function to the given argument.static <R,E extends Exception>
LongFunctionWithException<R,E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.default LongFunction<R>
ignore()
Converts thisLongFunctionWithException
to a liftedLongFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <R,E extends Exception>
LongFunction<R>ignored(LongFunctionWithException<R,E> function)
Converts aLongFunctionWithException
to a liftedLongFunction
returningnull
in case of exception.static <R,E extends Exception>
LongFunction<R>ignored(LongFunctionWithException<R,E> function, R defaultValue)
Converts aLongFunctionWithException
to a liftedLongFunction
returning a default value in case of exception.default LongFunction<Optional<R>>
lift()
Converts thisLongFunctionWithException
to a liftedLongFunction
usingOptional
as return value.static <R,E extends Exception>
LongFunction<Optional<R>>lifted(LongFunctionWithException<R,E> function)
Converts aLongFunctionWithException
to a liftedFunction
usingOptional
as return value.default LongFunction<CompletionStage<R>>
stage()
Convert thisLongFunctionWithException
to a liftedLongFunction
returningCompletionStage
as return value.static <R,E extends Exception>
LongFunction<CompletionStage<R>>staged(LongFunctionWithException<R,E> function)
Convert thisLongFunctionWithException
to a liftedLongFunction
returnCompletionStage
as return value.default LongFunction<R>
uncheck()
Converts thisLongFunctionWithException
to aLongFunction
that wraps exception toRuntimeException
.static <R,E extends Exception>
LongFunction<R>unchecked(LongFunctionWithException<R,E> function)
Converts aFunctionWithException
to aLongFunction
that wraps toRuntimeException
.static <R,E extends Exception>
LongFunction<R>unchecked(LongFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aLongFunctionWithException
to aLongFunction
that wraps exception 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(long 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:
LongFunction.apply(long)
-
uncheck
default LongFunction<R> uncheck()
Converts thisLongFunctionWithException
to aLongFunction
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunctionWithException<R,E extends Exception>>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<R,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(LongFunctionWithException)
,unchecked(LongFunctionWithException, Function)
-
lift
default LongFunction<Optional<R>> lift()
Converts thisLongFunctionWithException
to a liftedLongFunction
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunctionWithException<R,E extends Exception>>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
lifted(LongFunctionWithException)
-
ignore
default LongFunction<R> ignore()
Converts thisLongFunctionWithException
to a liftedLongFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunctionWithException<R,E extends Exception>>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<R,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(LongFunctionWithException)
-
stage
default LongFunction<CompletionStage<R>> stage()
Convert thisLongFunctionWithException
to a liftedLongFunction
returningCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<LongFunction<R>,LongFunction<Optional<R>>,LongFunction<CompletionStage<R>>,R,LongFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
staged(LongFunctionWithException)
-
failing
static <R,E extends Exception> LongFunctionWithException<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> LongFunction<R> unchecked(LongFunctionWithException<R,E> function)
Converts aFunctionWithException
to aLongFunction
that wraps toRuntimeException
.- Type Parameters:
R
- the type of the output object to 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(LongFunctionWithException, Function)
-
unchecked
static <R,E extends Exception> LongFunction<R> unchecked(LongFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aLongFunctionWithException
to aLongFunction
that wraps exception 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(LongFunctionWithException)
-
lifted
static <R,E extends Exception> LongFunction<Optional<R>> lifted(LongFunctionWithException<R,E> function)
Converts aLongFunctionWithException
to a liftedFunction
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> LongFunction<R> ignored(LongFunctionWithException<R,E> function)
Converts aLongFunctionWithException
to a liftedLongFunction
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> LongFunction<R> ignored(LongFunctionWithException<R,E> function, R defaultValue)
Converts aLongFunctionWithException
to a liftedLongFunction
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 value to be returned in case of exception- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- Since:
- 3.0.0
- See Also:
ignore()
,ignored(LongFunctionWithException)
-
staged
static <R,E extends Exception> LongFunction<CompletionStage<R>> staged(LongFunctionWithException<R,E> function)
Convert thisLongFunctionWithException
to a liftedLongFunction
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()
-
-