use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class AbstractHashBag method forEachWithIndex.
@Override
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) {
Counter index = new Counter();
this.items.forEachKeyValue((key, count) -> {
for (int i = 0; i < count; i++) {
objectIntProcedure.value(key, index.getCount());
index.increment();
}
});
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class UnmodifiableMutableListTest method forEachFromTo.
@Test
public void forEachFromTo() {
Counter counter = new Counter();
this.unmodifiableList.forEach(1, 2, band -> counter.increment());
Assert.assertEquals(2, counter.getCount());
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class AbstractParallelIterable method count.
@Override
public int count(Predicate<? super T> predicate) {
Function<Batch<T>, Integer> map = batch -> batch.count(predicate);
Counter state = new Counter();
this.collectCombineUnordered(map, Counter::add, state);
return state.getCount();
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class UnmodifiableMutableCollectionTest method forEach.
@Test
public void forEach() {
Counter counter = new Counter();
this.unmodifiableCollection.forEach(Procedures.cast(band -> counter.increment()));
Assert.assertEquals(4, counter.getCount());
}
use of org.eclipse.collections.impl.Counter in project eclipse-collections by eclipse.
the class UnmodifiableMutableCollectionTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
Counter counter = new Counter();
this.unmodifiableCollection.forEachWithIndex((band, index) -> counter.add(index));
Assert.assertEquals(6, counter.getCount());
}
Aggregations