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:

Noncompliant Code Example

boolean hasRed = widgets.stream().filter(w -> w.getColor() == RED).findFirst().isPresent(); // Noncompliant

Compliant Solution

boolean hasRed = widgets.stream().anyMatch(w -> w.getColor() == RED);