use of org.eclipse.collections.api.map.MutableMap in project eclipse-collections by eclipse.
the class SerialParallelLazyPerformanceTest method forEach.
private void forEach(FastList<Integer> collection) {
MutableList<Runnable> runnables = FastList.newList();
runnables.add(() -> this.basicSerialForEachPerformance(collection, SERIAL_RUN_COUNT));
int cores = Runtime.getRuntime().availableProcessors();
ExecutorService service = Executors.newFixedThreadPool(cores);
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicParallelLazyForEachPerformance(collection, "Procedure", (Procedure<Integer>) each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
List<Integer> arrayList = new ArrayList<>(collection);
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(arrayList, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(arrayList, "Consumer", each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
this.shuffleAndRun(runnables);
service.shutdown();
try {
service.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.collections.api.map.MutableMap in project eclipse-collections by eclipse.
the class ParallelIterateTest method sumByBigInteger.
@Test
public void sumByBigInteger() {
MutableList<BigInteger> list = Interval.oneTo(100000).collect(Object::toString).collect(BigInteger::new).toList().shuffleThis();
MutableMap<String, BigInteger> sumByCount = ParallelIterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> BigInteger.valueOf(1L));
Assert.assertEquals(BigInteger.valueOf(50000L), sumByCount.get("Even"));
Assert.assertEquals(BigInteger.valueOf(50000L), sumByCount.get("Odd"));
MutableMap<String, BigInteger> sumByValue = ParallelIterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> bi), sumByValue);
MutableMap<Integer, BigInteger> sumByValue2 = ParallelIterate.sumByBigInteger(list, bi -> bi.intValue() % 1000, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list, bi -> bi.intValue() % 1000, bi -> bi), sumByValue2);
MutableList<BigInteger> list2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY).collect(Object::toString).collect(BigInteger::new).toList();
MutableMap<String, BigInteger> sumByValue3 = ParallelIterate.sumByBigInteger(list2, EVEN_OR_ODD_BI, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list2, EVEN_OR_ODD_BI, bi -> bi), sumByValue3);
MutableMap<Integer, BigInteger> sumByValue4 = ParallelIterate.sumByBigInteger(list2, bi -> bi.intValue() % 1000, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list2, bi -> bi.intValue() % 1000, bi -> bi), sumByValue4);
Interval small = Interval.oneTo(11);
MutableMap<String, BigInteger> smallSumByCount = ParallelIterate.sumByBigInteger(small, EVEN_OR_ODD, i -> BigInteger.valueOf(1L));
Assert.assertEquals(new BigInteger("5"), smallSumByCount.get("Even"));
Assert.assertEquals(new BigInteger("6"), smallSumByCount.get("Odd"));
}
use of org.eclipse.collections.api.map.MutableMap in project eclipse-collections by eclipse.
the class ParallelIterateTest method sumByBigDecimal.
@Test
public void sumByBigDecimal() {
MutableList<BigDecimal> list = Interval.oneTo(100000).collect(BigDecimal::new).toList().shuffleThis();
MutableMap<String, BigDecimal> sumByCount = ParallelIterate.sumByBigDecimal(list, EVEN_OR_ODD_BD, bd -> new BigDecimal(1L));
Assert.assertEquals(BigDecimal.valueOf(50000L), sumByCount.get("Even"));
Assert.assertEquals(BigDecimal.valueOf(50000L), sumByCount.get("Odd"));
MutableMap<String, BigDecimal> sumByValue = ParallelIterate.sumByBigDecimal(list, EVEN_OR_ODD_BD, bd -> bd);
Assert.assertEquals(Iterate.sumByBigDecimal(list, EVEN_OR_ODD_BD, bd -> bd), sumByValue);
MutableMap<Integer, BigDecimal> sumByValue2 = ParallelIterate.sumByBigDecimal(list, bd -> bd.intValue() % 1000, bd -> bd);
Assert.assertEquals(Iterate.sumByBigDecimal(list, bd -> bd.intValue() % 1000, bd -> bd), sumByValue2);
MutableList<BigDecimal> list2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY).collect(BigDecimal::new).toList();
MutableMap<String, BigDecimal> sumByValue3 = ParallelIterate.sumByBigDecimal(list2, EVEN_OR_ODD_BD, bd -> bd);
Assert.assertEquals(Iterate.sumByBigDecimal(list2, EVEN_OR_ODD_BD, bd -> bd), sumByValue3);
MutableMap<Integer, BigDecimal> sumByValue4 = ParallelIterate.sumByBigDecimal(list2, bd -> bd.intValue() % 1000, bd -> bd);
Assert.assertEquals(Iterate.sumByBigDecimal(list2, bd -> bd.intValue() % 1000, bd -> bd), sumByValue4);
Interval small = Interval.oneTo(11);
MutableMap<String, BigDecimal> smallSumByCount = ParallelIterate.sumByBigDecimal(small, EVEN_OR_ODD, i -> BigDecimal.valueOf(1L));
Assert.assertEquals(new BigDecimal(5), smallSumByCount.get("Even"));
Assert.assertEquals(new BigDecimal(6), smallSumByCount.get("Odd"));
}
use of org.eclipse.collections.api.map.MutableMap in project eclipse-collections by eclipse.
the class IterateTest method injectIntoIfProcedure.
@Test
public void injectIntoIfProcedure() {
Integer newItemToIndex = 99;
MutableMap<String, Integer> index1 = IterateTest.createPretendIndex(1);
MutableMap<String, Integer> index2 = IterateTest.createPretendIndex(2);
MutableMap<String, Integer> index3 = IterateTest.createPretendIndex(3);
MutableMap<String, Integer> index4 = IterateTest.createPretendIndex(4);
MutableMap<String, Integer> index5 = IterateTest.createPretendIndex(5);
MutableMap<String, MutableMap<String, Integer>> allIndexes = UnifiedMap.newMapWith(Tuples.pair("pretend index 1", index1), Tuples.pair("pretend index 2", index2), Tuples.pair("pretend index 3", index3), Tuples.pair("pretend index 4", index4), Tuples.pair("pretend index 5", index5));
MutableSet<MutableMap<String, Integer>> systemIndexes = Sets.fixedSize.of(index3, index5);
MapIterate.injectIntoIf(newItemToIndex, allIndexes, Predicates.notIn(systemIndexes), (itemToAdd, index) -> {
index.put(itemToAdd.toString(), itemToAdd);
return itemToAdd;
});
Verify.assertSize(5, allIndexes);
Verify.assertContainsKey("pretend index 2", allIndexes);
Verify.assertContainsKey("pretend index 3", allIndexes);
Verify.assertContainsKeyValue("99", newItemToIndex, index1);
Verify.assertContainsKeyValue("99", newItemToIndex, index2);
Verify.assertNotContainsKey("99", index3);
Verify.assertContainsKeyValue("99", newItemToIndex, index4);
Verify.assertNotContainsKey("99", index5);
}
Aggregations