The Stream API provides the boolean anyMatch(Predicate<? super T> predicate)
method, which is a very convenient and efficient
way to check whether any elements of a stream match the provided predicate.
This rule raises an issue when a Stream
chain could be replaced by this method call. Specifically:
filter(Predicate<? super T> predicate).findFirst().isPresent()
filter(Predicate<? super T> predicate).findAny().isPresent()
boolean hasRed = widgets.stream().filter(w -> w.getColor() == RED).findFirst().isPresent(); // Noncompliant
boolean hasRed = widgets.stream().anyMatch(w -> w.getColor() == RED);