aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/lang3/Functions.java
diff options
context:
space:
mode:
authorJochen Wiedmann <jochen.wiedmann@gmail.com>2020-01-26 22:57:13 +0100
committerJochen Wiedmann <jochen.wiedmann@gmail.com>2020-01-26 22:57:13 +0100
commit2ea44b2adae8da8e3e7f55cc226479f9431feda9 (patch)
tree27f30cd3ba3961164b5b5c6649434ef681441322 /src/main/java/org/apache/commons/lang3/Functions.java
parentbfc88d23cb83448f6f5ac98cece5da92deeb221e (diff)
downloadapache-commons-lang-2ea44b2adae8da8e3e7f55cc226479f9431feda9.tar.gz
- Added the Streams class.
- Added Functions.stream() as an accessor method.
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/Functions.java')
-rw-r--r--src/main/java/org/apache/commons/lang3/Functions.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/org/apache/commons/lang3/Functions.java b/src/main/java/org/apache/commons/lang3/Functions.java
index 2d0ca06b7..ef9c45d90 100644
--- a/src/main/java/org/apache/commons/lang3/Functions.java
+++ b/src/main/java/org/apache/commons/lang3/Functions.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
@@ -28,6 +29,9 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
+import java.util.stream.Stream;
+
+import org.apache.commons.lang3.Streams.FailableStream;
/** This class provides utility functions, and classes for working with the
@@ -400,6 +404,39 @@ public class Functions {
}
}
+ /**
+ * Converts the given stream into a {@link FailableStream}. The
+ * {@link FailableStream} consists of the same elements, than the
+ * input stream. However, failable lambdas, like
+ * {@link FailablePredicate}, {@link FailableFunction}, and
+ * {@link FailableConsumer} may be applied, rather than
+ * {@link Predicate}, {@link Function}, {@link Consumer}, etc.
+ * @param pStream The stream, which is being converted into a
+ * {@link FailableStream}.
+ * @param <O> The streams element type.
+ * @return The created {@link FailableStream}.
+ */
+ public static <O> FailableStream<O> stream(Stream<O> pStream) {
+ return new FailableStream<O>(pStream);
+ }
+
+ /**
+ * Converts the given collection into a {@link FailableStream}.
+ * The {@link FailableStream} consists of the collections
+ * elements. Shortcut for
+ * <pre>
+ * Functions.stream(pCollection.stream());
+ * </pre>
+ * @param pCollection The collection, which is being converted into a
+ * {@link FailableStream}.
+ * @param <O> The collections element type. (In turn, the result
+ * streams element type.)
+ * @return The created {@link FailableStream}.
+ */
+ public static <O> FailableStream<O> stream(Collection<O> pCollection) {
+ return new FailableStream<O>(pCollection.stream());
+ }
+
/**
* A simple try-with-resources implementation, that can be used, if your