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

Last change on this file since 12783 was 11921, checked in by Don-vip, 7 years ago

improve unit test coverage of utilities classes thanks to https://trajano.github.io/commons-testing

File size: 1.3 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 // 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.