Search in sources :

Example 71 with Sum

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

the class SelectIterableTest method forEachWith.

@Test
public void forEachWith() {
    InternalIterable<Integer> select = new SelectIterable<>(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 72 with Sum

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

the class TakeIterableTest method forEachWith.

@Test
public void forEachWith() {
    Procedure2<Integer, Sum> sumAdditionProcedure = (each, sum) -> sum.add(each);
    Sum sum1 = new IntegerSum(0);
    this.takeIterable.forEachWith(sumAdditionProcedure, sum1);
    Assert.assertEquals(3, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    this.emptyListTakeIterable.forEachWith(sumAdditionProcedure, sum2);
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    this.zeroCountTakeIterable.forEachWith(sumAdditionProcedure, sum3);
    Assert.assertEquals(0, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    this.sameCountTakeIterable.forEachWith(sumAdditionProcedure, sum5);
    Assert.assertEquals(15, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    this.higherCountTakeIterable.forEachWith(sumAdditionProcedure, sum6);
    Assert.assertEquals(15, sum6.getValue().intValue());
}
Also used : CountProcedure(org.eclipse.collections.impl.block.procedure.CountProcedure) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) Sum(org.eclipse.collections.impl.math.Sum) FastList(org.eclipse.collections.impl.list.mutable.FastList) LazyIterable(org.eclipse.collections.api.LazyIterable) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Interval(org.eclipse.collections.impl.list.Interval) Assert(org.junit.Assert) Before(org.junit.Before) 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 73 with Sum

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

the class TakeIterableTest method iterator.

@Override
@Test
public void iterator() {
    Sum sum1 = new IntegerSum(0);
    for (Integer each : this.takeIterable) {
        sum1.add(each);
    }
    Assert.assertEquals(3, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    for (Integer each : this.emptyListTakeIterable) {
        sum2.add(each);
    }
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    for (Integer each : this.zeroCountTakeIterable) {
        sum3.add(each);
    }
    Assert.assertEquals(0, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    for (Integer each : this.sameCountTakeIterable) {
        sum5.add(each);
    }
    Assert.assertEquals(15, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    for (Integer each : this.higherCountTakeIterable) {
        sum6.add(each);
    }
    Assert.assertEquals(15, sum6.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 74 with Sum

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

the class TakeWhileIterableTest method forEachWith.

@Test
public void forEachWith() {
    Procedure2<Integer, Sum> sumAdditionProcedure = (each, sum) -> sum.add(each);
    Sum sum1 = new IntegerSum(0);
    this.takeWhileIterable.forEachWith(sumAdditionProcedure, sum1);
    Assert.assertEquals(3, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    this.emptyListTakeWhileIterable.forEachWith(sumAdditionProcedure, sum2);
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    this.alwaysFalseTakeWhileIterable.forEachWith(sumAdditionProcedure, sum3);
    Assert.assertEquals(0, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    this.alwaysTrueTakeWhileIterable.forEachWith(sumAdditionProcedure, sum5);
    Assert.assertEquals(15, sum5.getValue().intValue());
}
Also used : CountProcedure(org.eclipse.collections.impl.block.procedure.CountProcedure) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) Sum(org.eclipse.collections.impl.math.Sum) FastList(org.eclipse.collections.impl.list.mutable.FastList) LazyIterable(org.eclipse.collections.api.LazyIterable) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Interval(org.eclipse.collections.impl.list.Interval) Assert(org.junit.Assert) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) 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 75 with Sum

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

the class IterateTest method forEachWithSets.

@Test
public void forEachWithSets() {
    Sum result = new IntegerSum(0);
    MutableSet<Integer> integers = Interval.toSet(1, 5);
    Iterate.forEachWith(integers, (each, parm) -> result.add(each.intValue() * parm.intValue()), 2);
    Assert.assertEquals(30, result.getValue().intValue());
}
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)

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