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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations