/** * Return the number of occurrences of object in the specified map. */ public static <K, V> int occurrencesOf(Map<K, V> map, V object) { return Iterate.count(map.values(), Predicates.equal(object)); }
/** * Return the number of occurrences where object is equal to the specified attribute in the specified map. */ public static <K, V, A> int occurrencesOfAttribute( Map<K, V> map, Function<? super V, ? extends A> function, A object) { return Iterate.count(map.values(), Predicates.attributeEqual(function, object)); }
public static <T> void assertCount( int expectedCount, Iterable<T> iterable, Predicate<? super T> predicate) { Assert.assertEquals(expectedCount, Iterate.count(iterable, predicate)); }
public int count(Predicate<? super T> predicate) { return Iterate.count(this.getDelegate(), predicate); }
/** * Returns the size of an iterable. * In the case of Collections and RichIterables, the method size is called. * All other iterables will force a complete iteration to happen, which can be unnecessarily costly. */ public static int sizeOf(Iterable<?> iterable) { if (iterable instanceof Collection) { return ((Collection<?>) iterable).size(); } if (iterable instanceof RichIterable) { return ((RichIterable<?>) iterable).size(); } return Iterate.count(iterable, Predicates.alwaysTrue()); }
/** * Return the number of occurrences where object is equal to the specified attribute in the specified map. */ public static <K, V, A> int occurrencesOfAttribute( Map<K, V> map, Function<? super V, ? extends A> function, A object) { return Iterate.count(map.values(), Predicates.attributeEqual(function, object)); }
public int count(Predicate<? super T> predicate) { return Iterate.count(this.getDelegate(), predicate); }
/** * Return the number of occurrences of object in the specified map. */ public static <K, V> int occurrencesOf(Map<K, V> map, V object) { return Iterate.count(map.values(), Predicates.equal(object)); }
public static <T> void assertCount( int expectedCount, Iterable<T> iterable, Predicate<? super T> predicate) { Assert.assertEquals(expectedCount, Iterate.count(iterable, predicate)); }
/** * Returns the size of an iterable. * In the case of Collections and RichIterables, the method size is called. * All other iterables will force a complete iteration to happen, which can be unnecessarily costly. */ public static int sizeOf(Iterable<?> iterable) { if (iterable instanceof Collection) { return ((Collection<?>) iterable).size(); } if (iterable instanceof RichIterable) { return ((RichIterable<?>) iterable).size(); } return Iterate.count(iterable, Predicates.alwaysTrue()); }