Search in sources :

Example 31 with Interval

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

the class MutableListTestCase method MutableList_shuffleThis.

@Test
default void MutableList_shuffleThis() {
    Integer[] integers = Interval.oneTo(50).toArray();
    MutableList<Integer> mutableList1 = this.newWith(integers);
    MutableList<Integer> mutableList2 = this.newWith(integers);
    Collections.shuffle(mutableList1, new Random(10));
    assertEquals(mutableList1, mutableList2.shuffleThis(new Random(10)));
    MutableList<Integer> list = this.newWith(1, 2, 3);
    UnifiedSet<ImmutableList<Integer>> objects = UnifiedSet.newSet();
    while (objects.size() < 6) {
        objects.add(list.shuffleThis().toImmutable());
    }
    Interval interval = Interval.oneTo(1000);
    MutableList<Integer> bigList = this.newWith(interval.toArray());
    MutableList<Integer> shuffledBigList = bigList.shuffleThis(new Random(8));
    MutableList<Integer> integers1 = this.newWith(interval.toArray());
    assertEquals(integers1.shuffleThis(new Random(8)), bigList);
    assertSame(bigList, shuffledBigList);
    assertSame(bigList, bigList.shuffleThis());
    assertSame(bigList, bigList.shuffleThis(new Random(8)));
    assertEquals(interval.toBag(), bigList.toBag());
}
Also used : Random(java.util.Random) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Interval(org.eclipse.collections.impl.list.Interval) Test(org.junit.Test)

Example 32 with Interval

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

the class Collectors2Test method countBy.

@Test
public void countBy() {
    Interval integers = Interval.oneTo(100);
    MutableBag<Integer> counts = integers.stream().collect(Collectors2.countBy(i -> i % 2));
    Assert.assertEquals(integers.countBy(i -> i % 2), counts);
    Assert.assertEquals(50, counts.occurrencesOf(0));
    Assert.assertEquals(50, counts.occurrencesOf(1));
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) MutableObjectLongMap(org.eclipse.collections.api.map.primitive.MutableObjectLongMap) PartitionMutableCollection(org.eclipse.collections.api.partition.PartitionMutableCollection) Function(org.eclipse.collections.api.block.function.Function) Stacks(org.eclipse.collections.impl.factory.Stacks) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) MutableSortedMap(org.eclipse.collections.api.map.sorted.MutableSortedMap) BiMaps(org.eclipse.collections.impl.factory.BiMaps) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) Interval(org.eclipse.collections.impl.list.Interval) PartitionHashBag(org.eclipse.collections.impl.partition.bag.PartitionHashBag) SortedMaps(org.eclipse.collections.impl.factory.SortedMaps) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) List(java.util.List) Comparator(java.util.Comparator) Assert(org.junit.Assert) IntBags(org.eclipse.collections.impl.factory.primitive.IntBags) 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