Search in sources :

Example 1 with BatchIterable

use of org.eclipse.collections.impl.parallel.BatchIterable 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());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 2 with BatchIterable

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

the class UnifiedMapWithHashingStrategyTest method batchForEachEntry_chains.

@Test
public void batchForEachEntry_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();
    // Testing 1 batch with chains
    Sum sum2 = new IntegerSum(0);
    // testing getBatchCount returns 1
    int batchCount = collisions.getBatchCount(100000);
    for (int i = 0; i < batchCount; ++i) {
        collisions.batchForEach(new EntrySumProcedure(sum2), i, batchCount);
    }
    Assert.assertEquals(1, batchCount);
    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());
}
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 3 with BatchIterable

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

the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry_emptySet.

@Test
public void batchIterable_forEachEntry_emptySet() {
    // Test forEach on empty set, it should simply do nothing and not throw any exceptions
    Sum sum = new IntegerSum(0);
    BatchIterable<Map.Entry<Integer, Integer>> empty = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.newMap(INTEGER_HASHING_STRATEGY).entrySet();
    empty.forEach(new EntrySumProcedure(sum));
    Assert.assertEquals(0, 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 4 with BatchIterable

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

the class UnifiedMapWithHashingStrategyTest method batchForEachEntry_emptySet.

@Test
public void batchForEachEntry_emptySet() {
    // Test batchForEach on empty set, it should simply do nothing and not throw any exceptions
    Sum sum5 = new IntegerSum(0);
    BatchIterable<Map.Entry<Integer, Integer>> empty = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.newMap(INTEGER_HASHING_STRATEGY).entrySet();
    empty.batchForEach(new EntrySumProcedure(sum5), 0, empty.getBatchCount(1));
    Assert.assertEquals(0, sum5.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 5 with BatchIterable

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

the class UnifiedMapTest method batchIterable_forEachEntry_emptySet.

@Test
public void batchIterable_forEachEntry_emptySet() {
    // Test forEach on empty set, it should simply do nothing and not throw any exceptions
    Sum sum = new IntegerSum(0);
    BatchIterable<Map.Entry<Integer, Integer>> empty = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMap.newMap().entrySet();
    empty.forEach(new EntrySumProcedure(sum));
    Assert.assertEquals(0, sum.getValue());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) 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