Search in sources :

Example 1 with ImmutableList

use of org.eclipse.collections.api.list.ImmutableList in project eclipse-collections by eclipse.

the class AbstractImmutableListTestCase method groupByEach.

@Test
public void groupByEach() {
    ImmutableList<Integer> list = this.classUnderTest();
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    list.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, list.size()))));
    Multimap<Integer, Integer> actual = list.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = list.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : ListIterator(java.util.ListIterator) Multimap(org.eclipse.collections.api.multimap.Multimap) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) IntSets(org.eclipse.collections.impl.factory.primitive.IntSets) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) ImmutableBooleanCollection(org.eclipse.collections.api.collection.primitive.ImmutableBooleanCollection) RichIterable(org.eclipse.collections.api.RichIterable) Functions(org.eclipse.collections.impl.block.factory.Functions) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Iterate(org.eclipse.collections.impl.utility.Iterate) ImmutableListMultimap(org.eclipse.collections.api.multimap.list.ImmutableListMultimap) PartitionImmutableList(org.eclipse.collections.api.partition.list.PartitionImmutableList) List(java.util.List) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Function(org.eclipse.collections.api.block.function.Function) ImmutableCollection(org.eclipse.collections.api.collection.ImmutableCollection) MutableStack(org.eclipse.collections.api.stack.MutableStack) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) MutableMap(org.eclipse.collections.api.map.MutableMap) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) HashingStrategy(org.eclipse.collections.api.block.HashingStrategy) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) AbstractImmutableCollectionTestCase(org.eclipse.collections.impl.collection.immutable.AbstractImmutableCollectionTestCase) Test(org.junit.Test) ListIterate(org.eclipse.collections.impl.utility.ListIterate) IntLists(org.eclipse.collections.impl.factory.primitive.IntLists) IntInterval(org.eclipse.collections.impl.list.primitive.IntInterval) ImmutableList(org.eclipse.collections.api.list.ImmutableList) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) Sets(org.eclipse.collections.impl.factory.Sets) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 2 with ImmutableList

use of org.eclipse.collections.api.list.ImmutableList 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)

Aggregations

ImmutableList (org.eclipse.collections.api.list.ImmutableList)2 Interval (org.eclipse.collections.impl.list.Interval)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Random (java.util.Random)1 RichIterable (org.eclipse.collections.api.RichIterable)1 HashingStrategy (org.eclipse.collections.api.block.HashingStrategy)1 Function (org.eclipse.collections.api.block.function.Function)1 ImmutableCollection (org.eclipse.collections.api.collection.ImmutableCollection)1 MutableCollection (org.eclipse.collections.api.collection.MutableCollection)1 ImmutableBooleanCollection (org.eclipse.collections.api.collection.primitive.ImmutableBooleanCollection)1 MutableList (org.eclipse.collections.api.list.MutableList)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 Multimap (org.eclipse.collections.api.multimap.Multimap)1 MutableMultimap (org.eclipse.collections.api.multimap.MutableMultimap)1