Changeset 12604 in josm for trunk/src/org/openstreetmap/josm/tools/Utils.java
- Timestamp:
- 2017-08-14T14:42:13+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12601 r12604 51 51 import java.util.concurrent.TimeUnit; 52 52 import java.util.concurrent.atomic.AtomicLong; 53 import java.util.function.Consumer; 53 54 import java.util.function.Function; 54 55 import java.util.function.Predicate; … … 675 676 return new Iterator<B>() { 676 677 677 private Iterator<? extends A> it = c.iterator();678 private final Iterator<? extends A> it = c.iterator(); 678 679 679 680 @Override … … 1702 1703 * @param klass the class U 1703 1704 * @return function converting an object to a singleton stream or null 1705 * @since 12594 1704 1706 */ 1705 1707 public static <T, U> Function<T, Stream<U>> castToStream(Class<U> klass) { 1706 1708 return x -> klass.isInstance(x) ? Stream.of(klass.cast(x)) : null; 1707 1709 } 1710 1711 /** 1712 * Helper method to replace the "<code>instanceof</code>-check and cast" pattern. 1713 * Checks if an object is instance of class T and performs an action if that 1714 * is the case. 1715 * Syntactic sugar to avoid typing the class name two times, when one time 1716 * would suffice. 1717 * @param <T> the type for the instanceof check and cast 1718 * @param o the object to check and cast 1719 * @param klass the class T 1720 * @param consumer action to take when o is and instance of T 1721 * @since 12604 1722 */ 1723 public static <T> void instanceOfThen(Object o, Class<T> klass, Consumer<? super T> consumer) { 1724 if (klass.isInstance(o)) { 1725 consumer.accept((T) o); 1726 } 1727 } 1708 1728 }
Note:
See TracChangeset
for help on using the changeset viewer.