Search in sources :

Example 11 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.

the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry.

@Test
public void batchIterable_forEachEntry() {
    BatchIterable<Map.Entry<Integer, Integer>> entries = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.newWithKeysValues(INTEGER_HASHING_STRATEGY, 1, 1, 2, 2, 3, 3, 4, 4).entrySet();
    Sum sum = new IntegerSum(0);
    entries.forEach(new EntrySumProcedure(sum));
    Assert.assertEquals(20, sum.getValue());
}
Also used : ImmutableEntry(org.eclipse.collections.impl.tuple.ImmutableEntry) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) HashMap(java.util.HashMap) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 12 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.

the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry_chains.

@Test
public void batchIterable_forEachEntry_chains() {
    BatchIterable<Map.Entry<Integer, Integer>> collisions = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.<Integer, Integer>newMap(INTEGER_HASHING_STRATEGY, 5).withKeysValues(COLLISION_1, 1, COLLISION_2, 2, COLLISION_3, 3, 1, 4).withKeysValues(2, 5, 3, 6).entrySet();
    Sum sum = new IntegerSum(0);
    collisions.forEach(new EntrySumProcedure(sum));
    Assert.assertEquals(78, sum.getValue());
}
Also used : ImmutableEntry(org.eclipse.collections.impl.tuple.ImmutableEntry) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) HashMap(java.util.HashMap) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 13 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.

the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry_null_handling.

@Test
public void batchIterable_forEachEntry_null_handling() {
    // Testing batchForEach handling null keys and null values
    Sum sum = new IntegerSum(0);
    BatchIterable<Map.Entry<Integer, Integer>> nulls = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.<Integer, Integer>newMap(INTEGER_HASHING_STRATEGY, 100).withKeysValues(null, 10, 1, null, 2, 11, 3, 12).withKeysValues(4, null, 5, null).entrySet();
    nulls.forEach(each -> {
        sum.add(each.getKey() == null ? 0 : each.getKey());
        sum.add(each.getValue() == null ? 0 : each.getValue());
    });
    Assert.assertEquals(48, sum.getValue());
}
Also used : ImmutableEntry(org.eclipse.collections.impl.tuple.ImmutableEntry) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) HashMap(java.util.HashMap) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 14 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.

the class UnifiedMapWithHashingStrategyTest 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>>) UnifiedMapWithHashingStrategy.newWithKeysValues(INTEGER_HASHING_STRATEGY, 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());
    }
}
Also used : ImmutableEntry(org.eclipse.collections.impl.tuple.ImmutableEntry) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) HashMap(java.util.HashMap) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 15 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable in project eclipse-collections by eclipse.

the class UnifiedMapWithHashingStrategyTest 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>>) UnifiedMapWithHashingStrategy.<Integer, Integer>newMap(INTEGER_HASHING_STRATEGY, 100).withKeysValues(null, 10, 1, null, 2, 11, 3, 12).withKeysValues(4, null, 5, null).entrySet();
    int numBatches = nulls.getBatchCount(7);
    for (int i = 0; i < numBatches; ++i) {
        nulls.batchForEach(each -> {
            sum4.add(each.getKey() == null ? 1 : each.getKey());
            sum4.add(each.getValue() == null ? 1 : each.getValue());
        }, i, numBatches);
    }
    Assert.assertEquals(52, sum4.getValue());
}
Also used : ImmutableEntry(org.eclipse.collections.impl.tuple.ImmutableEntry) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) HashMap(java.util.HashMap) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Aggregations

IntegerSum (org.eclipse.collections.impl.math.IntegerSum)20 Sum (org.eclipse.collections.impl.math.Sum)20 BatchIterable (org.eclipse.collections.impl.parallel.BatchIterable)20 Test (org.junit.Test)20 Map (java.util.Map)16 MutableMap (org.eclipse.collections.api.map.MutableMap)16 HashMap (java.util.HashMap)8 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)8 ImmutableEntry (org.eclipse.collections.impl.tuple.ImmutableEntry)8