Search in sources :

Example 1 with StackIterable

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

Aggregations

Collections (java.util.Collections)1 EmptyStackException (java.util.EmptyStackException)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RichIterable (org.eclipse.collections.api.RichIterable)1 SortedBag (org.eclipse.collections.api.bag.sorted.SortedBag)1 Function (org.eclipse.collections.api.block.function.Function)1 Function0 (org.eclipse.collections.api.block.function.Function0)1 Function2 (org.eclipse.collections.api.block.function.Function2)1 Predicate (org.eclipse.collections.api.block.predicate.Predicate)1 Predicate2 (org.eclipse.collections.api.block.predicate.Predicate2)1 Procedure (org.eclipse.collections.api.block.procedure.Procedure)1 MutableList (org.eclipse.collections.api.list.MutableList)1 MapIterable (org.eclipse.collections.api.map.MapIterable)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 ObjectDoubleMap (org.eclipse.collections.api.map.primitive.ObjectDoubleMap)1 Multimap (org.eclipse.collections.api.multimap.Multimap)1 MutableMultimap (org.eclipse.collections.api.multimap.MutableMultimap)1 ListMultimap (org.eclipse.collections.api.multimap.list.ListMultimap)1 PartitionStack (org.eclipse.collections.api.partition.stack.PartitionStack)1