Search in sources :

Example 21 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class IterateTest method injectIntoWithHashSet.

@Test
public void injectIntoWithHashSet() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    MutableSet<Integer> integers = Interval.toSet(1, 5);
    this.basicTestDoubleSum(result, integers, parameter);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 22 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class IterateTest method basicTestDoubleSum.

private void basicTestDoubleSum(Sum newResult, Collection<Integer> newIntegers, Integer newParameter) {
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add(element.intValue() * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(newResult, newIntegers, function, newParameter);
    Assert.assertEquals(30, sumOfDoubledValues.getValue().intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Maps(org.eclipse.collections.impl.factory.Maps) Arrays(java.util.Arrays) Multimap(org.eclipse.collections.api.multimap.Multimap) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) PairPredicate(org.eclipse.collections.impl.block.predicate.PairPredicate) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) RichIterable(org.eclipse.collections.api.RichIterable) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) TreeBagMultimap(org.eclipse.collections.impl.multimap.bag.sorted.mutable.TreeBagMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) Comparators(org.eclipse.collections.impl.block.factory.Comparators) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) MutableSortedBagMultimap(org.eclipse.collections.api.multimap.sortedbag.MutableSortedBagMultimap) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) Set(java.util.Set) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) Procedures(org.eclipse.collections.impl.block.factory.Procedures) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) TreeSortedSetMultimap(org.eclipse.collections.impl.multimap.set.sorted.TreeSortedSetMultimap) List(java.util.List) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) Optional(java.util.Optional) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Function(org.eclipse.collections.api.block.function.Function) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) Iterables.iBag(org.eclipse.collections.impl.factory.Iterables.iBag) Sum(org.eclipse.collections.impl.math.Sum) TreeSet(java.util.TreeSet) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Function3(org.eclipse.collections.api.block.function.Function3) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) Function2(org.eclipse.collections.api.block.function.Function2) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableSetMultimap(org.eclipse.collections.api.multimap.set.MutableSetMultimap) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) MutableSortedSetMultimap(org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap) Collectors2(org.eclipse.collections.impl.collector.Collectors2) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) Bags(org.eclipse.collections.impl.factory.Bags) Test(org.junit.Test) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) Iterables.iSet(org.eclipse.collections.impl.factory.Iterables.iSet) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ImmutableList(org.eclipse.collections.api.list.ImmutableList) BagMultimap(org.eclipse.collections.api.multimap.bag.BagMultimap) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) Sets(org.eclipse.collections.impl.factory.Sets) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) MapIterable(org.eclipse.collections.api.map.MapIterable) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum)

Example 23 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class LazyIterateTest method selectForEachWith.

@Test
public void selectForEachWith() {
    LazyIterable<Integer> select = LazyIterate.select(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEachWith((each, aSum) -> aSum.add(each), sum);
    Assert.assertEquals(10, sum.getValue().intValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 24 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class LazyIterateTest method rejectForEachWith.

@Test
public void rejectForEachWith() {
    LazyIterable<Integer> select = LazyIterate.reject(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEachWith((each, aSum) -> aSum.add(each), sum);
    Assert.assertEquals(5, sum.getValue().intValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 25 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class LazyIterateTest method selectForEachWithIndex.

@Test
public void selectForEachWithIndex() {
    LazyIterable<Integer> select = LazyIterate.select(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEachWithIndex((object, index) -> {
        sum.add(object);
        sum.add(index);
    });
    Assert.assertEquals(16, sum.getValue().intValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Aggregations

IntegerSum (org.eclipse.collections.impl.math.IntegerSum)88 Sum (org.eclipse.collections.impl.math.Sum)88 Test (org.junit.Test)76 BatchIterable (org.eclipse.collections.impl.parallel.BatchIterable)20 MutableMap (org.eclipse.collections.api.map.MutableMap)17 Map (java.util.Map)16 Interval (org.eclipse.collections.impl.list.Interval)10 FastList (org.eclipse.collections.impl.list.mutable.FastList)10 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)10 Assert (org.junit.Assert)10 ObjectIntProcedure (org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure)9 HashMap (java.util.HashMap)8 ImmutableEntry (org.eclipse.collections.impl.tuple.ImmutableEntry)8 Procedure2 (org.eclipse.collections.api.block.procedure.Procedure2)7 Predicates (org.eclipse.collections.impl.block.factory.Predicates)7 Before (org.junit.Before)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LazyIterable (org.eclipse.collections.api.LazyIterable)6 Verify (org.eclipse.collections.impl.test.Verify)6 BigInteger (java.math.BigInteger)5