Search in sources :

Example 11 with NegativeIntervalFunction

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

the class AbstractImmutableSortedSetTestCase method groupByEach.

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

Example 12 with NegativeIntervalFunction

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

the class AbstractSortedSetTestCase method groupByEach.

@Override
@Test
public void groupByEach() {
    super.groupByEach();
    MutableSortedSet<Integer> set = this.newWith(Collections.reverseOrder(), 1, 2, 3, 4, 5, 6, 7);
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    MutableSortedSetMultimap<Integer, Integer> expected = this.newWith(Collections.<Integer>reverseOrder()).groupByEach(function);
    for (int i = 1; i < 8; i++) {
        expected.putAll(-i, Interval.fromTo(i, 7));
    }
    MutableSortedSetMultimap<Integer, Integer> actual = set.groupByEach(function);
    Assert.assertEquals(expected, actual);
    MutableSortedSetMultimap<Integer, Integer> actualWithTarget = set.groupByEach(function, this.<Integer>newWith().groupByEach(function));
    Assert.assertEquals(expected, actualWithTarget);
    for (int i = 1; i < 8; ++i) {
        Verify.assertSortedSetsEqual(expected.get(-i), actual.get(-i));
        Verify.assertSortedSetsEqual(expected.get(-i), actualWithTarget.get(-i).toSortedSet(Collections.reverseOrder()));
    }
    Verify.assertSize(7, actual.keysView().toList());
    Verify.assertSize(7, actualWithTarget.keysView().toList());
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 13 with NegativeIntervalFunction

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

the class AbstractImmutableSetTestCase method groupByEachWithTarget.

@Test
public void groupByEachWithTarget() {
    ImmutableSet<Integer> undertest = this.classUnderTest();
    NegativeIntervalFunction function = new NegativeIntervalFunction();
    UnifiedSetMultimap<Integer, Integer> actual = undertest.groupByEach(function, UnifiedSetMultimap.newMultimap());
    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 14 with NegativeIntervalFunction

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

the class AbstractLazyIterableTestCase 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 = this.lazyIterable.groupByEach(new NegativeIntervalFunction());
    Assert.assertEquals(expected, actual);
    Multimap<Integer, Integer> actualWithTarget = this.lazyIterable.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
    Assert.assertEquals(expected, actualWithTarget);
}
Also used : NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Test(org.junit.Test)

Example 15 with NegativeIntervalFunction

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

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