Interface UnaryOperatorWithException<T,E extends Exception>
-
- Type Parameters:
T
- the type of the operand and result of the operator
- All Superinterfaces:
ExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,FunctionWithException<T,T,E>>
,FunctionWithException<T,T,E>
,ObjectReturnExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,Function<T,CompletionStage<T>>,T,FunctionWithException<T,T,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 UnaryOperatorWithException<T,E extends Exception> extends FunctionWithException<T,T,E>
Represents an operation on a single operand that produces a result of the same type as its operand. This is a specialization ofFunctionWithException
for the case where the operand and result are of the same type.As this interface must return the same type of the input, a lifted version which returns
Optional
is not possible.General contract
T apply(T t) throws E
- The functional method.- uncheck - Return a
UnaryOperator<T>
- lift - Return a
Function<T,Optional<T>
- ignore - Return a
UnaryOperator<T>
- See Also:
FunctionWithException
,UnaryOperator
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default UnaryOperatorWithException<T,E>
documented(Supplier<String> toString)
Add atoString
method to the existing interface based on the receivedSupplier
.static <T,E extends Exception>
UnaryOperatorWithException<T,E>failing(Supplier<E> exceptionBuilder)
Returns a unary operator that always throw exception.static <T,E extends Exception>
UnaryOperatorWithException<T,E>identity()
Returns a unary operator that always returns its input argument.default UnaryOperator<T>
ignore()
Converts thisUnaryOperatorWithException
to a liftedUnaryOperator
returningnull
in case of exception.static <T,E extends Exception>
UnaryOperator<T>ignored(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to a liftedUnaryOperator
returningnull
in case of exception.static <T,E extends Exception>
Function<T,Optional<T>>lifted(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to a liftedFunction
returningOptional
.default UnaryOperator<T>
uncheck()
Converts thisUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
.static <T,E extends Exception>
UnaryOperator<T>unchecked(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
.static <T,E extends Exception>
UnaryOperator<T>unchecked(UnaryOperatorWithException<T,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.FunctionWithException
andThen, apply, asBiFunction, asCallable, asConsumer, asRunnable, asSupplier, compose, lift, stage
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ObjectReturnExceptionHandlerSupport
defaultValue, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
uncheck
default UnaryOperator<T> uncheck()
Converts thisUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,FunctionWithException<T,T,E extends Exception>>
- Specified by:
uncheck
in interfaceFunctionWithException<T,T,E extends Exception>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,Function<T,CompletionStage<T>>,T,FunctionWithException<T,T,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
FunctionWithException.unchecked(FunctionWithException)
,FunctionWithException.unchecked(FunctionWithException, Function)
-
ignore
default UnaryOperator<T> ignore()
Converts thisUnaryOperatorWithException
to a liftedUnaryOperator
returningnull
in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,FunctionWithException<T,T,E extends Exception>>
- Specified by:
ignore
in interfaceFunctionWithException<T,T,E extends Exception>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,Function<T,CompletionStage<T>>,T,FunctionWithException<T,T,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
FunctionWithException.ignored(FunctionWithException)
-
documented
default UnaryOperatorWithException<T,E> documented(Supplier<String> toString)
Description copied from interface:ExceptionHandlerSupport
Add atoString
method to the existing interface based on the receivedSupplier
.- Specified by:
documented
in interfaceExceptionHandlerSupport<Function<T,T>,Function<T,Optional<T>>,FunctionWithException<T,T,E extends Exception>>
- Parameters:
toString
- the supplier to be used- Returns:
- a new interface, with
toString
using the received supplier.
-
identity
static <T,E extends Exception> UnaryOperatorWithException<T,E> identity()
Returns a unary operator that always returns its input argument.- Type Parameters:
T
- the type of the input and output of the operatorE
- the type of the potential exception- Returns:
- a unary operator that always returns its input argument
- See Also:
Function.identity()
-
failing
static <T,E extends Exception> UnaryOperatorWithException<T,E> failing(Supplier<E> exceptionBuilder)
Returns a unary operator that always throw exception.- Type Parameters:
T
- the type of the input and output of the operatorE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a function that always throw exception
-
unchecked
static <T,E extends Exception> UnaryOperator<T> unchecked(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
.- Type Parameters:
T
- the type of the input and output of the operatorE
- 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(UnaryOperatorWithException, Function)
-
unchecked
static <T,E extends Exception> UnaryOperator<T> unchecked(UnaryOperatorWithException<T,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aUnaryOperatorWithException
to aUnaryOperator
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
T
- the type of the input and output of the operatorE
- the type of the potential exception- Parameters:
function
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if function or exceptionMapper is null- See Also:
uncheck()
,unchecked(UnaryOperatorWithException)
-
lifted
static <T,E extends Exception> Function<T,Optional<T>> lifted(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to a liftedFunction
returningOptional
.- Type Parameters:
T
- the type of the input and output of the operatorE
- 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 <T,E extends Exception> UnaryOperator<T> ignored(UnaryOperatorWithException<T,E> function)
Converts aUnaryOperatorWithException
to a liftedUnaryOperator
returningnull
in case of exception.- Type Parameters:
T
- the type of the input and output of the operatorE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
ignore()
-
-