Search in sources :

Example 1 with MutableMultimap

use of org.eclipse.collections.api.multimap.MutableMultimap in project eclipse-collections by eclipse.

the class StackIterableTestCase method groupByEach.

@Override
@Test
public void groupByEach() {
    StackIterable<Integer> stack = this.newStackFromTopToBottom(1, 2, 3);
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    stack.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, stack.size()))));
    Multimap<Integer, Integer> actual = stack.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = stack.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) Predicate2(org.eclipse.collections.api.block.predicate.Predicate2) SetIterable(org.eclipse.collections.api.set.SetIterable) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) FloatHashSet(org.eclipse.collections.impl.set.mutable.primitive.FloatHashSet) ByteArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.ByteArrayStack) DoubleHashSet(org.eclipse.collections.impl.set.mutable.primitive.DoubleHashSet) FloatArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.FloatArrayStack) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) RichIterable(org.eclipse.collections.api.RichIterable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) Comparators(org.eclipse.collections.impl.block.factory.Comparators) BooleanHashSet(org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) AbstractRichIterableTestCase(org.eclipse.collections.impl.AbstractRichIterableTestCase) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) Procedures(org.eclipse.collections.impl.block.factory.Procedures) DoubleArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.DoubleArrayStack) MutableSortedSet(org.eclipse.collections.api.set.sorted.MutableSortedSet) TreeSortedSet(org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet) List(java.util.List) PartitionStack(org.eclipse.collections.api.partition.stack.PartitionStack) ListMultimap(org.eclipse.collections.api.multimap.list.ListMultimap) Lists(org.eclipse.collections.impl.factory.Lists) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) SortedBag(org.eclipse.collections.api.bag.sorted.SortedBag) IntArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.IntArrayStack) Function(org.eclipse.collections.api.block.function.Function) Stacks(org.eclipse.collections.impl.factory.Stacks) CharHashSet(org.eclipse.collections.impl.set.mutable.primitive.CharHashSet) ShortArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.ShortArrayStack) Procedure(org.eclipse.collections.api.block.procedure.Procedure) BooleanArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.BooleanArrayStack) FastList(org.eclipse.collections.impl.list.mutable.FastList) LongArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.LongArrayStack) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) ByteHashSet(org.eclipse.collections.impl.set.mutable.primitive.ByteHashSet) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) EmptyStackException(java.util.EmptyStackException) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) ArrayStack(org.eclipse.collections.impl.stack.mutable.ArrayStack) Bags(org.eclipse.collections.impl.factory.Bags) TreeSortedMap(org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap) CharArrayStack(org.eclipse.collections.impl.stack.mutable.primitive.CharArrayStack) StackIterable(org.eclipse.collections.api.stack.StackIterable) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) ShortHashSet(org.eclipse.collections.impl.set.mutable.primitive.ShortHashSet) MapIterable(org.eclipse.collections.api.map.MapIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) 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 MutableMultimap

use of org.eclipse.collections.api.multimap.MutableMultimap in project eclipse-collections by eclipse.

the class AbstractMemoryEfficientMutableSetTestCase method groupByEach.

@Test
public void groupByEach() {
    MutableSet<Integer> set = this.classUnderTest().collect(Integer::valueOf);
    MutableMultimap<Integer, Integer> expected = UnifiedSetMultimap.newMultimap();
    set.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, set.size()))));
    Multimap<Integer, Integer> actual = set.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = set.groupByEach(new NegativeIntervalFunction(), UnifiedSetMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Function(org.eclipse.collections.api.block.function.Function) Multimap(org.eclipse.collections.api.multimap.Multimap) UnsortedSetIterable(org.eclipse.collections.api.set.UnsortedSetIterable) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) UnmodifiableMutableSet(org.eclipse.collections.impl.set.mutable.UnmodifiableMutableSet) LazyIterable(org.eclipse.collections.api.LazyIterable) UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Interval(org.eclipse.collections.impl.list.Interval) MutableSetMultimap(org.eclipse.collections.api.multimap.set.MutableSetMultimap) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) Comparators(org.eclipse.collections.impl.block.factory.Comparators) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) SynchronizedMutableSet(org.eclipse.collections.impl.set.mutable.SynchronizedMutableSet) Bags(org.eclipse.collections.impl.factory.Bags) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) FixedSizeSet(org.eclipse.collections.api.set.FixedSizeSet) List(java.util.List) Lists(org.eclipse.collections.impl.factory.Lists) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) 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 3 with MutableMultimap

use of org.eclipse.collections.api.multimap.MutableMultimap in project eclipse-collections by eclipse.

the class DoubletonSetTest method groupByEach.

@Override
@Test
public void groupByEach() {
    super.groupByEach();
    MutableSet<Integer> set = Sets.fixedSize.of(1, 2);
    MutableMultimap<Integer, Integer> expected = UnifiedSetMultimap.newMultimap();
    set.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, set.size()))));
    Multimap<Integer, Integer> actual = set.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = set.groupByEach(new NegativeIntervalFunction(), UnifiedSetMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Multimap(org.eclipse.collections.api.multimap.Multimap) Twin(org.eclipse.collections.api.tuple.Twin) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) Iterables.mSet(org.eclipse.collections.impl.factory.Iterables.mSet) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) MutableSet(org.eclipse.collections.api.set.MutableSet) Lists(org.eclipse.collections.impl.factory.Lists) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Sets(org.eclipse.collections.impl.factory.Sets) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) Assert(org.junit.Assert) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Before(org.junit.Before) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 4 with MutableMultimap

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

Aggregations

MutableList (org.eclipse.collections.api.list.MutableList)4 Multimap (org.eclipse.collections.api.multimap.Multimap)4 MutableMultimap (org.eclipse.collections.api.multimap.MutableMultimap)4 Procedures (org.eclipse.collections.impl.block.factory.Procedures)4 NegativeIntervalFunction (org.eclipse.collections.impl.block.function.NegativeIntervalFunction)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Interval (org.eclipse.collections.impl.list.Interval)4 FastList (org.eclipse.collections.impl.list.mutable.FastList)4 UnifiedSet (org.eclipse.collections.impl.set.mutable.UnifiedSet)4 Verify (org.eclipse.collections.impl.test.Verify)4 Assert (org.junit.Assert)4 Test (org.junit.Test)4 Collections (java.util.Collections)3 List (java.util.List)3 RichIterable (org.eclipse.collections.api.RichIterable)3 Function (org.eclipse.collections.api.block.function.Function)3 MutableMap (org.eclipse.collections.api.map.MutableMap)3 Pair (org.eclipse.collections.api.tuple.Pair)3 IntegerPredicates (org.eclipse.collections.impl.block.factory.IntegerPredicates)3 Predicates (org.eclipse.collections.impl.block.factory.Predicates)3