Search in sources :

Example 6 with IntegerSum

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

the class DropWhileIterableTest method forEachWith.

@Test
public void forEachWith() {
    Procedure2<Integer, Sum> sumAdditionProcedure = (each, sum) -> sum.add(each);
    Sum sum1 = new IntegerSum(0);
    this.dropWhileIterable.forEachWith(sumAdditionProcedure, sum1);
    Assert.assertEquals(12, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    this.emptyListDropWhileIterable.forEachWith(sumAdditionProcedure, sum2);
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    this.alwaysFalseDropWhileIterable.forEachWith(sumAdditionProcedure, sum3);
    Assert.assertEquals(15, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    this.mostlyFalseDropWhileIterable.forEachWith(sumAdditionProcedure, sum5);
    Assert.assertEquals(5, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    this.alwaysTrueDropWhileIterable.forEachWith(sumAdditionProcedure, sum6);
    Assert.assertEquals(0, sum6.getValue().intValue());
}
Also used : SumProcedure(org.eclipse.collections.impl.math.SumProcedure) Test(org.junit.Test) 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 7 with IntegerSum

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

the class LazyIterableAdapterTest method iterator.

@Override
@Test
public void iterator() {
    LazyIterable<Integer> select = new LazyIterableAdapter<>(Interval.oneTo(5));
    Sum sum = new IntegerSum(0);
    for (Integer each : select) {
        sum.add(each);
    }
    Assert.assertEquals(15, sum.getValue().intValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) Test(org.junit.Test)

Example 8 with IntegerSum

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

the class LazyIterableAdapterTest method forEachWith.

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

Example 9 with IntegerSum

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

the class LazyIterableAdapterTest method forEach.

@Test
public void forEach() {
    LazyIterable<Integer> select = new LazyIterableAdapter<>(Interval.oneTo(5));
    Sum sum = new IntegerSum(0);
    select.forEach(new SumProcedure<>(sum));
    Assert.assertEquals(15, sum.getValue().intValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) Test(org.junit.Test)

Example 10 with IntegerSum

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

the class RejectIterableTest method forEachWithIndex.

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

Aggregations

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