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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations