Interface LongUnaryOperatorWithException<E extends Exception>
-
- Type Parameters:
E
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperator,LongUnaryOperatorWithException<E>>
,PrimitiveReturnExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperatorWithException<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 LongUnaryOperatorWithException<E extends Exception> extends PrimitiveReturnExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperatorWithException<E>>
Represents an operation on a singlelong
-valued operand, may thrown exception and that produces along
-valued result. This is the primitive type specialization ofUnaryOperatorWithException
forlong
.General contract
long applyAsLong(long operand) throws E
- The functional method.- uncheck - Return a
LongUnaryOperator
- lift - Return a
LongUnaryOperator
- ignore - Return a
LongUnaryOperator
- See Also:
LongUnaryOperator
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default LongUnaryOperatorWithException<E>
andThen(LongUnaryOperatorWithException<? extends E> after)
Returns a composed operator that first applies this operator to its input, and then applies theafter
operator to the result.long
applyAsLong(long operand)
Applies this operator to the given operand.default LongUnaryOperatorWithException<E>
compose(LongUnaryOperatorWithException<? extends E> before)
Returns a composed operator that first applies thebefore
operator to its input, and then applies this operator to the result.default long
defaultValue()
Defines the default value returned by the ignore and ignored method.static <E extends Exception>
LongUnaryOperatorWithException<E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.static <E extends Exception>
LongUnaryOperatorWithException<E>identity()
Returns a unary operator that always returns its input argument.default LongUnaryOperator
ignore()
Converts thisLongUnaryOperatorWithException
to a liftedLongUnaryOperator
returning zero in case of exception.static <E extends Exception>
LongUnaryOperatorignored(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
returning0
in case of exception.static <E extends Exception>
LongUnaryOperatorignored(LongUnaryOperatorWithException<E> function, long defaultValue)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
returning a default value in case of exception.static <E extends Exception>
LongUnaryOperatorlifted(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
using0
as return value in case of error.default LongUnaryOperator
uncheck()
Converts thisLongUnaryOperatorWithException
to aLongUnaryOperator
that convert exception toRuntimeException
.static <E extends Exception>
LongUnaryOperatorunchecked(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorException
to aLongUnaryOperator
that wraps exception toRuntimeException
.static <E extends Exception>
LongUnaryOperatorunchecked(LongUnaryOperatorWithException<E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aLongUnaryOperatorWithException
to aLongUnaryOperator
that wraps exception toRuntimeException
by using the provided mapping function.default LongUnaryOperator
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
lift
-
-
-
-
Method Detail
-
applyAsLong
long applyAsLong(long 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:
LongUnaryOperator.applyAsLong(long)
-
uncheckOrIgnore
default LongUnaryOperator uncheckOrIgnore(boolean uncheck)
Description copied from interface:PrimitiveReturnExceptionHandlerSupport
Used internally to implements the ignore or uncheck operation.- Specified by:
uncheckOrIgnore
in interfacePrimitiveReturnExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperatorWithException<E extends Exception>>
- Parameters:
uncheck
- create unchecked version of the function when true, else ignored version.- Returns:
- the function
-
uncheck
default LongUnaryOperator uncheck()
Converts thisLongUnaryOperatorWithException
to aLongUnaryOperator
that convert exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperator,LongUnaryOperatorWithException<E extends Exception>>
- Specified by:
uncheck
in interfacePrimitiveReturnExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperatorWithException<E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(LongUnaryOperatorWithException)
,unchecked(LongUnaryOperatorWithException, Function)
-
ignore
default LongUnaryOperator ignore()
Converts thisLongUnaryOperatorWithException
to a liftedLongUnaryOperator
returning zero in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperator,LongUnaryOperatorWithException<E extends Exception>>
- Specified by:
ignore
in interfacePrimitiveReturnExceptionHandlerSupport<LongUnaryOperator,LongUnaryOperatorWithException<E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(LongUnaryOperatorWithException)
-
compose
default LongUnaryOperatorWithException<E> compose(LongUnaryOperatorWithException<? 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(LongUnaryOperatorWithException)
-
andThen
default LongUnaryOperatorWithException<E> andThen(LongUnaryOperatorWithException<? 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(LongUnaryOperatorWithException)
-
identity
static <E extends Exception> LongUnaryOperatorWithException<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> LongUnaryOperatorWithException<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> LongUnaryOperator unchecked(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorException
to aLongUnaryOperator
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:
uncheck()
,unchecked(LongUnaryOperatorWithException, Function)
-
unchecked
static <E extends Exception> LongUnaryOperator unchecked(LongUnaryOperatorWithException<E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aLongUnaryOperatorWithException
to aLongUnaryOperator
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:
uncheck()
,unchecked(LongUnaryOperatorWithException)
-
lifted
static <E extends Exception> LongUnaryOperator lifted(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
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> LongUnaryOperator ignored(LongUnaryOperatorWithException<E> function)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
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:
ignore()
-
ignored
static <E extends Exception> LongUnaryOperator ignored(LongUnaryOperatorWithException<E> function, long defaultValue)
Converts aLongUnaryOperatorWithException
to a liftedLongUnaryOperator
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:
ignore()
,ignored(LongUnaryOperatorWithException)
-
defaultValue
default long 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
-
-