diff options
author | Gary Gregory <garydgregory@gmail.com> | 2020-06-24 18:25:47 -0400 |
---|---|---|
committer | Gary Gregory <garydgregory@gmail.com> | 2020-06-24 18:25:47 -0400 |
commit | c7aea90a7a6e27d7159034cfbea64f796c6846af (patch) | |
tree | f42c53e6d8e5468abc1d62aa978e4ee9c015669f /src/main/java/org/apache/commons/lang3/function | |
parent | 4badcde7f7cfb7a295103b5b89d1e58a868e196b (diff) | |
download | apache-commons-lang-c7aea90a7a6e27d7159034cfbea64f796c6846af.tar.gz |
[LANG-1568]
org.apache.commons.lang3.function.FailableBiFunction.andThen(FailableFunction<?
super R, ? extends V, E>)
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/function')
3 files changed, 52 insertions, 3 deletions
diff --git a/src/main/java/org/apache/commons/lang3/function/FailableBiConsumer.java b/src/main/java/org/apache/commons/lang3/function/FailableBiConsumer.java index 5f56b06e9..6d5d99f5f 100644 --- a/src/main/java/org/apache/commons/lang3/function/FailableBiConsumer.java +++ b/src/main/java/org/apache/commons/lang3/function/FailableBiConsumer.java @@ -37,7 +37,7 @@ public interface FailableBiConsumer<T, U, E extends Throwable> { /** * Returns The NOP singleton. - * + * * @param <T> Consumed type 1. * @param <U> Consumed type 2. * @param <E> Thrown exception. @@ -62,9 +62,9 @@ public interface FailableBiConsumer<T, U, E extends Throwable> { * @param after the operation to perform after this one. * @return a composed {@code FailableBiConsumer} like {@link BiConsumer#andThen(BiConsumer)}. * @throws E Thrown when a consumer fails. - * @throws NullPointerException if {@code after} is null + * @throws NullPointerException if {@code after} is null. */ - default FailableBiConsumer<T, U, E> andThen(FailableBiConsumer<? super T, ? super U, E> after) throws E { + default FailableBiConsumer<T, U, E> andThen(final FailableBiConsumer<? super T, ? super U, E> after) throws E { Objects.requireNonNull(after); return (t, u) -> { diff --git a/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java b/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java index d112be8e9..be0e4704b 100644 --- a/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java +++ b/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java @@ -17,7 +17,9 @@ package org.apache.commons.lang3.function; +import java.util.Objects; import java.util.function.BiFunction; +import java.util.function.Function; /** * A functional interface like {@link BiFunction} that declares a {@code Throwable}. @@ -31,6 +33,37 @@ import java.util.function.BiFunction; @FunctionalInterface public interface FailableBiFunction<T, U, R, E extends Throwable> { + /** NOP singleton */ + @SuppressWarnings("rawtypes") + final FailableBiFunction NOP = (t, u) -> null; + + /** + * Returns The NOP singleton. + * + * @param <T> Consumed type 1. + * @param <U> Consumed type 2. + * @param <R> Return type. + * @param <E> Thrown exception. + * @return The NOP singleton. + */ + static <T, U, R, E extends Throwable> FailableBiFunction<T, U, R, E> nop() { + return NOP; + } + + /** + * Returns a composed {@code FailableBiFunction} that like {@link BiFunction#andThen(Function)}. + * + * @param <V> the type of output of the {@code after} function, and of the composed function + * @param after the operation to perform after this one. + * @return a composed {@code FailableBiFunction} that like {@link BiFunction#andThen(Function)}. + * @throws E Thrown when a consumer fails. + * @throws NullPointerException if after is null. + */ + default <V> FailableBiFunction<T, U, V, E> andThen(final FailableFunction<? super R, ? extends V, E> after) throws E { + Objects.requireNonNull(after); + return (final T t, final U u) -> after.apply(apply(t, u)); + } + /** * Applies this function. * diff --git a/src/main/java/org/apache/commons/lang3/function/FailableFunction.java b/src/main/java/org/apache/commons/lang3/function/FailableFunction.java index 7de443796..3d4b905b6 100644 --- a/src/main/java/org/apache/commons/lang3/function/FailableFunction.java +++ b/src/main/java/org/apache/commons/lang3/function/FailableFunction.java @@ -30,6 +30,22 @@ import java.util.function.Function; @FunctionalInterface public interface FailableFunction<T, R, E extends Throwable> { + /** NOP singleton */ + @SuppressWarnings("rawtypes") + final FailableFunction NOP = t -> null; + + /** + * Returns The NOP singleton. + * + * @param <T> Consumed type 1. + * @param <R> Return type. + * @param <E> Thrown exception. + * @return The NOP singleton. + */ + static <T, R, E extends Throwable> FailableFunction<T, R, E> nop() { + return NOP; + } + /** * Applies this function. * |