Search in sources :

Example 1 with ObjectDoubleMap

use of org.eclipse.collections.api.map.primitive.ObjectDoubleMap in project eclipse-collections by eclipse.

the class ParallelIterateTest method sumByDouble.

@Test
public void sumByDouble() {
    Interval interval = Interval.oneTo(100000);
    ObjectDoubleMap<String> sumByCount = ParallelIterate.sumByDouble(interval, EVEN_OR_ODD, i -> 1.0d);
    Assert.assertEquals(50000.0, sumByCount.get("Even"), 0.0);
    Assert.assertEquals(50000.0, sumByCount.get("Odd"), 0.0);
    ObjectDoubleMap<String> sumByValue = ParallelIterate.sumByDouble(interval, EVEN_OR_ODD, Integer::doubleValue);
    Assert.assertEquals(interval.sumByDouble(EVEN_OR_ODD, Integer::doubleValue), sumByValue);
    ObjectDoubleMap<Integer> sumByValue2 = ParallelIterate.sumByDouble(interval, i -> i % 1000, Integer::doubleValue);
    Assert.assertEquals(interval.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue2);
    Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
    ObjectDoubleMap<String> sumByValue3 = ParallelIterate.sumByDouble(interval2, EVEN_OR_ODD, Integer::doubleValue);
    Assert.assertEquals(interval2.sumByDouble(EVEN_OR_ODD, Integer::doubleValue), sumByValue3);
    ObjectDoubleMap<Integer> sumByValue4 = ParallelIterate.sumByDouble(interval2, i -> i % 1000, Integer::doubleValue);
    Assert.assertEquals(interval2.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue4);
    Interval small = Interval.oneTo(11);
    ObjectDoubleMap<String> smallSumByCount = ParallelIterate.sumByDouble(small, EVEN_OR_ODD, i -> 1.0d);
    Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
    Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 2 with ObjectDoubleMap

use of org.eclipse.collections.api.map.primitive.ObjectDoubleMap in project eclipse-collections by eclipse.

the class ParallelIterateTest method sumByFloat.

@Test
public void sumByFloat() {
    Interval interval = Interval.oneTo(100000);
    ObjectDoubleMap<String> sumByCount = ParallelIterate.sumByFloat(interval, EVEN_OR_ODD, i -> 1.0f);
    Assert.assertEquals(50000.0, sumByCount.get("Even"), 0.0);
    Assert.assertEquals(50000.0, sumByCount.get("Odd"), 0.0);
    ObjectDoubleMap<String> sumByValue = ParallelIterate.sumByFloat(interval, EVEN_OR_ODD, Integer::floatValue);
    Assert.assertEquals(interval.sumByFloat(EVEN_OR_ODD, Integer::floatValue), sumByValue);
    ObjectDoubleMap<Integer> sumByValue2 = ParallelIterate.sumByFloat(interval, i -> i % 1000, Integer::floatValue);
    Assert.assertEquals(interval.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue2);
    Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
    ObjectDoubleMap<String> sumByValue3 = ParallelIterate.sumByFloat(interval2, EVEN_OR_ODD, Integer::floatValue);
    Assert.assertEquals(interval2.sumByFloat(EVEN_OR_ODD, Integer::floatValue), sumByValue3);
    ObjectDoubleMap<Integer> sumByValue4 = ParallelIterate.sumByFloat(interval2, i -> i % 1000, Integer::floatValue);
    Assert.assertEquals(interval2.sumByFloat(i -> i % 1000, Integer::floatValue), sumByValue4);
    Interval small = Interval.oneTo(11);
    ObjectDoubleMap<String> smallSumByCount = ParallelIterate.sumByFloat(small, EVEN_OR_ODD, i -> 1.0f);
    Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
    Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Aggregations

BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LazyIterable (org.eclipse.collections.api.LazyIterable)2 RichIterable (org.eclipse.collections.api.RichIterable)2 Bag (org.eclipse.collections.api.bag.Bag)2 Function (org.eclipse.collections.api.block.function.Function)2 Function2 (org.eclipse.collections.api.block.function.Function2)2 Predicate (org.eclipse.collections.api.block.predicate.Predicate)2 Procedure (org.eclipse.collections.api.block.procedure.Procedure)2 Procedure2 (org.eclipse.collections.api.block.procedure.Procedure2)2 ObjectIntProcedure (org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure)2