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