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 of UnaryOperator.
    • Method Detail

      • onErrorThrowAsChecked

        default <E extends ThrowableThrowingUnaryOperator<T,​E> onErrorThrowAsChecked​(Function<? super X,​? extends E> errorMapper)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorThrowAsChecked in interface ThrowingFunction<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 RuntimeExceptionUnaryOperator<T> onErrorThrowAsUnchecked​(Function<? super X,​? extends E> errorMapper)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorThrowAsUnchecked in interface ThrowingFunction<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 ThrowableThrowingUnaryOperator<T,​E> onErrorHandleChecked​(ThrowingFunction<? super X,​? extends T,​? extends E> errorHandler)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorHandleChecked in interface ThrowingFunction<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: ThrowingFunction
        Returns 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:
        onErrorHandleUnchecked in interface ThrowingFunction<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 ThrowableThrowingUnaryOperator<T,​E> onErrorApplyChecked​(ThrowingFunction<? super T,​? extends T,​? extends E> fallback)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorApplyChecked in interface ThrowingFunction<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 fallback function if this function throws any checked exception.
      • onErrorApplyUnchecked

        default UnaryOperator<T> onErrorApplyUnchecked​(Function<? super T,​? extends T> fallback)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorApplyUnchecked in interface ThrowingFunction<T,​T,​X extends Throwable>
        Parameters:
        fallback - The function to invoke if this function throws any checked exception.
        Returns:
        A function that invokes the fallback function if this function throws any checked exception.
      • onErrorGetChecked

        default <E extends ThrowableThrowingUnaryOperator<T,​E> onErrorGetChecked​(ThrowingSupplier<? extends T,​? extends E> fallback)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorGetChecked in interface ThrowingFunction<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 fallback supplier if this function throws any checked exception.
      • onErrorGetUnchecked

        default UnaryOperator<T> onErrorGetUnchecked​(Supplier<? extends T> fallback)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorGetUnchecked in interface ThrowingFunction<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 fallback supplier if this function throws any checked exception.
      • onErrorReturn

        default UnaryOperator<T> onErrorReturn​(T fallback)
        Description copied from interface: ThrowingFunction
        Returns 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:
        onErrorReturn in interface ThrowingFunction<T,​T,​X extends Throwable>
        Parameters:
        fallback - The value to return if this function throws any checked exception.
        Returns:
        A function that returns the fallback value if this function throws any checked exception.
      • of

        static <T,​X extends ThrowableThrowingUnaryOperator<T,​X> of​(ThrowingUnaryOperator<T,​X> operator)
        Factory method for turning ThrowingUnaryOperator-shaped lambdas into ThrowingUnaryOperators.
        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 as ThrowingUnaryOperator.
        Returns:
        The given lambda as a ThrowingUnaryOperator.
        Throws:
        NullPointerException - If operator is null.
      • identity

        static <T,​X extends ThrowableThrowingUnaryOperator<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 the operator unary operator to its input. Any checked exception thrown by the operator unary operator is wrapped in an UncheckedException.
        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 - If operator is null.
      • checked

        static <T,​X extends ThrowableThrowingUnaryOperator<T,​X> checked​(UnaryOperator<T> operator)
        Returns a unary operator that applies the operator unary operator to its input. Any unchecked exception thrown by the operator unary operator is relayed to the caller. This method allows existing UnaryOperator instances to be used where ThrowingUnaryOperator is 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 - If operator is null.
      • checked

        static <T,​X extends ThrowableThrowingUnaryOperator<T,​X> checked​(UnaryOperator<T> operator,
                                                                                      Class<X> errorType)
        Returns a unary operator that applies the operator unary operator to its input. Any UncheckedException thrown by the operator unary operator is unwrapped if its cause is an instance of errorType, 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 - If operator or errorType is null.