This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new 4ff5e2b Extract a map method. 4ff5e2b is described below commit 4ff5e2b9f98e5ca9dd105a2d08477e0371ae8832 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Sep 1 15:23:02 2021 -0400 Extract a map method. --- .../commons/lang3/concurrent/UncheckedFuture.java | 17 +++++++++++++++-- .../commons/lang3/concurrent/UncheckedFutureTest.java | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/concurrent/UncheckedFuture.java b/src/main/java/org/apache/commons/lang3/concurrent/UncheckedFuture.java index d491b64..a8cc0b7 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/UncheckedFuture.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/UncheckedFuture.java @@ -23,6 +23,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.lang3.exception.UncheckedInterruptedException; @@ -39,13 +40,25 @@ public interface UncheckedFuture<V> extends Future<V> { /** * Maps the given instances as unchecked. * - * @param <T> The result type returned by this Future's {@link #get()} and {@link #get(long, TimeUnit)} methods. + * @param <T> The result type returned by the Futures' {@link #get()} and {@link #get(long, TimeUnit)} methods. + * + * @param futures The Futures to uncheck. + * @return a new stream. + */ + static <T> Stream<UncheckedFuture<T>> map(final Collection<Future<T>> futures) { + return futures.stream().map(UncheckedFuture::on); + } + + /** + * Maps the given instances as unchecked. + * + * @param <T> The result type returned by the Futures' {@link #get()} and {@link #get(long, TimeUnit)} methods. * * @param futures The Futures to uncheck. * @return a new collection. */ static <T> Collection<UncheckedFuture<T>> on(final Collection<Future<T>> futures) { - return futures.stream().map(UncheckedFuture::on).collect(Collectors.toList()); + return map(futures).collect(Collectors.toList()); } /** diff --git a/src/test/java/org/apache/commons/lang3/concurrent/UncheckedFutureTest.java b/src/test/java/org/apache/commons/lang3/concurrent/UncheckedFutureTest.java index 7eab6cb..84dfc62 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/UncheckedFutureTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/UncheckedFutureTest.java @@ -102,6 +102,13 @@ public class UncheckedFutureTest { } @Test + public void testMap() { + final List<String> expected = Arrays.asList("Y", "Z"); + final List<Future<String>> input = Arrays.asList(new TestFuture<>("Y"), new TestFuture<>("Z")); + assertEquals(expected, UncheckedFuture.map(input).map(UncheckedFuture::get).collect(Collectors.toList())); + } + + @Test public void testOnCollection() { final List<String> expected = Arrays.asList("Y", "Z"); final List<Future<String>> input = Arrays.asList(new TestFuture<>("Y"), new TestFuture<>("Z"));