diff options
author | Dico200 <dico.karssiens@gmail.com> | 2018-07-25 01:53:02 +0100 |
---|---|---|
committer | Dico200 <dico.karssiens@gmail.com> | 2018-07-25 01:53:02 +0100 |
commit | 5e168847c2624b767deb9da310ecfdf169e0f43c (patch) | |
tree | 56b76556a6837fff20b800d5a22218286a975581 /dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java | |
parent | 60503351a30a91985b95ee8aa64e163ef084b34b (diff) |
Add dicore3-core, without really irrelevant packages
Diffstat (limited to 'dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java')
-rw-r--r-- | dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java b/dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java new file mode 100644 index 0000000..badf05b --- /dev/null +++ b/dicore3/core/src/main/java/io/dico/dicore/exceptions/checkedfunctions/CheckedBiConsumer.java @@ -0,0 +1,69 @@ +package io.dico.dicore.exceptions.checkedfunctions; + +import io.dico.dicore.exceptions.ExceptionHandler; + +import java.util.function.BiConsumer; + +/** + * checked mimic of {@link BiConsumer} + * + * @param <TParam1> + * @param <TParam2> + * @param <TException> + */ +@FunctionalInterface +public interface CheckedBiConsumer<TParam1, TParam2, TException extends Throwable> + extends CheckedFunctionalObject<Void, TException>, BiConsumer<TParam1, TParam2> { + + /** + * The consuming action + * + * @param t the first argument to consume + * @param u the second argument to consume + * @throws TException if an exception occurs + */ + void checkedAccept(TParam1 t, TParam2 u) throws TException; + + /** + * unchecked wrapper for {@link #checkedAccept(Object, Object)} + * If a {@link TException} occurs, an unchecked one might be thrown by {@link #resultOnError(Throwable, Object...)} + * + * @param t the first input + * @param u the second input + * @see #checkedAccept(Object, Object) + * @see #resultOnError(Throwable, Object...) + */ + @Override + default void accept(TParam1 t, TParam2 u) { + try { + checkedAccept(t, u); + } catch (Throwable ex) { + handleGenericException(ex, t, u); + } + } + + /** + * {@inheritDoc} + */ + @Override + default CheckedBiConsumer<TParam1, TParam2, TException> handleExceptionsWith(ExceptionHandler handler) { + return new CheckedBiConsumer<TParam1, TParam2, TException>() { + @Override + public void checkedAccept(TParam1 t, TParam2 u) throws TException { + CheckedBiConsumer.this.checkedAccept(t, u); + } + + @Override + public Void handleGenericException(Throwable thrown, Object... args) { + handler.handleGenericException(thrown, args); + return null; + } + + @Override + public CheckedBiConsumer<TParam1, TParam2, TException> handleExceptionsWith(ExceptionHandler handler) { + return CheckedBiConsumer.this.handleExceptionsWith(handler); + } + }; + } + +} |