use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchForEachEntry.
@Test
public void batchForEachEntry() {
// Testing batch size of 1 to 16 with no chains
BatchIterable<Map.Entry<Integer, Integer>> entries = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMap.newWithKeysValues(1, 1, 2, 2, 3, 3, 4, 4).entrySet();
for (int sectionCount = 1; sectionCount <= 16; ++sectionCount) {
Sum sum = new IntegerSum(0);
for (int sectionIndex = 0; sectionIndex < sectionCount; ++sectionIndex) {
entries.batchForEach(new EntrySumProcedure(sum), sectionIndex, sectionCount);
}
Assert.assertEquals(20, sum.getValue());
}
}
use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchForEachEntry_chains.
@Test
public void batchForEachEntry_chains() {
BatchIterable<Map.Entry<Integer, Integer>> collisions = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMap.<Integer, Integer>newMap(5).withKeysValues(COLLISION_1, 1, COLLISION_2, 2, COLLISION_3, 3, 1, 4).withKeysValues(2, 5, 3, 6).entrySet();
// Testing 1 batch with chains
Sum sum2 = new IntegerSum(0);
// testing getBatchCount returns 1
int numBatches = collisions.getBatchCount(100000);
for (int i = 0; i < numBatches; ++i) {
collisions.batchForEach(new EntrySumProcedure(sum2), i, numBatches);
}
Assert.assertEquals(1, numBatches);
Assert.assertEquals(78, sum2.getValue());
// Testing 3 batches with chains and uneven last batch
Sum sum3 = new IntegerSum(0);
for (int i = 0; i < 5; ++i) {
collisions.batchForEach(new EntrySumProcedure(sum3), i, 5);
}
Assert.assertEquals(78, sum3.getValue());
}
use of org.eclipse.collections.impl.parallel.BatchIterable 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.parallel.BatchIterable 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());
}
use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.
the class ImmutableUnifiedMapWithHashingStrategyTest method batchForEach.
@Test
public void batchForEach() {
Sum sum = new IntegerSum(0);
BatchIterable<String> integerBatchIterable = (BatchIterable<String>) this.classUnderTest();
integerBatchIterable.batchForEach(each -> sum.add(Integer.valueOf(each)), 0, 1);
Assert.assertEquals(10, sum.getValue());
}
Aggregations