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)
| 372 | * @see Collections#frequency |
| 373 | */ |
| 374 | public static int frequency(Iterable<?> iterable, @Nullable Object element) { |
| 375 | if ((iterable instanceof Multiset)) { |
| 376 | return ((Multiset<?>) iterable).count(element); |
| 377 | } else if ((iterable instanceof Set)) { |
| 378 | return ((Set<?>) iterable).contains(element) ? 1 : 0; |
| 379 | } |
| 380 | return Iterators.frequency(iterable.iterator(), element); |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Returns an iterable whose iterators cycle indefinitely over the elements of |