Returns the number of elements in the specified iterable that equal the specified object. This implementation avoids a full iteration when the iterable is a Multiset or Set. @see Collections#frequency
(Iterable<?> iterable, @Nullable Object element)
| 393 | |
| 394 | |
| 395 | public static int frequency(Iterable<?> iterable, @Nullable Object element) { |
| 396 | if ((iterable instanceof Multiset)) { |
| 397 | return ((Multiset<?>) iterable).count(element); |
| 398 | } else if ((iterable instanceof Set)) { |
| 399 | return ((Set<?>) iterable).contains(element) ? 1 : 0; |
| 400 | } |
| 401 | return Iterators.frequency(iterable.iterator(), element); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Returns an iterable whose iterators cycle indefinitely over the elements of |