Find the first item of coll for which pred.test(...) returns true. @param pred The IPredicate to test for @param coll The Collection of items to search through. @return The first matching value in coll, or null if nothing matches.
(IPredicate<T> pred, Collection<T> coll)
| 1487 | * @return The first matching value in coll, or null if nothing matches. |
| 1488 | */ |
| 1489 | public static <T> T findOne(IPredicate<T> pred, Collection<T> coll) { |
| 1490 | if (coll == null) { |
| 1491 | return null; |
| 1492 | } |
| 1493 | for (T elem : coll) { |
| 1494 | if (pred.test(elem)) { |
| 1495 | return elem; |
| 1496 | } |
| 1497 | } |
| 1498 | return null; |
| 1499 | } |
| 1500 | |
| 1501 | public static <T, U> T findOne(IPredicate<T> pred, Map<U, T> map) { |
| 1502 | if (map == null) { |