source: josm/trunk/src/org/openstreetmap/josm/tools/StreamUtils.java@ 10790

Last change on this file since 10790 was 10718, checked in by simon04, 8 years ago

see #11390 - Simplify StreamUtils

File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.util.StringJoiner;
5import java.util.stream.Collector;
6import java.util.stream.Stream;
7import java.util.stream.StreamSupport;
8
9/**
10 * Utility methods for streams.
11 * @author Michael Zangl
12 */
13public final class StreamUtils {
14
15 /**
16 * Utility class
17 */
18 private StreamUtils() {}
19
20 /**
21 * Returns a sequential {@code Stream} with the iterable as its source.
22 * @param <T> The element type to iterate over
23 * @param iterable The iterable
24 * @return The stream of for that iterable.
25 * @since 10718
26 */
27 public static <T> Stream<T> toStream(Iterable<T> iterable) {
28 return StreamSupport.stream(iterable.spliterator(), false);
29 }
30
31 /**
32 * Creates a new Collector that collects the items and returns them as HTML unordered list.
33 * @return The collector.
34 * @since 10638
35 */
36 public static Collector<String, ?, String> toHtmlList() {
37 return Collector.of(
38 () -> new StringJoiner("</li><li>", "<ul><li>", "</li></ul>").setEmptyValue("<ul></ul>"),
39 StringJoiner::add, StringJoiner::merge, StringJoiner::toString
40 );
41 }
42}
Note: See TracBrowser for help on using the repository browser.