Search in sources :

Example 16 with IntegerSum

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

the class SelectIterableTest method forEach.

@Test
public void forEach() {
    InternalIterable<Integer> select = new SelectIterable<>(Interval.oneTo(5), Predicates.lessThan(5));
    Sum sum = new IntegerSum(0);
    select.forEach(new SumProcedure<>(sum));
    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 17 with IntegerSum

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

the class SelectIterableTest method forEachWithIndex.

@Test
public void forEachWithIndex() {
    InternalIterable<Integer> select = new SelectIterable<>(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);
        LOGGER.info("value={} index={}", object, index);
    });
    Assert.assertEquals(13, 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 18 with IntegerSum

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

the class TakeWhileIterableTest method iterator.

@Override
@Test
public void iterator() {
    Sum sum1 = new IntegerSum(0);
    for (Integer each : this.takeWhileIterable) {
        sum1.add(each);
    }
    Assert.assertEquals(3, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    for (Integer each : this.emptyListTakeWhileIterable) {
        sum2.add(each);
    }
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    for (Integer each : this.alwaysFalseTakeWhileIterable) {
        sum3.add(each);
    }
    Assert.assertEquals(0, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    for (Integer each : this.alwaysTrueTakeWhileIterable) {
        sum5.add(each);
    }
    Assert.assertEquals(15, sum5.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 19 with IntegerSum

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

the class ArrayListIterateTest method injectIntoWithOver100.

@Test
public void injectIntoWithOver100() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
    Sum sumOfDoubledValues = ArrayListIterate.injectIntoWith(result, this.getOver100IntegerList(), function, parameter);
    Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
Also used : Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) MutableFloatList(org.eclipse.collections.api.list.primitive.MutableFloatList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Function(org.eclipse.collections.api.block.function.Function) Sum(org.eclipse.collections.impl.math.Sum) MutableByteList(org.eclipse.collections.api.list.primitive.MutableByteList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Test(org.junit.Test) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) 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 20 with IntegerSum

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

the class IterateTest method injectIntoWithRandomAccess.

@Test
public void injectIntoWithRandomAccess() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    MutableList<Integer> integers = Interval.oneTo(5).toList().asSynchronized();
    this.basicTestDoubleSum(result, integers, parameter);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) 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