Search in sources :

Example 1 with IntegerSum

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

the class IntervalTest method run.

@Test
public void run() {
    IntegerSum sum = new IntegerSum(0);
    Interval.oneTo(5).run(() -> sum.add(1));
    Assert.assertEquals(5, sum.getIntSum());
    IntegerSum sum2 = new IntegerSum(0);
    Interval.fromTo(5, 1).run(() -> sum2.add(1));
    Assert.assertEquals(5, sum2.getIntSum());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 2 with IntegerSum

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

the class IntervalTest method forEachWithIndex.

@Test
public void forEachWithIndex() {
    IntegerSum sum = new IntegerSum(0);
    Interval.oneTo(5).forEachWithIndex((ObjectIntProcedure<Integer>) (each, index) -> sum.add(each + index));
    Assert.assertEquals(25, sum.getIntSum());
    IntegerSum zeroSum = new IntegerSum(0);
    Interval.fromTo(0, -4).forEachWithIndex((ObjectIntProcedure<Integer>) (each, index) -> zeroSum.add(each + index));
    Assert.assertEquals(0, zeroSum.getIntSum());
    Verify.assertThrows(IndexOutOfBoundsException.class, () -> Interval.zeroTo(10).forEachWithIndex(null, -1, 10));
}
Also used : BigInteger(java.math.BigInteger) Iterator(java.util.Iterator) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) Iterate(org.eclipse.collections.impl.utility.Iterate) MutableList(org.eclipse.collections.api.list.MutableList) Executors(java.util.concurrent.Executors) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableSet(org.eclipse.collections.api.set.MutableSet) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Lists(org.eclipse.collections.impl.factory.Lists) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) BigInteger(java.math.BigInteger) NoSuchElementException(java.util.NoSuchElementException) Assert(org.junit.Assert) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 3 with IntegerSum

use of org.eclipse.collections.impl.math.IntegerSum 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 4 with IntegerSum

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

the class DropIterableTest method iterator.

@Override
@Test
public void iterator() {
    Sum sum1 = new IntegerSum(0);
    for (Integer each : this.dropIterable) {
        sum1.add(each);
    }
    Assert.assertEquals(12, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    for (Integer each : this.emptyListDropIterable) {
        sum2.add(each);
    }
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    for (Integer each : this.zeroCountDropIterable) {
        sum3.add(each);
    }
    Assert.assertEquals(15, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    for (Integer each : this.nearCountDropIterable) {
        sum5.add(each);
    }
    Assert.assertEquals(5, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    for (Integer each : this.sameCountDropIterable) {
        sum6.add(each);
    }
    Assert.assertEquals(0, sum6.getValue().intValue());
    Sum sum7 = new IntegerSum(0);
    for (Integer each : this.higherCountDropIterable) {
        sum7.add(each);
    }
    Assert.assertEquals(0, sum7.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 5 with IntegerSum

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

the class DropWhileIterableTest method forEach.

@Test
public void forEach() {
    Sum sum1 = new IntegerSum(0);
    this.dropWhileIterable.forEach(new SumProcedure<>(sum1));
    Assert.assertEquals(12, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    this.emptyListDropWhileIterable.forEach(new SumProcedure<>(sum2));
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    this.alwaysFalseDropWhileIterable.forEach(new SumProcedure<>(sum3));
    Assert.assertEquals(15, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    this.mostlyFalseDropWhileIterable.forEach(new SumProcedure<>(sum5));
    Assert.assertEquals(5, sum5.getValue().intValue());
    Sum sum6 = new IntegerSum(0);
    this.alwaysTrueDropWhileIterable.forEach(new SumProcedure<>(sum6));
    Assert.assertEquals(0, 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)

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