Interface ThrowingUnaryOperator<T,X extends Throwable>
-
- Type Parameters:
T- The type of the operand and result of the operator.X- The type of checked exception that can be thrown.
- All Superinterfaces:
ThrowingFunction<T,T,X>
- 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 ThrowingUnaryOperator<T,X extends Throwable> extends ThrowingFunction<T,T,X>
Represents an operation on a single operand that produces a result of the same type as its operand. This is a checked-exception throwing equivalent ofUnaryOperator.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <T,X extends Throwable>
ThrowingUnaryOperator<T,X>checked(UnaryOperator<T> operator)Returns a unary operator that applies theoperatorunary operator to its input.static <T,X extends Throwable>
ThrowingUnaryOperator<T,X>checked(UnaryOperator<T> operator, Class<X> errorType)Returns a unary operator that applies theoperatorunary operator to its input.static <T,X extends Throwable>
ThrowingUnaryOperator<T,X>identity()Returns a unary operator that always returns its input argument.static <T,X extends Throwable>
ThrowingUnaryOperator<T,X>of(ThrowingUnaryOperator<T,X> operator)Factory method for turningThrowingUnaryOperator-shaped lambdas intoThrowingUnaryOperators.default <E extends Throwable>
ThrowingUnaryOperator<T,E>onErrorApplyChecked(ThrowingFunction<? super T,? extends T,? extends E> fallback)Returns a function that applies this function to its input.default UnaryOperator<T>onErrorApplyUnchecked(Function<? super T,? extends T> fallback)Returns a function that applies this function to its input.default <E extends Throwable>
ThrowingUnaryOperator<T,E>onErrorGetChecked(ThrowingSupplier<? extends T,? extends E> fallback)Returns a function that applies this function to its input.default UnaryOperator<T>onErrorGetUnchecked(Supplier<? extends T> fallback)Returns a function that applies this function to its input.default <E extends Throwable>
ThrowingUnaryOperator<T,E>onErrorHandleChecked(ThrowingFunction<? super X,? extends T,? extends E> errorHandler)Returns a function that applies this function to its input.default UnaryOperator<T>onErrorHandleUnchecked(Function<? super X,? extends T> errorHandler)Returns a function that applies this function to its input.default UnaryOperator<T>onErrorReturn(T fallback)Returns a function that applies this function to its input.default <E extends Throwable>
ThrowingUnaryOperator<T,E>onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)Returns a function that applies this function to its input.default <E extends RuntimeException>
UnaryOperator<T>onErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)Returns a function that applies this function to its input.default UnaryOperator<T>unchecked()Returns a function that applies this function to its input.static <T> UnaryOperator<T>unchecked(ThrowingUnaryOperator<T,?> operator)Returns a unary operator that applies theoperatorunary operator to its input.-
Methods inherited from interface com.github.robtimus.function.throwing.ThrowingFunction
andThen, apply, compose
-
-
-
-
Method Detail
-
onErrorThrowAsChecked
default <E extends Throwable> ThrowingUnaryOperator<T,E> onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. Any checked exception thrown by this function is transformed using the given error mapper, and the returned function throws the transformation result.- Specified by:
onErrorThrowAsCheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Type Parameters:
E- The type of checked exception to transform to.- Parameters:
errorMapper- The function to use to transform any checked exception thrown by this function.- Returns:
- A function that transforms any thrown checked exception.
-
onErrorThrowAsUnchecked
default <E extends RuntimeException> UnaryOperator<T> onErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. Any checked exception thrown by this function is transformed using the given error mapper, and the returned function throws the transformation result.- Specified by:
onErrorThrowAsUncheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Type Parameters:
E- The type of unchecked exception to transform to.- Parameters:
errorMapper- The function to use to transform any checked exception thrown by this function.- Returns:
- A function that transforms any thrown checked exception.
-
onErrorHandleChecked
default <E extends Throwable> ThrowingUnaryOperator<T,E> onErrorHandleChecked(ThrowingFunction<? super X,? extends T,? extends E> errorHandler)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. Any checked exception thrown by this function is transformed using the given error handler, and the returned function returns the transformation result.- Specified by:
onErrorHandleCheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Type Parameters:
E- The type of checked exception that can be thrown by the given error handler.- Parameters:
errorHandler- The function to use to transform any checked exception thrown by this function.- Returns:
- A function that transforms any thrown checked exception.
-
onErrorHandleUnchecked
default UnaryOperator<T> onErrorHandleUnchecked(Function<? super X,? extends T> errorHandler)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. Any checked exception thrown by this function is transformed using the given error handler, and the returned function returns the transformation result.- Specified by:
onErrorHandleUncheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Parameters:
errorHandler- The function to use to transform any checked exception thrown by this function.- Returns:
- A function that transforms any thrown checked exception.
-
onErrorApplyChecked
default <E extends Throwable> ThrowingUnaryOperator<T,E> onErrorApplyChecked(ThrowingFunction<? super T,? extends T,? extends E> fallback)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. If this function throws any checked exception, it is discarded and the given fallback function is invoked.- Specified by:
onErrorApplyCheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Type Parameters:
E- The type of checked exception that can be thrown by the given fallback function.- Parameters:
fallback- The function to invoke if this function throws any checked exception.- Returns:
- A function that invokes the
fallbackfunction if this function throws any checked exception.
-
onErrorApplyUnchecked
default UnaryOperator<T> onErrorApplyUnchecked(Function<? super T,? extends T> fallback)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. If this function throws any checked exception, it is discarded and the given fallback function is invoked.- Specified by:
onErrorApplyUncheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Parameters:
fallback- The function to invoke if this function throws any checked exception.- Returns:
- A function that invokes the
fallbackfunction if this function throws any checked exception.
-
onErrorGetChecked
default <E extends Throwable> ThrowingUnaryOperator<T,E> onErrorGetChecked(ThrowingSupplier<? extends T,? extends E> fallback)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. If this function throws any checked exception, it is discarded and the given fallback supplier is invoked.- Specified by:
onErrorGetCheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Type Parameters:
E- The type of checked exception that can be thrown by the given fallback supplier.- Parameters:
fallback- The supplier to produce the value to return if this function throws any checked exception.- Returns:
- A function that invokes the
fallbacksupplier if this function throws any checked exception.
-
onErrorGetUnchecked
default UnaryOperator<T> onErrorGetUnchecked(Supplier<? extends T> fallback)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. If this function throws any checked exception, it is discarded and the given fallback supplier is invoked.- Specified by:
onErrorGetUncheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Parameters:
fallback- The supplier to produce the value to return if this function throws any checked exception.- Returns:
- A function that invokes the
fallbacksupplier if this function throws any checked exception.
-
onErrorReturn
default UnaryOperator<T> onErrorReturn(T fallback)
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. If this function throws any checked exception, it is discarded and the given fallback value is returned.- Specified by:
onErrorReturnin interfaceThrowingFunction<T,T,X extends Throwable>- Parameters:
fallback- The value to return if this function throws any checked exception.- Returns:
- A function that returns the
fallbackvalue if this function throws any checked exception.
-
unchecked
default UnaryOperator<T> unchecked()
Description copied from interface:ThrowingFunctionReturns a function that applies this function to its input. Any checked exception thrown by this function is wrapped in anUncheckedExceptionwithout a stack trace.- Specified by:
uncheckedin interfaceThrowingFunction<T,T,X extends Throwable>- Returns:
- A function that wraps any checked exception in an
UncheckedException.
-
of
static <T,X extends Throwable> ThrowingUnaryOperator<T,X> of(ThrowingUnaryOperator<T,X> operator)
Factory method for turningThrowingUnaryOperator-shaped lambdas intoThrowingUnaryOperators.- Type Parameters:
T- The type of the operand and result of the operator.X- The type of checked exception that can be thrown.- Parameters:
operator- The lambda to return asThrowingUnaryOperator.- Returns:
- The given lambda as a
ThrowingUnaryOperator. - Throws:
NullPointerException- Ifoperatorisnull.
-
identity
static <T,X extends Throwable> ThrowingUnaryOperator<T,X> identity()
Returns a unary operator that always returns its input argument.- Type Parameters:
T- The type of the operand and result of the operator.X- The type of checked exception that can be thrown.- Returns:
- A unary operator that always returns its input argument.
-
unchecked
static <T> UnaryOperator<T> unchecked(ThrowingUnaryOperator<T,?> operator)
Returns a unary operator that applies theoperatorunary operator to its input. Any checked exception thrown by theoperatorunary operator is wrapped in anUncheckedException.- Type Parameters:
T- The type of the operand and result of the operator.- Parameters:
operator- The unary operator to apply when the returned unary operator is applied.- Returns:
- A unary operator that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Ifoperatorisnull.
-
checked
static <T,X extends Throwable> ThrowingUnaryOperator<T,X> checked(UnaryOperator<T> operator)
Returns a unary operator that applies theoperatorunary operator to its input. Any unchecked exception thrown by theoperatorunary operator is relayed to the caller. This method allows existingUnaryOperatorinstances to be used whereThrowingUnaryOperatoris expected.- Type Parameters:
T- The type of the operand and result of the operator.X- The type of checked exception that can be thrown.- Parameters:
operator- The unary operator to apply when the returned unary operator is applied.- Returns:
- A unary operator that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Ifoperatorisnull.
-
checked
static <T,X extends Throwable> ThrowingUnaryOperator<T,X> checked(UnaryOperator<T> operator, Class<X> errorType)
Returns a unary operator that applies theoperatorunary operator to its input. AnyUncheckedExceptionthrown by theoperatorunary operator is unwrapped if its cause is an instance oferrorType, otherwise it is relayed to the caller.- Type Parameters:
T- The type of the operand and result of the operator.X- The type of checked exception that can be thrown.- Parameters:
operator- The unary operator to apply when the returned unary operator is applied.errorType- The type of checked exception that can be thrown.- Returns:
- A unary operator that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- IfoperatororerrorTypeisnull.
-
-