Search in sources :

Example 76 with Sum

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

the class LazyIterateTest method rejectForEachWithIndex.

@Test
public void rejectForEachWithIndex() {
    LazyIterable<Integer> select = LazyIterate.reject(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEachWithIndex((object, index) -> {
        sum.add(object);
        sum.add(index);
    });
    Assert.assertEquals(5, 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 77 with Sum

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

the class LazyIterateTest method rejectIterator.

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

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

the class IterableIterateTest method injectIntoWithOver30.

@Test
public void injectIntoWithOver30() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    List<Integer> integers = Interval.oneTo(31);
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(result, integers, function, parameter);
    Assert.assertEquals(0, 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 79 with Sum

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

the class MapIterableTestCase method injectInto.

@Test
public void injectInto() {
    MapIterable<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
    Integer actual = map.injectInto(0, AddFunction.INTEGER);
    Assert.assertEquals(Integer.valueOf(10), actual);
    Sum sum = map.injectInto(new IntegerSum(0), SumProcedure.number());
    Assert.assertEquals(new IntegerSum(10), sum);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 80 with Sum

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

the class FastListTest method testLazyRejectForEach.

/**
 * @deprecated since 3.0. Use {@code asLazy().reject(Predicate)} instead.
 */
@Deprecated
@Test
public void testLazyRejectForEach() {
    LazyIterable<Integer> select = FastList.newList(Interval.oneTo(5)).asLazy().reject(Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEach(new SumProcedure<>(sum));
    Assert.assertEquals(5, 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)

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