The following call chains are replaced by this inspection:
Collection.stream().count()
→ Collection.size()
. In Java 8 Collection.stream().count()
actually iterates over collection elements to count them while Collection.size() is much faster for most of collections.Stream.flatMap(Collection::stream).count()
→ Stream.mapToLong(Collection::size).sum()
. Similarly
there's no need to iterate all the nested collections. Instead, their sizes could be summed up.collection.stream().filter(o -> ...).count() > 0
→ collection.stream().anyMatch(o -> ...)
collection.stream().filter(o -> ...).count() == 0
→ collection.stream().noneMatch(o -> ...)