Interface ThrowingBiConsumer<T,U,X extends Throwable>
-
- Type Parameters:
T- The type of the first argument to the operation.U- The type of the second argument to the operation.X- The type of checked exception that can be thrown.
- 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 ThrowingBiConsumer<T,U,X extends Throwable>
Represents an operation that accepts two input arguments and returns no result. This is a checked-exception throwing equivalent ofBiConsumer.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaccept(T t, U u)Performs this operation on the given arguments.default ThrowingBiConsumer<T,U,X>andThen(ThrowingBiConsumer<? super T,? super U,? extends X> after)Returns a composedThrowingBiConsumerthat performs, in sequence, this operation followed by theafteroperation.static <T,U,X extends Throwable>
ThrowingBiConsumer<T,U,X>checked(BiConsumer<? super T,? super U> operation)Returns an operation that performs theoperationoperation to its input.static <T,U,X extends Throwable>
ThrowingBiConsumer<T,U,X>checked(BiConsumer<? super T,? super U> operation, Class<X> errorType)Returns an operation that performs theoperationoperation to its input.static <T,U,X extends Throwable>
ThrowingBiConsumer<T,U,X>of(ThrowingBiConsumer<T,U,X> operation)Factory method for turningThrowingBiConsumer-shaped lambdas intoThrowingBiConsumers.default <E extends Throwable>
ThrowingBiConsumer<T,U,E>onErrorAcceptChecked(ThrowingBiConsumer<? super T,? super U,? extends E> fallback)Returns an operation that performs this operation on its input.default BiConsumer<T,U>onErrorAcceptUnchecked(BiConsumer<? super T,? super U> fallback)Returns an operation that performs this operation on its input.default BiConsumer<T,U>onErrorDiscard()Returns an operation that performs this operation on its input.default <E extends Throwable>
ThrowingBiConsumer<T,U,E>onErrorHandleChecked(ThrowingConsumer<? super X,? extends E> errorHandler)Returns an operation that performs this operation on its input.default BiConsumer<T,U>onErrorHandleUnchecked(Consumer<? super X> errorHandler)Returns an operation that performs this operation on its input.default <E extends Throwable>
ThrowingBiConsumer<T,U,E>onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)Returns an operation that performs this operation on its input.default <E extends RuntimeException>
BiConsumer<T,U>onErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)Returns an operation that performs this operation on its input.default BiConsumer<T,U>unchecked()Returns an operation that performs this operation on its input.static <T,U>
BiConsumer<T,U>unchecked(ThrowingBiConsumer<? super T,? super U,?> operation)Returns an operation that performs theoperationoperation to its input.
-
-
-
Method Detail
-
accept
void accept(T t, U u) throws X extends Throwable
Performs this operation on the given arguments.
-
andThen
default ThrowingBiConsumer<T,U,X> andThen(ThrowingBiConsumer<? super T,? super U,? extends X> after)
Returns a composedThrowingBiConsumerthat performs, in sequence, this operation followed by theafteroperation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, theafteroperation will not be performed.- Parameters:
after- The operation to perform after this operation.- Returns:
- A composed
ThrowingBiConsumerthat performs in sequence this operation followed by theafteroperation. - Throws:
NullPointerException- Ifafterisnull.
-
onErrorThrowAsChecked
default <E extends Throwable> ThrowingBiConsumer<T,U,E> onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is transformed using the given error mapper, and the returned operation throws the transformation result.- 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 operation.- Returns:
- An operation that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorMapperisnull.
-
onErrorThrowAsUnchecked
default <E extends RuntimeException> BiConsumer<T,U> onErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is transformed using the given error mapper, and the returned operation throws the transformation result.- 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 operation.- Returns:
- An operation that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorMapperisnull.
-
onErrorHandleChecked
default <E extends Throwable> ThrowingBiConsumer<T,U,E> onErrorHandleChecked(ThrowingConsumer<? super X,? extends E> errorHandler)
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is handled by the given error handler.- Type Parameters:
E- The type of checked exception that can be thrown by the given error handler.- Parameters:
errorHandler- The operation to perform on any checked exception thrown by this operation.- Returns:
- An operation that handles any thrown checked exception.
- Throws:
NullPointerException- IferrorHandlerisnull.
-
onErrorHandleUnchecked
default BiConsumer<T,U> onErrorHandleUnchecked(Consumer<? super X> errorHandler)
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is handled by the given error handler.- Parameters:
errorHandler- The operation to perform on any checked exception thrown by this operation.- Returns:
- An operation that handles any thrown checked exception.
- Throws:
NullPointerException- IferrorHandlerisnull.
-
onErrorAcceptChecked
default <E extends Throwable> ThrowingBiConsumer<T,U,E> onErrorAcceptChecked(ThrowingBiConsumer<? super T,? super U,? extends E> fallback)
Returns an operation that performs this operation on its input. If this operation throws any checked exception, it is discarded and the given fallback operation is invoked.- Type Parameters:
E- The type of checked exception that can be thrown by the given fallback operation.- Parameters:
fallback- The operation to invoke if this operation throws any checked exception.- Returns:
- An operation that invokes the
fallbackoperation if this operation throws any checked exception. - Throws:
NullPointerException- Iffallbackisnull.
-
onErrorAcceptUnchecked
default BiConsumer<T,U> onErrorAcceptUnchecked(BiConsumer<? super T,? super U> fallback)
Returns an operation that performs this operation on its input. If this operation throws any checked exception, it is discarded and the given fallback operation is invoked.- Parameters:
fallback- The operation to invoke if this operation throws any checked exception.- Returns:
- An operation that invokes the
fallbackoperation if this operation throws any checked exception. - Throws:
NullPointerException- Iffallbackisnull.
-
onErrorDiscard
default BiConsumer<T,U> onErrorDiscard()
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is discarded.- Returns:
- An operation that discards any thrown checked exception.
-
unchecked
default BiConsumer<T,U> unchecked()
Returns an operation that performs this operation on its input. Any checked exception thrown by this operation is wrapped in anUncheckedExceptionwithout a stack trace.- Returns:
- An operation that wraps any checked exception in an
UncheckedException.
-
of
static <T,U,X extends Throwable> ThrowingBiConsumer<T,U,X> of(ThrowingBiConsumer<T,U,X> operation)
Factory method for turningThrowingBiConsumer-shaped lambdas intoThrowingBiConsumers.- Type Parameters:
T- The type of the first argument to the operation.U- The type of the second argument to the operation.X- The type of checked exception that can be thrown.- Parameters:
operation- The lambda to return asThrowingBiConsumer.- Returns:
- The given lambda as a
ThrowingBiConsumer. - Throws:
NullPointerException- Ifoperationisnull.
-
unchecked
static <T,U> BiConsumer<T,U> unchecked(ThrowingBiConsumer<? super T,? super U,?> operation)
Returns an operation that performs theoperationoperation to its input. Any checked exception thrown by theoperationoperation is wrapped in anUncheckedException.- Type Parameters:
T- The type of the first argument to the operation.U- The type of the second argument to the operation.- Parameters:
operation- The operation to perform when the returned operation is performed.- Returns:
- An operation that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Ifoperationisnull.
-
checked
static <T,U,X extends Throwable> ThrowingBiConsumer<T,U,X> checked(BiConsumer<? super T,? super U> operation)
Returns an operation that performs theoperationoperation to its input. Any checked exception thrown by theoperationoperation is relayed to the caller. This method allows existingBiConsumerinstances to be used whereThrowingBiConsumeris expected.- Type Parameters:
T- The type of the first argument to the operation.U- The type of the second argument to the operation.X- The type of checked exception that can be thrown.- Parameters:
operation- The operation to perform when the returned operation is performed.- Returns:
- An operation that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Ifoperationisnull.
-
checked
static <T,U,X extends Throwable> ThrowingBiConsumer<T,U,X> checked(BiConsumer<? super T,? super U> operation, Class<X> errorType)
Returns an operation that performs theoperationoperation to its input. AnyUncheckedExceptionthrown by theoperationoperation is unwrapped if its cause is an instance oferrorType, otherwise it is relayed to the caller.- Type Parameters:
T- The type of the first argument to the operation.U- The type of the second argument to the operation.X- The type of checked exception that can be thrown.- Parameters:
operation- The operation to perform when the returned operation is performed.errorType- The type of checked exception that can be thrown.- Returns:
- An operation that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- IfoperationorerrorTypeisnull.
-
-