Changeset 3836 in josm for trunk/src/org/openstreetmap/josm/tools/Utils.java
- Timestamp:
- 2011-01-31T14:18:47+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3796 r3836 4 4 public class Utils { 5 5 6 public static <T> boolean exists(Iterable<? extends T> coll , Predicate<? super T> pred) {7 for (T el : coll) {8 if (pred .evaluate(el))6 public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate) { 7 for (T item : collection) { 8 if (predicate.evaluate(item)) 9 9 return true; 10 10 } 11 11 return false; 12 } 13 14 public static <T> boolean exists(Iterable collection, Class<? extends T> klass) { 15 for (Object item : collection) { 16 if (klass.isInstance(item)) 17 return true; 18 } 19 return false; 20 } 21 22 public static <T> T find(Iterable<? extends T> collection, Predicate<? super T> predicate) { 23 for (T item : collection) { 24 if (predicate.evaluate(item)) 25 return item; 26 } 27 return null; 28 } 29 30 public static <T> T find(Iterable collection, Class<? extends T> klass) { 31 for (Object item : collection) { 32 if (klass.isInstance(item)) { 33 @SuppressWarnings("unchecked") T res = (T) item; 34 return res; 35 } 36 } 37 return null; 12 38 } 13 39 … … 28 54 } 29 55 56 public static int max(int a, int b, int c, int d) { 57 return Math.max(Math.max(a, b), Math.max(c, d)); 58 } 59 30 60 /** 31 61 * for convenience: test whether 2 objects are either both null or a.equals(b) 32 62 */ 33 63 public static <T> boolean equal(T a, T b) { 34 if (a == null && b == null)64 if (a == b) 35 65 return true; 36 66 return (a != null && a.equals(b));
Note:
See TracChangeset
for help on using the changeset viewer.