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