Search in sources :

Example 16 with NegativeIntervalFunction

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

the class ImmutableHashBagTest method groupByEach.

@Override
@Test
public void groupByEach() {
    ImmutableBag<Integer> immutableBag = ImmutableHashBag.newBagWith(1, 2, 2, 3, 3, 3, 4, 4, 4, 4);
    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 17 with NegativeIntervalFunction

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

the class ArrayIterateTest method groupByEach.

@Test
public void groupByEach() {
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    for (int i = 1; i < 8; i++) {
        expected.putAll(-i, Interval.fromTo(i, 7));
    }
    Multimap<Integer, Integer> actual = ArrayIterate.groupByEach(new Integer[] { 1, 2, 3, 4, 5, 6, 7 }, new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
}
Also used : BigInteger(java.math.BigInteger) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 18 with NegativeIntervalFunction

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

the class MapIterableTestCase method groupByEach.

@Test
public void groupByEach() {
    MapIterable<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    for (int i = 1; i < 4; i++) {
        expected.putAll(-i, Interval.fromTo(i, 4));
    }
    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 : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 19 with NegativeIntervalFunction

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

the class AbstractMemoryEfficientMutableMapTest method groupByEach.

@Test
public void groupByEach() {
    MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
    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 20 with NegativeIntervalFunction

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

the class SynchronizedMutableCollectionTest method groupByEach.

@Override
@Test
public void groupByEach() {
    RichIterable<Integer> underTest = this.newWith(1, 2, 3, 4, 5, 6, 7);
    MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
    for (int i = 1; i < 8; i++) {
        expected.putAll(-i, Interval.fromTo(i, 7));
    }
    Multimap<Integer, Integer> actual = underTest.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = underTest.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
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