All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andyshao.util.function.ThrowableBiConsumer Maven / Gradle / Ivy

The newest version!
package com.github.andyshao.util.function;

import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.ThrowableException;

import java.util.Objects;
import java.util.function.BiConsumer;

/**
 * 
 * 
 * Title:
* Descript:
* Copyright: Copryright(c) May 30, 2019
* Encoding: UNIX UTF-8 * * @author Andy.Shao * * @param argument type * @param artument type * @see ExceptionableBiConsumer * @see BiConsumer * @deprecated repeated */ @Deprecated(since = "5.0.0.RELEASE") public interface ThrowableBiConsumer { /** * accept operation * @param t left type * @param u right type * @throws Throwable any error */ void accept(T t, U u) throws Throwable; /** * to {@link ExceptionableBiConsumer} * @return {@link ExceptionableBiConsumer} * @param left type * @param right type */ static Convert, ExceptionableBiConsumer> toExceptionableBiConsumer() { return input -> { return new ExceptionableBiConsumer() { @Override public void accept(T t, U u) throws Exception { try { input.accept(t, u); } catch (Throwable e) { throw ThrowableException.convertToException(e); } } }; }; } /** * and then * @param after after operation * @return {@link ThrowableBiConsumer} */ default ThrowableBiConsumer andThen(ThrowableBiConsumer after) { Objects.requireNonNull(after); return (t, u) -> { this.accept(t, u); after.accept(t, u); }; } }