Search in sources :

Example 1 with Procedure2

use of org.eclipse.collections.api.block.procedure.Procedure2 in project eclipse-collections by eclipse.

the class DropIterableTest method forEachWith.

@Test
public void forEachWith() {
    Procedure2<Integer, Sum> sumAdditionProcedure = (each, sum) -> sum.add(each);
    Sum sum1 = new IntegerSum(0);
    this.dropIterable.forEachWith(sumAdditionProcedure, sum1);
    Assert.assertEquals(12, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    this.emptyListDropIterable.forEachWith(sumAdditionProcedure, sum2);
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    this.zeroCountDropIterable.forEachWith(sumAdditionProcedure, sum3);
    Assert.assertEquals(15, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    this.nearCountDropIterable.forEachWith(sumAdditionProcedure, sum5);
    Assert.assertEquals(5, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    this.sameCountDropIterable.forEachWith(sumAdditionProcedure, sum6);
    Assert.assertEquals(0, sum6.getValue().intValue());
    Sum sum7 = new IntegerSum(0);
    this.higherCountDropIterable.forEachWith(sumAdditionProcedure, sum7);
    Assert.assertEquals(0, sum7.getValue().intValue());
}
Also used : LazyIterable(org.eclipse.collections.api.LazyIterable) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) SumProcedure(org.eclipse.collections.impl.math.SumProcedure) 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) Test(org.junit.Test) Sum(org.eclipse.collections.impl.math.Sum) Assert(org.junit.Assert) FastList(org.eclipse.collections.impl.list.mutable.FastList) Before(org.junit.Before) 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 2 with Procedure2

use of org.eclipse.collections.api.block.procedure.Procedure2 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 3 with Procedure2

use of org.eclipse.collections.api.block.procedure.Procedure2 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 4 with Procedure2

use of org.eclipse.collections.api.block.procedure.Procedure2 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)

Aggregations

LazyIterable (org.eclipse.collections.api.LazyIterable)4 Procedure2 (org.eclipse.collections.api.block.procedure.Procedure2)4 ObjectIntProcedure (org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure)4 Interval (org.eclipse.collections.impl.list.Interval)4 FastList (org.eclipse.collections.impl.list.mutable.FastList)4 IntegerSum (org.eclipse.collections.impl.math.IntegerSum)4 Sum (org.eclipse.collections.impl.math.Sum)4 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)4 Assert (org.junit.Assert)4 Before (org.junit.Before)4 Test (org.junit.Test)4 Predicates (org.eclipse.collections.impl.block.factory.Predicates)2 CountProcedure (org.eclipse.collections.impl.block.procedure.CountProcedure)2 SumProcedure (org.eclipse.collections.impl.math.SumProcedure)2 Verify (org.eclipse.collections.impl.test.Verify)2