|
34 | 34 | import java.util.Date; |
35 | 35 | import java.util.Deque; |
36 | 36 | import java.util.HashMap; |
37 | | -import java.util.HashSet; |
38 | 37 | import java.util.Iterator; |
39 | 38 | import java.util.LinkedHashMap; |
40 | 39 | import java.util.LinkedHashSet; |
41 | | -import java.util.LinkedList; |
42 | 40 | import java.util.List; |
43 | 41 | import java.util.ListIterator; |
44 | 42 | import java.util.Map; |
45 | 43 | import java.util.Objects; |
46 | | -import java.util.Queue; |
| 44 | +import java.util.Optional; |
47 | 45 | import java.util.Set; |
48 | 46 | import java.util.UUID; |
49 | 47 | import java.util.function.BiConsumer; |
|
60 | 58 | * |
61 | 59 | * @author Valentyn Kolesnikov |
62 | 60 | */ |
63 | | -@SuppressWarnings({"java:S106", "java:S2189", "java:S2272", "java:S3740", "java:S5852"}) |
| 61 | +@SuppressWarnings({ |
| 62 | + "java:S106", |
| 63 | + "java:S2189", |
| 64 | + "java:S2272", |
| 65 | + "java:S2789", |
| 66 | + "java:S3740", |
| 67 | + "java:S5852" |
| 68 | +}) |
64 | 69 | public class Underscore<T> { |
65 | 70 | private static final Map<String, Function<String, String>> FUNCTIONS = newLinkedHashMap(); |
66 | 71 | private static final Map<String, String> TEMPLATE_SETTINGS = new HashMap<>(); |
@@ -534,7 +539,7 @@ public static <T, E> E foldr( |
534 | 539 | public static <E> Optional<E> find(final Iterable<E> iterable, final Predicate<E> pred) { |
535 | 540 | for (E element : iterable) { |
536 | 541 | if (pred.test(element)) { |
537 | | - return Optional.of(element); |
| 542 | + return isNull(element) ? null : Optional.of(element); |
538 | 543 | } |
539 | 544 | } |
540 | 545 | return Optional.empty(); |
@@ -667,7 +672,8 @@ public boolean all(final Predicate<T> pred) { |
667 | 672 | } |
668 | 673 |
|
669 | 674 | public static <E> boolean some(final Iterable<E> iterable, final Predicate<E> pred) { |
670 | | - return find(iterable, pred).isPresent(); |
| 675 | + Optional<E> optional = find(iterable, pred); |
| 676 | + return optional == null || optional.isPresent(); |
671 | 677 | } |
672 | 678 |
|
673 | 679 | public boolean some(final Predicate<T> pred) { |
|
0 commit comments