use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class FJIterateTest method setUp.
@Before
public void setUp() {
Interval interval = Interval.oneTo(200);
this.iterables = Lists.immutable.of(interval.toList(), interval.toList().asUnmodifiable(), interval.toList().asSynchronized(), interval.toList().toImmutable(), interval.toSet(), interval.toSet().asUnmodifiable(), interval.toSet().asSynchronized(), interval.toSet().toImmutable(), interval.toBag(), interval.toBag().asUnmodifiable(), interval.toBag().asSynchronized(), interval.toBag().toImmutable(), interval.toSortedSet(), interval.toSortedSet().asUnmodifiable(), interval.toSortedSet().asSynchronized(), interval.toSortedSet().toImmutable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asUnmodifiable(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).asSynchronized(), interval.toMap(Functions.getPassThru(), Functions.getPassThru()).toImmutable(), new CompositeFastList<Integer>().withAll(interval.toList()), new CompositeFastList<Integer>().withAll(interval.toList()).asUnmodifiable(), new CompositeFastList<Integer>().withAll(interval.toList()).asSynchronized(), ArrayListAdapter.<Integer>newList().withAll(interval), ArrayListAdapter.<Integer>newList().withAll(interval).asUnmodifiable(), ArrayListAdapter.<Integer>newList().withAll(interval).asSynchronized(), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asUnmodifiable(), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).asUnmodifiable(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).toImmutable());
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class UnifiedMapTest method trimToSize.
@Test
public void trimToSize() {
UnifiedMap<String, String> map = UnifiedMap.newMap();
MutableMap<String, String> expected = Maps.mutable.empty();
Interval integers = Interval.fromTo(0, 250);
integers.each(each -> {
map.put(each.toString(), each.toString());
expected.put(each.toString(), each.toString());
});
ArrayIterate.forEach(FREQUENT_COLLISIONS, each -> {
map.put(each, each);
expected.put(each, each);
});
Assert.assertEquals(expected, map);
Assert.assertEquals(261, map.size());
MutableList<Integer> toRemove = Lists.mutable.withAll(Interval.evensFromTo(0, 20));
toRemove.addAll(Interval.oddsFromTo(35, 55));
toRemove.each(each -> {
map.remove(each.toString());
expected.remove(each.toString());
});
// First assertion to verify that trim does not happen since, the table is already at the smallest required power of 2.
Assert.assertFalse(map.trimToSize());
Assert.assertEquals(expected, map);
Assert.assertEquals(239, map.size());
Interval.evensFromTo(0, 250).each(each -> {
map.remove(each.toString());
expected.remove(each.toString());
});
// Second assertion to verify that trim happens since, the table length is less than smallest required power of 2.
Assert.assertTrue(map.trimToSize());
Assert.assertFalse(map.trimToSize());
Assert.assertEquals(expected, map);
Assert.assertEquals(124, map.size());
expected.forEachKey(each -> Assert.assertEquals(each, map.get(each)));
integers.each(each -> {
map.remove(each.toString());
expected.remove(each.toString());
});
Assert.assertTrue(map.trimToSize());
Assert.assertFalse(map.trimToSize());
Assert.assertEquals(expected, map);
expected.forEachKey(each -> Assert.assertEquals(each, map.get(each)));
map.clear();
expected.clear();
Assert.assertTrue(map.trimToSize());
Interval.zeroTo(20).each(each -> {
map.put(each.toString(), each.toString());
expected.put(each.toString(), each.toString());
});
Assert.assertFalse(map.trimToSize());
Interval.fromTo(9, 18).each(each -> {
map.remove(each.toString());
expected.remove(each.toString());
});
Assert.assertTrue(map.trimToSize());
Assert.assertFalse(map.trimToSize());
Assert.assertEquals(expected, map);
expected.forEachKey(each -> Assert.assertEquals(each, map.get(each)));
map.clear();
Assert.assertTrue(map.trimToSize());
Assert.assertTrue(map.isEmpty());
Interval.zeroTo(6).each(each -> map.put(each.toString(), each.toString()));
// Assert that trim does not happen as long as table.size is already as smaller than required
Assert.assertFalse(map.trimToSize());
map.put("7", "7");
map.removeKey("2");
map.removeKey("3");
// Assert that trim does not happen as long as table.size is as smaller as required
Assert.assertFalse(map.trimToSize());
map.removeKey("5");
map.removeKey("7");
Assert.assertTrue(map.trimToSize());
// Inflate the map so that table.length increases to next power of 2 and check that trim does not happen
map.put("2", "2");
map.put("5", "5");
map.put("7", "7");
// Assert that the resized table due to put is the required size and no need to trim that.
Assert.assertFalse(map.trimToSize());
Interval.zeroTo(4).each(each -> map.put(each.toString(), each.toString()));
Interval.oneTo(3).each(each -> map.removeKey(each.toString()));
Assert.assertTrue(map.trimToSize());
Assert.assertEquals(5, map.size());
}
use of org.eclipse.collections.impl.list.Interval 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.impl.list.Interval in project eclipse-collections by eclipse.
the class ParallelIterateTest method sumByLong.
@Test
public void sumByLong() {
Interval interval = Interval.oneTo(100000);
ObjectLongMap<String> sumByCount = ParallelIterate.sumByLong(interval, EVEN_OR_ODD, i -> 1L);
Assert.assertEquals(50000, sumByCount.get("Even"));
Assert.assertEquals(50000, sumByCount.get("Odd"));
ObjectLongMap<String> sumByValue = ParallelIterate.sumByLong(interval, EVEN_OR_ODD, Integer::longValue);
Assert.assertEquals(interval.sumByLong(EVEN_OR_ODD, Integer::longValue), sumByValue);
ObjectLongMap<Integer> sumByValue2 = ParallelIterate.sumByLong(interval, i -> i % 1000, Integer::longValue);
Assert.assertEquals(interval.sumByLong(i -> i % 1000, Integer::longValue), sumByValue2);
Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
ObjectLongMap<String> sumByValue3 = ParallelIterate.sumByLong(interval2, EVEN_OR_ODD, Integer::longValue);
Assert.assertEquals(interval2.sumByLong(EVEN_OR_ODD, Integer::longValue), sumByValue3);
ObjectLongMap<Integer> sumByValue4 = ParallelIterate.sumByLong(interval2, i -> i % 1000, Integer::longValue);
Assert.assertEquals(interval2.sumByLong(i -> i % 1000, Integer::longValue), sumByValue4);
Interval small = Interval.oneTo(11);
ObjectLongMap<String> smallSumByCount = ParallelIterate.sumByLong(small, EVEN_OR_ODD, i -> 1L);
Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.
the class ParallelIterateTest method setUp.
@Before
public void setUp() {
Interval interval = Interval.oneTo(200);
this.iterables = Lists.immutable.of(interval.toList(), interval.toList().asUnmodifiable(), interval.toList().asSynchronized(), interval.toList().toImmutable(), interval.toSet(), interval.toSet().asUnmodifiable(), interval.toSet().asSynchronized(), interval.toSet().toImmutable(), interval.toBag(), interval.toBag().asUnmodifiable(), interval.toBag().asSynchronized(), interval.toBag().toImmutable(), interval.toSortedSet(), interval.toSortedSet().asUnmodifiable(), interval.toSortedSet().asSynchronized(), interval.toSortedSet().toImmutable(), interval.toMap(Functions.identity(), Functions.identity()), interval.toMap(Functions.identity(), Functions.identity()).asUnmodifiable(), interval.toMap(Functions.identity(), Functions.identity()).asSynchronized(), interval.toMap(Functions.identity(), Functions.identity()).toImmutable(), new CompositeFastList<Integer>().withAll(interval.toList()), new CompositeFastList<Integer>().withAll(interval.toList()).asUnmodifiable(), new CompositeFastList<Integer>().withAll(interval.toList()).asSynchronized(), ArrayListAdapter.<Integer>newList().withAll(interval), ArrayListAdapter.<Integer>newList().withAll(interval).asUnmodifiable(), ArrayListAdapter.<Integer>newList().withAll(interval).asSynchronized(), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asUnmodifiable(), ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).asUnmodifiable(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).asSynchronized(), UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy()).withAll(interval).toImmutable());
}
Aggregations