Search in sources :

Example 26 with IntegerSum

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

Example 27 with IntegerSum

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

the class LazyIterateTest method selectIterator.

@Test
public void selectIterator() {
    LazyIterable<Integer> select = LazyIterate.select(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    for (Integer each : select) {
        sum.add(each);
    }
    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 28 with IntegerSum

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

the class IterableIterateTest method forEachWith.

@Test
public void forEachWith() {
    Sum result = new IntegerSum(0);
    Iterable<Integer> integers = new IterableAdapter<>(Interval.oneTo(5));
    Iterate.forEachWith(integers, (each, parm) -> result.add(each.intValue() * parm.intValue()), 2);
    Assert.assertEquals(30, result.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 29 with IntegerSum

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

the class IterableIterateTest method injectIntoWith.

@Test
public void injectIntoWith() {
    Sum result = new IntegerSum(0);
    Iterable<Integer> iterable = new IterableAdapter<>(Interval.oneTo(5));
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add(element.intValue() * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(result, iterable, function, 2);
    Assert.assertEquals(30, sumOfDoubledValues.getValue().intValue());
}
Also used : Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) Sum(org.eclipse.collections.impl.math.Sum) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) Interval(org.eclipse.collections.impl.list.Interval) LinkedList(java.util.LinkedList) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Objects(java.util.Objects) List(java.util.List) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Lists(org.eclipse.collections.impl.factory.Lists) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Optional(java.util.Optional) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) 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 30 with IntegerSum

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

the class ImmutableUnifiedSetWithHashingStrategyTest method batchForEach.

@Test
public void batchForEach() {
    Sum sum = new IntegerSum(0);
    BatchIterable<Integer> integerBatchIterable = (BatchIterable<Integer>) this.newSet(1, 2, 3, 4, 5);
    integerBatchIterable.batchForEach(new SumProcedure<>(sum), 0, 1);
    Assert.assertEquals(15, sum.getValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) 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