Utility method to treat Iterable as a Stream.
Change-Id: I70564ee9fa675c4293aa733b1a28e63c12dea0b7
Showing
1 changed file
with
12 additions
and
0 deletions
... | @@ -46,6 +46,8 @@ import java.util.concurrent.Future; | ... | @@ -46,6 +46,8 @@ import java.util.concurrent.Future; |
46 | import java.util.concurrent.ThreadFactory; | 46 | import java.util.concurrent.ThreadFactory; |
47 | import java.util.concurrent.TimeUnit; | 47 | import java.util.concurrent.TimeUnit; |
48 | import java.util.concurrent.TimeoutException; | 48 | import java.util.concurrent.TimeoutException; |
49 | +import java.util.stream.Stream; | ||
50 | +import java.util.stream.StreamSupport; | ||
49 | 51 | ||
50 | import org.slf4j.Logger; | 52 | import org.slf4j.Logger; |
51 | 53 | ||
... | @@ -460,6 +462,16 @@ public abstract class Tools { | ... | @@ -460,6 +462,16 @@ public abstract class Tools { |
460 | return bytes; | 462 | return bytes; |
461 | } | 463 | } |
462 | 464 | ||
465 | + /** | ||
466 | + * Converts an Iterable to a Stream. | ||
467 | + * | ||
468 | + * @param it Iterable to convert | ||
469 | + * @return Iterable as a Stream | ||
470 | + */ | ||
471 | + public static <T> Stream<T> stream(Iterable<T> it) { | ||
472 | + return StreamSupport.stream(it.spliterator(), false); | ||
473 | + } | ||
474 | + | ||
463 | // Auxiliary path visitor for recursive directory structure copying. | 475 | // Auxiliary path visitor for recursive directory structure copying. |
464 | private static class DirectoryCopier extends SimpleFileVisitor<Path> { | 476 | private static class DirectoryCopier extends SimpleFileVisitor<Path> { |
465 | private Path src; | 477 | private Path src; | ... | ... |
-
Please register or login to post a comment