aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/lang3/function
diff options
context:
space:
mode:
authorGary Gregory <garydgregory@gmail.com>2020-06-24 18:40:25 -0400
committerGary Gregory <garydgregory@gmail.com>2020-06-24 18:40:25 -0400
commit47fb7767924e95157488d0816599e5d7c9cf40a9 (patch)
tree43622089fb1794dcc22cfa033747214c2f0a3f16 /src/main/java/org/apache/commons/lang3/function
parentc7aea90a7a6e27d7159034cfbea64f796c6846af (diff)
downloadapache-commons-lang-47fb7767924e95157488d0816599e5d7c9cf40a9.tar.gz
[LANG-1568]
org.apache.commons.lang3.function.FailableConsumer.andThen(FailableConsumer<? super T, E>)
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/function')
-rw-r--r--src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java2
-rw-r--r--src/main/java/org/apache/commons/lang3/function/FailableConsumer.java38
2 files changed, 36 insertions, 4 deletions
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 be0e4704b..3173c73b7 100644
--- a/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java
+++ b/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java
@@ -57,7 +57,7 @@ public interface FailableBiFunction<T, U, R, E extends Throwable> {
* @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.
+ * @throws NullPointerException if {@code after} is null.
*/
default <V> FailableBiFunction<T, U, V, E> andThen(final FailableFunction<? super R, ? extends V, E> after) throws E {
Objects.requireNonNull(after);
diff --git a/src/main/java/org/apache/commons/lang3/function/FailableConsumer.java b/src/main/java/org/apache/commons/lang3/function/FailableConsumer.java
index acb73cc51..c2f2de8a9 100644
--- a/src/main/java/org/apache/commons/lang3/function/FailableConsumer.java
+++ b/src/main/java/org/apache/commons/lang3/function/FailableConsumer.java
@@ -17,17 +17,33 @@
package org.apache.commons.lang3.function;
+import java.util.Objects;
import java.util.function.Consumer;
/**
* A functional interface like {@link Consumer} that declares a {@code Throwable}.
*
- * @param <O> Consumed type 1.
+ * @param <T> Consumed type 1.
* @param <E> Thrown exception.
* @since 3.11
*/
@FunctionalInterface
-public interface FailableConsumer<O, E extends Throwable> {
+public interface FailableConsumer<T, E extends Throwable> {
+
+ /** NOP singleton */
+ @SuppressWarnings("rawtypes")
+ final FailableConsumer NOP = t -> {/* NOP */};
+
+ /**
+ * Returns The NOP singleton.
+ *
+ * @param <T> Consumed type 1.
+ * @param <E> Thrown exception.
+ * @return The NOP singleton.
+ */
+ static <T, E extends Throwable> FailableConsumer<T, E> nop() {
+ return NOP;
+ }
/**
* Accepts the consumer.
@@ -35,5 +51,21 @@ public interface FailableConsumer<O, E extends Throwable> {
* @param object the parameter for the consumable to accept
* @throws E Thrown when the consumer fails.
*/
- void accept(O object) throws E;
+ void accept(T object) throws E;
+
+ /**
+ * Returns a composed {@code Consumer} like {@link Consumer#andThen(Consumer)}.
+ *
+ * @param after the operation to perform after this operation
+ * @return a composed {@code Consumer} like {@link Consumer#andThen(Consumer)}.
+ * @throws E Thrown when a consumer fails.
+ * @throws NullPointerException if {@code after} is null
+ */
+ default FailableConsumer<T, E> andThen(final FailableConsumer<? super T, E> after) throws E {
+ Objects.requireNonNull(after);
+ return (final T t) -> {
+ accept(t);
+ after.accept(t);
+ };
+ }
}