use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class ListIterateTest method assertReverseForEachWithIndex.
private void assertReverseForEachWithIndex(List<Integer> list) {
Counter counter = new Counter();
ListIterate.reverseForEachWithIndex(list, (object, index) -> {
Assert.assertEquals(counter.getCount() + 1, object.longValue());
Assert.assertEquals(4 - counter.getCount(), index);
counter.increment();
});
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class AbstractBag method count.
@Override
public int count(Predicate<? super T> predicate) {
Counter result = new Counter();
this.forEachWithOccurrences((each, occurrences) -> {
if (predicate.accept(each)) {
result.add(occurrences);
}
});
return result.getCount();
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class ImmutableSortedBagImpl method hashCode.
@Override
public int hashCode() {
Counter counter = new Counter();
this.forEachWithOccurrences((each, count) -> counter.add((each == null ? 0 : each.hashCode()) ^ count));
return counter.getCount();
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class TreeBag method addOccurrences.
@Override
public int addOccurrences(T item, int occurrences) {
if (occurrences < 0) {
throw new IllegalArgumentException("Cannot add a negative number of occurrences");
}
if (occurrences > 0) {
Counter counter = this.items.getIfAbsentPut(item, Counter::new);
counter.add(occurrences);
this.size += occurrences;
return counter.getCount();
}
return this.occurrencesOf(item);
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class TreeBag method add.
@Override
public boolean add(T item) {
Counter counter = this.items.getIfAbsentPut(item, Counter::new);
counter.increment();
this.size++;
return true;
}
Aggregations