public static <T, U> BiConsumerChainer<T, U> biConsumer( final ThrowingBiConsumer<T, U> consumer) { return new BiConsumerChainer<>(consumer); }
@Override public BiConsumer<T, U> sneakyThrow() { return (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable throwable) { throw doSneakyThrow(throwable); } }; }
@Override public <E extends RuntimeException> ThrowingBiConsumer<T, U> orThrow( final Class<E> exclass) { return (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable throwable) { throw rethrow(exclass, throwable); } }; }
@Test public void orDoNothingTest() throws Throwable { final ThrowingBiConsumer<Type1, Type2> throwing = getThrowing(); configureFull(throwing); final BiConsumer<Type1, Type2> chain = getChain(throwing).orDoNothing(); final Callable<Type3> callable = toCallable(chain); assertThat(callable.call()).isSameAs(ret1); assertThat(callable.call()).isSameAs(ret1); verifyUncheckedThrow(callable); verifyErrorThrow(callable); } }
@Override public BiConsumer<T, U> sneakyThrow() { return (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable throwable) { throw doSneakyThrow(throwable); } }; }
@Override public <E extends RuntimeException> ThrowingBiConsumer<T, U> orThrow( final Class<E> exclass) { return (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable throwable) { throw rethrow(exclass, throwable); } }; }
public static <T, U> BiConsumerChainer<T, U> biConsumer( final ThrowingBiConsumer<T, U> consumer) { return new BiConsumerChainer<>(consumer); }
@Override public BiConsumerChainer<T, U> orTryWith(final ThrowingBiConsumer<T, U> other) { final ThrowingBiConsumer<T, U> consumer = (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable ignored) { other.doAccept(t, u); } }; return new BiConsumerChainer<>(consumer); }
@Override public BiConsumerChainer<T, U> orTryWith(final ThrowingBiConsumer<T, U> other) { final ThrowingBiConsumer<T, U> consumer = (t, u) -> { try { throwing.doAccept(t, u); } catch (Error | RuntimeException e) { throw e; } catch (Throwable ignored) { other.doAccept(t, u); } }; return new BiConsumerChainer<>(consumer); }