Search in sources :

Example 21 with Counter

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();
        }
    });
}
Also used : Counter(org.eclipse.collections.impl.Counter)

Example 22 with Counter

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());
}
Also used : Counter(org.eclipse.collections.impl.Counter) Test(org.junit.Test)

Example 23 with Counter

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();
}
Also used : Predicate(org.eclipse.collections.api.block.predicate.Predicate) Predicate2(org.eclipse.collections.api.block.predicate.Predicate2) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Functions2(org.eclipse.collections.impl.block.factory.Functions2) CompletionService(java.util.concurrent.CompletionService) MutableSortedMap(org.eclipse.collections.api.map.sorted.MutableSortedMap) MutableSet(org.eclipse.collections.api.set.MutableSet) Future(java.util.concurrent.Future) MutatingAggregationProcedure(org.eclipse.collections.impl.block.procedure.MutatingAggregationProcedure) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) NonMutatingAggregationProcedure(org.eclipse.collections.impl.block.procedure.NonMutatingAggregationProcedure) Comparators(org.eclipse.collections.impl.block.factory.Comparators) LongFunction(org.eclipse.collections.api.block.function.primitive.LongFunction) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) CheckedProcedure2(org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure2) Set(java.util.Set) MutableSortedBag(org.eclipse.collections.api.bag.sorted.MutableSortedBag) Procedures(org.eclipse.collections.impl.block.factory.Procedures) MutableSortedSet(org.eclipse.collections.api.set.sorted.MutableSortedSet) TreeSortedSet(org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Beta(org.eclipse.collections.api.annotation.Beta) Function(org.eclipse.collections.api.block.function.Function) Callable(java.util.concurrent.Callable) Procedure(org.eclipse.collections.api.block.procedure.Procedure) SetAdapter(org.eclipse.collections.impl.set.mutable.SetAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ParallelIterable(org.eclipse.collections.api.ParallelIterable) LazyIterable(org.eclipse.collections.api.LazyIterable) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Counter(org.eclipse.collections.impl.Counter) TreeSortedMap(org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap) IOException(java.io.IOException) IntFunction(org.eclipse.collections.api.block.function.primitive.IntFunction) ExecutionException(java.util.concurrent.ExecutionException) DoubleSumResultHolder(org.eclipse.collections.impl.block.procedure.DoubleSumResultHolder) MapCollectProcedure(org.eclipse.collections.impl.block.procedure.MapCollectProcedure) ConcurrentHashMapUnsafe(org.eclipse.collections.impl.map.mutable.ConcurrentHashMapUnsafe) MapIterable(org.eclipse.collections.api.map.MapIterable) Comparator(java.util.Comparator) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Counter(org.eclipse.collections.impl.Counter)

Example 24 with Counter

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());
}
Also used : Function(org.eclipse.collections.api.block.function.Function) Multimap(org.eclipse.collections.api.multimap.Multimap) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) FastList(org.eclipse.collections.impl.list.mutable.FastList) Function3(org.eclipse.collections.api.block.function.Function3) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) RichIterable(org.eclipse.collections.api.RichIterable) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) MutableMap(org.eclipse.collections.api.map.MutableMap) Functions(org.eclipse.collections.impl.block.factory.Functions) Function2(org.eclipse.collections.api.block.function.Function2) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) Interval(org.eclipse.collections.impl.list.Interval) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) Counter(org.eclipse.collections.impl.Counter) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) StringPredicates(org.eclipse.collections.impl.block.factory.StringPredicates) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) Twin(org.eclipse.collections.api.tuple.Twin) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) MutableSortedSet(org.eclipse.collections.api.set.sorted.MutableSortedSet) TreeSortedSet(org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Assert(org.junit.Assert) Collections(java.util.Collections) Counter(org.eclipse.collections.impl.Counter) Test(org.junit.Test)

Example 25 with Counter

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());
}
Also used : Counter(org.eclipse.collections.impl.Counter) Test(org.junit.Test)

Aggregations

Counter (org.eclipse.collections.impl.Counter)25 Test (org.junit.Test)10 MutableList (org.eclipse.collections.api.list.MutableList)6 NoSuchElementException (java.util.NoSuchElementException)5 Function (org.eclipse.collections.api.block.function.Function)5 Predicates (org.eclipse.collections.impl.block.factory.Predicates)5 Procedures (org.eclipse.collections.impl.block.factory.Procedures)5 FastList (org.eclipse.collections.impl.list.mutable.FastList)5 Collections (java.util.Collections)4 Iterator (java.util.Iterator)4 RichIterable (org.eclipse.collections.api.RichIterable)4 TreeBag (org.eclipse.collections.impl.bag.sorted.mutable.TreeBag)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Interval (org.eclipse.collections.impl.list.Interval)4 Assert (org.junit.Assert)4 Map (java.util.Map)3 LazyIterable (org.eclipse.collections.api.LazyIterable)3 MutableSortedBag (org.eclipse.collections.api.bag.sorted.MutableSortedBag)3 MutableSortedMap (org.eclipse.collections.api.map.sorted.MutableSortedMap)3 TreeSortedMap (org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap)3