Search in sources :

Example 6 with NegativeIntervalFunction

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

the class AbstractImmutableSetTestCase method groupByEach.

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

Example 7 with NegativeIntervalFunction

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

the class AbstractImmutableSortedBagTestCase method groupByEachWithTarget.

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

Example 8 with NegativeIntervalFunction

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

the class AbstractMutableSortedBagTestCase method groupByEach.

@Override
@Test
public void groupByEach() {
    super.groupByEach();
    MutableSortedBag<Integer> bag = this.newWith(Collections.reverseOrder(), 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    MutableSortedBagMultimap<Integer, Integer> expected = this.newWith(Collections.<Integer>reverseOrder()).groupByEach(function);
    for (int i = 1; i < 10; i++) {
        expected.putAll(-i, Interval.fromTo(i, 9));
    }
    expected.put(-1, 1);
    expected.put(-1, 1);
    MutableSortedBagMultimap<Integer, Integer> actual = bag.groupByEach(function);
    Assert.assertEquals(expected, actual);
    MutableSortedBagMultimap<Integer, Integer> actualWithTarget = bag.groupByEach(function, this.<Integer>newWith().groupByEach(function));
    Assert.assertEquals(expected, actualWithTarget);
    for (int i = 1; i < 10; ++i) {
        Verify.assertSortedBagsEqual(expected.get(-i), actual.get(-i));
    }
    Verify.assertSize(9, actual.keysView().toList());
    Verify.assertSize(9, actualWithTarget.keysView().toList());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 9 with NegativeIntervalFunction

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

the class ImmutableMemoryEfficientMapTestCase method groupByEach.

@Test
public void groupByEach() {
    ImmutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    for (int i = 1; i < map.size(); i++) {
        expected.putAll(-i, Interval.fromTo(i, map.size()));
    }
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    Multimap<Integer, Integer> actual = map.groupByEach(function);
    expected.forEachKey(each -> {
        Assert.assertTrue(actual.containsKey(each));
        MutableList<Integer> values = actual.get(each).toList();
        Verify.assertNotEmpty(values);
        Assert.assertTrue(expected.get(each).containsAllIterable(values));
    });
    Multimap<Integer, Integer> actualFromTarget = map.groupByEach(function, FastListMultimap.newMultimap());
    expected.forEachKey(each -> {
        Assert.assertTrue(actualFromTarget.containsKey(each));
        MutableList<Integer> values = actualFromTarget.get(each).toList();
        Verify.assertNotEmpty(values);
        Assert.assertTrue(expected.get(each).containsAllIterable(values));
    });
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 10 with NegativeIntervalFunction

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

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