Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.collections.candykata;

import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.sorted.SortedBag;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
Expand Down Expand Up @@ -57,15 +58,20 @@ public void commonInTop10()
Assertions.assertEquals(expectedSet, commonInTop10);
}

// @Test
// @Tag("SOLUTION")
@Test
@Tag("SOLUTION")
public void lessThan30()
{
MutableList<Bag<Candy>> bagsOfCandy = this.collectBagsOfCandy();

Bag<Candy> bigBagOfCandy = null;

String stringOfItemToCount = null;
bigBagOfCandy = bagsOfCandy.flatCollect(bag -> bag).toBag();

Bag<Candy> filteredCandies = bigBagOfCandy.selectByOccurrences(i -> i < 30);

SortedBag<Candy> sortedCandies = filteredCandies.toSortedBag();
String stringOfItemToCount = sortedCandies.toStringOfItemToCount();

var expected = "{WHOPPERS=28, TWIX=26, NERDS=28, HERSHEYS_KISSES=24, SWEDISH_FISH=26}";
Assertions.assertEquals(expected, stringOfItemToCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import java.time.LocalTime;
import java.time.Month;
import java.time.ZoneId;
import java.util.Collection;
import java.util.Random;
import java.util.stream.IntStream;

import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.sorted.SortedBag;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
Expand Down Expand Up @@ -75,9 +78,7 @@ public void lessThan30()
// Hint: use Bag#toStringOfItemToCount() and sort the items in the bag
// before converting them to a string
// Uncomment the @Test and @Solution annotations before running the test

String stringOfItemToCount = null;

var expected = "{WHOPPERS=28, TWIX=26, NERDS=28, HERSHEYS_KISSES=24, SWEDISH_FISH=26}";
Assertions.assertEquals(expected, stringOfItemToCount);
}
Expand Down