Interface IntUnaryOperatorWithException<E extends Exception>
-
- Type Parameters:
E
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<IntUnaryOperator,IntUnaryOperator,IntUnaryOperatorWithException<E>>
,PrimitiveReturnExceptionHandlerSupport<IntUnaryOperator,IntUnaryOperatorWithException<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 IntUnaryOperatorWithException<E extends Exception> extends PrimitiveReturnExceptionHandlerSupport<IntUnaryOperator,IntUnaryOperatorWithException<E>>
Represents an operation on a singleint
-valued operand that produces anint
-valued result and may throws exception. This is the primitive type specialization ofUnaryOperatorWithException
forint
.General contract
int applyAsInt(int operand) throws E
- The functional method.- uncheck - Return a
IntUnaryOperator
- lift - Return a
IntUnaryOperator
- ignore - Return a
IntUnaryOperator
- See Also:
IntUnaryOperator
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default IntUnaryOperatorWithException<E>
andThen(IntUnaryOperatorWithException<? extends E> after)
Returns a composed operator that first applies this operator to its input, and then applies theafter
operator to the result.int
applyAsInt(int operand)
Applies this operator to the given operand.default IntUnaryOperatorWithException<E>
compose(IntUnaryOperatorWithException<? extends E> before)
Returns a composed operator that first applies thebefore
operator to its input, and then applies this operator to the result.default int
defaultValue()
Defines the default value returned by the ignore and ignored method.static <E extends Exception>
IntUnaryOperatorWithException<E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.static <E extends Exception>
IntUnaryOperatorWithException<E>identity()
Returns a unary operator that always returns its input argument.static <E extends Exception>
IntUnaryOperatorignored(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
returning0
in case of exception.static <E extends Exception>
IntUnaryOperatorignored(IntUnaryOperatorWithException<E> function, int defaultValue)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
returning a default value in case of exception.static <E extends Exception>
IntUnaryOperatorlifted(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
using0
as return value in case of error.static <E extends Exception>
IntUnaryOperatorunchecked(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorException
to aIntUnaryOperator
that wraps exception toRuntimeException
.static <E extends Exception>
IntUnaryOperatorunchecked(IntUnaryOperatorWithException<E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aIntUnaryOperatorWithException
to aIntUnaryOperator
that wraps exception toRuntimeException
by using the provided mapping function.default IntUnaryOperator
uncheckOrIgnore(boolean uncheck)
Used internally to implements the ignore or uncheck operation.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.PrimitiveReturnExceptionHandlerSupport
ignore, lift, uncheck
-
-
-
-
Method Detail
-
applyAsInt
int applyAsInt(int operand) throws E extends Exception
Applies this operator to the given operand.- Parameters:
operand
- the operand- Returns:
- the operator result
- Throws:
E
- any exceptionE extends Exception
- See Also:
IntUnaryOperator.applyAsInt(int)
-
uncheckOrIgnore
default IntUnaryOperator uncheckOrIgnore(boolean uncheck)
Description copied from interface:PrimitiveReturnExceptionHandlerSupport
Used internally to implements the ignore or uncheck operation.- Specified by:
uncheckOrIgnore
in interfacePrimitiveReturnExceptionHandlerSupport<IntUnaryOperator,IntUnaryOperatorWithException<E extends Exception>>
- Parameters:
uncheck
- create unchecked version of the function when true, else ignored version.- Returns:
- the function
-
compose
default IntUnaryOperatorWithException<E> compose(IntUnaryOperatorWithException<? extends E> before)
Returns a composed operator that first applies thebefore
operator to its input, and then applies this operator to the result. If evaluation of either operator throws an exception, it is relayed to the caller of the composed operator.- Parameters:
before
- the operator to apply before this operator is applied- Returns:
- a composed operator that first applies the
before
operator and then applies this operator - Throws:
NullPointerException
- if before is null- See Also:
andThen(IntUnaryOperatorWithException)
-
andThen
default IntUnaryOperatorWithException<E> andThen(IntUnaryOperatorWithException<? extends E> after)
Returns a composed operator that first applies this operator to its input, and then applies theafter
operator to the result. If evaluation of either operator throws an exception, it is relayed to the caller of the composed operator.- Parameters:
after
- the operator to apply after this operator is applied- Returns:
- a composed operator that first applies this operator and then applies
the
after
operator - Throws:
NullPointerException
- if after is null- See Also:
compose(IntUnaryOperatorWithException)
-
identity
static <E extends Exception> IntUnaryOperatorWithException<E> identity()
Returns a unary operator that always returns its input argument.- Type Parameters:
E
- the exception that may be thrown- Returns:
- a unary operator that always returns its input argument
-
failing
static <E extends Exception> IntUnaryOperatorWithException<E> failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.- Type Parameters:
E
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a function that always throw exception
-
unchecked
static <E extends Exception> IntUnaryOperator unchecked(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorException
to aIntUnaryOperator
that wraps exception toRuntimeException
.- Type Parameters:
E
- the type of the potential exception- Parameters:
function
- to be unchecked- Returns:
- the unchecked function
- Throws:
NullPointerException
- if function is null- See Also:
PrimitiveReturnExceptionHandlerSupport.uncheck()
,unchecked(IntUnaryOperatorWithException, Function)
-
unchecked
static <E extends Exception> IntUnaryOperator unchecked(IntUnaryOperatorWithException<E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aIntUnaryOperatorWithException
to aIntUnaryOperator
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
E
- 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:
PrimitiveReturnExceptionHandlerSupport.uncheck()
,unchecked(IntUnaryOperatorWithException)
-
lifted
static <E extends Exception> IntUnaryOperator lifted(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
using0
as return value in case of error.- Type Parameters:
E
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
PrimitiveReturnExceptionHandlerSupport.lift()
-
ignored
static <E extends Exception> IntUnaryOperator ignored(IntUnaryOperatorWithException<E> function)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
returning0
in case of exception.- Type Parameters:
E
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
PrimitiveReturnExceptionHandlerSupport.ignore()
-
ignored
static <E extends Exception> IntUnaryOperator ignored(IntUnaryOperatorWithException<E> function, int defaultValue)
Converts aIntUnaryOperatorWithException
to a liftedIntUnaryOperator
returning a default value in case of exception.- Type Parameters:
E
- the type of the potential exception- Parameters:
function
- to be lifteddefaultValue
- value in case of exception- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- Since:
- 3.0.0
- See Also:
PrimitiveReturnExceptionHandlerSupport.ignore()
,ignored(IntUnaryOperatorWithException)
-
defaultValue
default int defaultValue()
Defines the default value returned by the ignore and ignored method.- Returns:
- the default value for the ignore/ignored method.
- Since:
- 3.0.0
-
-