Search in sources :

Example 6 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class ParallelIterateTest method sumByDouble.

@Test
public void sumByDouble() {
    Interval interval = Interval.oneTo(100000);
    ObjectDoubleMap<String> sumByCount = ParallelIterate.sumByDouble(interval, EVEN_OR_ODD, i -> 1.0d);
    Assert.assertEquals(50000.0, sumByCount.get("Even"), 0.0);
    Assert.assertEquals(50000.0, sumByCount.get("Odd"), 0.0);
    ObjectDoubleMap<String> sumByValue = ParallelIterate.sumByDouble(interval, EVEN_OR_ODD, Integer::doubleValue);
    Assert.assertEquals(interval.sumByDouble(EVEN_OR_ODD, Integer::doubleValue), sumByValue);
    ObjectDoubleMap<Integer> sumByValue2 = ParallelIterate.sumByDouble(interval, i -> i % 1000, Integer::doubleValue);
    Assert.assertEquals(interval.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue2);
    Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
    ObjectDoubleMap<String> sumByValue3 = ParallelIterate.sumByDouble(interval2, EVEN_OR_ODD, Integer::doubleValue);
    Assert.assertEquals(interval2.sumByDouble(EVEN_OR_ODD, Integer::doubleValue), sumByValue3);
    ObjectDoubleMap<Integer> sumByValue4 = ParallelIterate.sumByDouble(interval2, i -> i % 1000, Integer::doubleValue);
    Assert.assertEquals(interval2.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue4);
    Interval small = Interval.oneTo(11);
    ObjectDoubleMap<String> smallSumByCount = ParallelIterate.sumByDouble(small, EVEN_OR_ODD, i -> 1.0d);
    Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
    Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 7 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class ParallelIterateTest method sumByInt.

@Test
public void sumByInt() {
    Interval interval = Interval.oneTo(100000);
    ObjectLongMap<String> sumByCount = ParallelIterate.sumByInt(interval, EVEN_OR_ODD, i -> 1);
    Assert.assertEquals(50000, sumByCount.get("Even"));
    Assert.assertEquals(50000, sumByCount.get("Odd"));
    ObjectLongMap<String> sumByValue = ParallelIterate.sumByInt(interval, EVEN_OR_ODD, Integer::intValue);
    Assert.assertEquals(interval.sumByInt(EVEN_OR_ODD, Integer::intValue), sumByValue);
    ObjectLongMap<Integer> sumByValue2 = ParallelIterate.sumByInt(interval, i -> i % 1000, Integer::intValue);
    Assert.assertEquals(interval.sumByInt(i -> i % 1000, Integer::intValue), sumByValue2);
    Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
    ObjectLongMap<String> sumByValue3 = ParallelIterate.sumByInt(interval2, EVEN_OR_ODD, Integer::intValue);
    Assert.assertEquals(interval2.sumByInt(EVEN_OR_ODD, Integer::intValue), sumByValue3);
    ObjectLongMap<Integer> sumByValue4 = ParallelIterate.sumByInt(interval2, i -> i % 1000, Integer::intValue);
    Assert.assertEquals(interval2.sumByInt(i -> i % 1000, Integer::intValue), sumByValue4);
    Interval small = Interval.oneTo(11);
    ObjectLongMap<String> smallSumByCount = ParallelIterate.sumByInt(small, EVEN_OR_ODD, i -> 1);
    Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
    Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 8 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class ParallelIterateTest method sumByFloat.

@Test
public void sumByFloat() {
    Interval interval = Interval.oneTo(100000);
    ObjectDoubleMap<String> sumByCount = ParallelIterate.sumByFloat(interval, EVEN_OR_ODD, i -> 1.0f);
    Assert.assertEquals(50000.0, sumByCount.get("Even"), 0.0);
    Assert.assertEquals(50000.0, sumByCount.get("Odd"), 0.0);
    ObjectDoubleMap<String> sumByValue = ParallelIterate.sumByFloat(interval, EVEN_OR_ODD, Integer::floatValue);
    Assert.assertEquals(interval.sumByFloat(EVEN_OR_ODD, Integer::floatValue), sumByValue);
    ObjectDoubleMap<Integer> sumByValue2 = ParallelIterate.sumByFloat(interval, i -> i % 1000, Integer::floatValue);
    Assert.assertEquals(interval.sumByDouble(i -> i % 1000, Integer::doubleValue), sumByValue2);
    Interval interval2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY);
    ObjectDoubleMap<String> sumByValue3 = ParallelIterate.sumByFloat(interval2, EVEN_OR_ODD, Integer::floatValue);
    Assert.assertEquals(interval2.sumByFloat(EVEN_OR_ODD, Integer::floatValue), sumByValue3);
    ObjectDoubleMap<Integer> sumByValue4 = ParallelIterate.sumByFloat(interval2, i -> i % 1000, Integer::floatValue);
    Assert.assertEquals(interval2.sumByFloat(i -> i % 1000, Integer::floatValue), sumByValue4);
    Interval small = Interval.oneTo(11);
    ObjectDoubleMap<String> smallSumByCount = ParallelIterate.sumByFloat(small, EVEN_OR_ODD, i -> 1.0f);
    Assert.assertEquals(5.0, smallSumByCount.get("Even"), 0.0);
    Assert.assertEquals(6.0, smallSumByCount.get("Odd"), 0.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 9 with Interval

use of org.eclipse.collections.impl.list.Interval 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"));
}
Also used : Arrays(java.util.Arrays) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) UnifiedSetWithHashingStrategy(org.eclipse.collections.impl.set.strategy.mutable.UnifiedSetWithHashingStrategy) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) After(org.junit.After) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Collection(java.util.Collection) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) Executors(java.util.concurrent.Executors) ListAdapter(org.eclipse.collections.impl.list.mutable.ListAdapter) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) Lists(org.eclipse.collections.impl.factory.Lists) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) Procedure(org.eclipse.collections.api.block.procedure.Procedure) ArrayListAdapter(org.eclipse.collections.impl.list.mutable.ArrayListAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) LazyIterable(org.eclipse.collections.api.LazyIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) SynchronizedPutUnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.SynchronizedPutUnifiedSetMultimap) Function2(org.eclipse.collections.api.block.function.Function2) SynchronizedPutHashBagMultimap(org.eclipse.collections.impl.multimap.bag.SynchronizedPutHashBagMultimap) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) Test(org.junit.Test) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) ImmutableList(org.eclipse.collections.api.list.ImmutableList) MapIterable(org.eclipse.collections.api.map.MapIterable) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 10 with Interval

use of org.eclipse.collections.impl.list.Interval in project eclipse-collections by eclipse.

the class UnifiedSetWithHashingStrategyTest method trimToSize.

@Test
public void trimToSize() {
    UnifiedSetWithHashingStrategy<String> set = UnifiedSetWithHashingStrategy.newSet(HashingStrategies.defaultStrategy());
    MutableSet<String> expected = Sets.mutable.empty();
    Interval integers = Interval.fromTo(0, 250);
    integers.each(each -> {
        set.add(each.toString());
        expected.add(each.toString());
    });
    ArrayIterate.forEach(FREQUENT_COLLISIONS, each -> {
        set.add(each);
        expected.add(each);
    });
    Assert.assertEquals(expected, set);
    Assert.assertEquals(261, set.size());
    MutableList<Integer> toRemove = Lists.mutable.withAll(Interval.evensFromTo(0, 20));
    toRemove.addAll(Interval.oddsFromTo(35, 55));
    toRemove.each(each -> {
        set.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(set.trimToSize());
    Assert.assertEquals(239, set.size());
    Assert.assertEquals(expected, set);
    Interval.evensFromTo(0, 250).each(each -> {
        set.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(set.trimToSize());
    Assert.assertFalse(set.trimToSize());
    Assert.assertEquals(expected, set);
    Assert.assertEquals(124, set.size());
    expected.each(each -> Assert.assertEquals(each, set.get(each)));
    integers.each(each -> {
        set.remove(each.toString());
        expected.remove(each.toString());
    });
    Assert.assertTrue(set.trimToSize());
    Assert.assertFalse(set.trimToSize());
    Assert.assertEquals(expected, set);
    expected.each(each -> Assert.assertEquals(each, set.get(each)));
    set.clear();
    Assert.assertTrue(set.trimToSize());
    Interval.oneTo(4).each(each -> set.add(each.toString()));
    // Assert that trim does not happen after puts
    Assert.assertFalse(set.trimToSize());
    set.remove("1");
    set.remove("2");
    Assert.assertTrue(set.trimToSize());
    set.add("1");
    // Assert that the resized table due to put is the required size and no need to trim that.
    Assert.assertFalse(set.trimToSize());
    Interval.zeroTo(4).each(each -> set.add(each.toString()));
    Interval.oneTo(3).each(each -> set.remove(each.toString()));
    Assert.assertTrue(set.trimToSize());
    Assert.assertEquals(2, set.size());
}
Also used : Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Aggregations

Interval (org.eclipse.collections.impl.list.Interval)32 Test (org.junit.Test)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 LinkedList (java.util.LinkedList)10 CompositeFastList (org.eclipse.collections.impl.list.mutable.CompositeFastList)10 Before (org.junit.Before)10 Function (org.eclipse.collections.api.block.function.Function)9 FastList (org.eclipse.collections.impl.list.mutable.FastList)9 Verify (org.eclipse.collections.impl.test.Verify)9 Assert (org.junit.Assert)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 MutableList (org.eclipse.collections.api.list.MutableList)8 MutableMap (org.eclipse.collections.api.map.MutableMap)8 BigInteger (java.math.BigInteger)7 Function2 (org.eclipse.collections.api.block.function.Function2)7 ImmutableList (org.eclipse.collections.api.list.ImmutableList)7 Predicates (org.eclipse.collections.impl.block.factory.Predicates)7 BigDecimal (java.math.BigDecimal)6 Arrays (java.util.Arrays)6