Search in sources :

Example 1 with NegativeIntervalFunction

use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.

the class ImmutableBagTestCase method groupByEach.

@Override
@Test
public void groupByEach() {
    super.groupByEach();
    ImmutableBag<Integer> immutableBag = this.newBag().collect(Integer::valueOf);
    MutableMultimap<Integer, Integer> expected = HashBagMultimap.newMultimap();
    int keys = this.numKeys();
    immutableBag.forEachWithOccurrences((each, parameter) -> {
        HashBag<Integer> bag = HashBag.newBag();
        Interval.fromTo(each, keys).forEach((int eachInt) -> bag.addOccurrences(eachInt, eachInt));
        expected.putAll(-each, bag);
    });
    Multimap<Integer, Integer> actual = immutableBag.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = immutableBag.groupByEach(new NegativeIntervalFunction(), HashBagMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 2 with NegativeIntervalFunction

use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.

the class AbstractRichIterableTestCase method groupByEach.

@Test
public void groupByEach() {
    RichIterable<Integer> collection = this.newWith(1, 2, 3, 4, 5, 6, 7);
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    MutableMultimap<Integer, Integer> expected = this.<Integer>newWith().groupByEach(function).toMutable();
    for (int i = 1; i < 8; i++) {
        expected.putAll(-i, Interval.fromTo(i, 7));
    }
    Multimap<Integer, Integer> actual = collection.groupByEach(function);
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = collection.groupByEach(function, this.<Integer>newWith().groupByEach(function).toMutable());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 3 with NegativeIntervalFunction

use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction 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 4 with NegativeIntervalFunction

use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction 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 5 with NegativeIntervalFunction

use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.

the class AbstractImmutableSortedSetTestCase method groupByEachWithTarget.

@Test
public void groupByEachWithTarget() {
    ImmutableSortedSet<Integer> undertest = this.classUnderTest();
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    TreeSortedSetMultimap<Integer, Integer> actual = undertest.groupByEach(function, TreeSortedSetMultimap.newMultimap());
    TreeSortedSetMultimap<Integer, Integer> expected = TreeSortedSet.newSet(undertest).groupByEach(function);
    Assert.assertEquals(expected, actual);
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Aggregations

NegativeIntervalFunction (org.eclipse.collections.impl.block.function.NegativeIntervalFunction)21 Test (org.junit.Test)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 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 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 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