Changeset 12594 in josm for trunk/src/org/openstreetmap/josm/tools/Utils.java
- Timestamp:
- 2017-08-12T11:24:39+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12238 r12594 55 55 import java.util.regex.Matcher; 56 56 import java.util.regex.Pattern; 57 import java.util.stream.Stream; 57 58 import java.util.zip.GZIPInputStream; 58 59 import java.util.zip.ZipEntry; … … 1690 1691 return null; 1691 1692 } 1693 1694 /** 1695 * Get a function that converts an object to a singleton stream of a certain 1696 * class (or null if the object cannot be cast to that class). 1697 * 1698 * Can be useful in relation with streams, but be aware of the performance 1699 * implications of creating a stream for each element. 1700 * @param <T> type of the objects to convert 1701 * @param <U> type of the elements in the resulting stream 1702 * @param klass the class U 1703 * @return function converting an object to a singleton stream or null 1704 */ 1705 public static <T, U> Function<T, Stream<U>> castToStream(Class<U> klass) { 1706 return x -> klass.isInstance(x) ? Stream.of(klass.cast(x)) : null; 1707 } 1692 1708 }
Note:
See TracChangeset
for help on using the changeset viewer.