Interface IntFunctionWithException<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<IntFunction<R>,IntFunction<Optional<R>>,IntFunctionWithException<R,E>>
,ObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<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 IntFunctionWithException<R,E extends Exception> extends ObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<R,E>>
Represents a function that accepts an int-valued argument, may throw exception and produces a result. This is theint
-consuming primitive specialization forFunctionWithException
.General contract
R apply(int value) throws E
- The functional method.- uncheck - Return a
IntFunction<R>
- lift - Return a
IntFunction<Optional<R>>
- ignore - Return a
IntFunction<R>
- See Also:
IntFunction
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description R
apply(int value)
Applies this function to the given argument.static <R,E extends Exception>
IntFunctionWithException<R,E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.default IntFunction<R>
ignore()
Converts thisIntFunctionWithException
to a liftedIntFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <R,E extends Exception>
IntFunction<R>ignored(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to a liftedIntFunction
returningnull
in case of exception.static <R,E extends Exception>
IntFunction<R>ignored(IntFunctionWithException<R,E> function, R defaultValue)
Converts aIntFunctionWithException
to a liftedIntFunction
returning a default value in case of exception.default IntFunction<Optional<R>>
lift()
Converts thisIntFunctionWithException
to a liftedIntFunction
usingOptional
as return value.static <R,E extends Exception>
IntFunction<Optional<R>>lifted(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to a liftedIntFunction
usingOptional
as return value.default IntFunction<CompletionStage<R>>
stage()
Convert thisIntFunctionWithException
to a liftedIntFunction
returningCompletionStage
as return value.static <R,E extends Exception>
IntFunction<CompletionStage<R>>staged(IntFunctionWithException<R,E> function)
Convert thisIntFunctionWithException
to a liftedIntFunction
returningCompletionStage
as return value.default IntFunction<R>
uncheck()
Converts thisIntFunctionWithException
to aIntFunction
that wraps exception toRuntimeException
.static <R,E extends Exception>
IntFunction<R>unchecked(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to aIntFunction
that wraps exception toRuntimeException
.static <R,E extends Exception>
IntFunction<R>unchecked(IntFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aIntFunctionWithException
to aIntFunction
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(int 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:
IntFunction.apply(int)
-
uncheck
default IntFunction<R> uncheck()
Converts thisIntFunctionWithException
to aIntFunction
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunctionWithException<R,E extends Exception>>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<R,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(IntFunctionWithException)
,unchecked(IntFunctionWithException, Function)
-
lift
default IntFunction<Optional<R>> lift()
Converts thisIntFunctionWithException
to a liftedIntFunction
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunctionWithException<R,E extends Exception>>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
lifted(IntFunctionWithException)
-
ignore
default IntFunction<R> ignore()
Converts thisIntFunctionWithException
to a liftedIntFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunctionWithException<R,E extends Exception>>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<R,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(IntFunctionWithException)
-
stage
default IntFunction<CompletionStage<R>> stage()
Convert thisIntFunctionWithException
to a liftedIntFunction
returningCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<IntFunction<R>,IntFunction<Optional<R>>,IntFunction<CompletionStage<R>>,R,IntFunctionWithException<R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
staged(IntFunctionWithException)
-
failing
static <R,E extends Exception> IntFunctionWithException<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> IntFunction<R> unchecked(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to aIntFunction
that wraps exception 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(IntFunctionWithException, Function)
-
unchecked
static <R,E extends Exception> IntFunction<R> unchecked(IntFunctionWithException<R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aIntFunctionWithException
to aIntFunction
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(IntFunctionWithException)
-
lifted
static <R,E extends Exception> IntFunction<Optional<R>> lifted(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to a liftedIntFunction
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> IntFunction<R> ignored(IntFunctionWithException<R,E> function)
Converts aIntFunctionWithException
to a liftedIntFunction
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> IntFunction<R> ignored(IntFunctionWithException<R,E> function, R defaultValue)
Converts aIntFunctionWithException
to a liftedIntFunction
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 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(IntFunctionWithException)
-
staged
static <R,E extends Exception> IntFunction<CompletionStage<R>> staged(IntFunctionWithException<R,E> function)
Convert thisIntFunctionWithException
to a liftedIntFunction
returningCompletionStage
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()
-
-