use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchForEachEntry_null_handling.
@Test
public void batchForEachEntry_null_handling() {
// Testing batchForEach handling null keys and null values
Sum sum4 = new IntegerSum(0);
BatchIterable<Map.Entry<Integer, Integer>> nulls = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMap.<Integer, Integer>newMap(100).withKeysValues(null, 10, 1, null, 2, 11, 3, 12).withKeysValues(4, null, 5, null).entrySet();
for (int i = 0; i < nulls.getBatchCount(7); ++i) {
nulls.batchForEach(each -> {
sum4.add(each.getKey() == null ? 1 : each.getKey());
sum4.add(each.getValue() == null ? 1 : each.getValue());
}, i, nulls.getBatchCount(7));
}
Assert.assertEquals(52, sum4.getValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchForEachEmptyBatchIterable.
private void batchForEachEmptyBatchIterable(BatchIterable<Integer> batchIterable) {
// Test batchForEach on empty set, it should simply do nothing and not throw any exceptions
Sum sum = new IntegerSum(0);
batchIterable.batchForEach(new SumProcedure<>(sum), 0, batchIterable.getBatchCount(1));
Assert.assertEquals(0, sum.getValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class FastListTest method testLazySelectForEach.
/**
* @deprecated since 3.0. Use {@code asLazy().select(Predicate)} instead.
*/
@Deprecated
@Test
public void testLazySelectForEach() {
LazyIterable<Integer> select = FastList.newList(Interval.oneTo(5)).asLazy().select(Predicates.lessThan(5));
Sum sum = new IntegerSum(0);
select.forEach(new SumProcedure<>(sum));
Assert.assertEquals(10, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class ParallelArrayIterateTest method parallelForEach.
@Test
public void parallelForEach() {
Sum sum1 = new IntegerSum(0);
Integer[] array1 = this.createIntegerArray(16);
ParallelArrayIterate.forEach(array1, new SumProcedure<>(sum1), new SumCombiner<>(sum1), 1, array1.length / 2);
Assert.assertEquals(16, sum1.getValue());
Sum sum2 = new IntegerSum(0);
Integer[] array2 = this.createIntegerArray(7);
ParallelArrayIterate.forEach(array2, new SumProcedure<>(sum2), new SumCombiner<>(sum2));
Assert.assertEquals(7, sum2.getValue());
Sum sum3 = new IntegerSum(0);
Integer[] array3 = this.createIntegerArray(15);
ParallelArrayIterate.forEach(array3, new SumProcedure<>(sum3), new SumCombiner<>(sum3), 1, array3.length / 2);
Assert.assertEquals(15, sum3.getValue());
Sum sum4 = new IntegerSum(0);
Integer[] array4 = this.createIntegerArray(35);
ParallelArrayIterate.forEach(array4, new SumProcedure<>(sum4), new SumCombiner<>(sum4));
Assert.assertEquals(35, sum4.getValue());
Sum sum5 = new IntegerSum(0);
Integer[] array5 = this.createIntegerArray(40);
ParallelArrayIterate.forEach(array5, new SumProcedure<>(sum5), new SumCombiner<>(sum5), 1, array5.length / 2);
Assert.assertEquals(40, sum5.getValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class ImmutableUnifiedSetTest 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