Hello I'm trying to sort a list in the following order
Breakfast -> Lunch -> Dinner -> Dessert->Breakfast -> Lunch -> Dinner -> Dessert getAllMealPlans([Cake (dessert), Vegetable Soup (lunch), Waffles (breakfast), Potato Gratin (dinner)], 4)
returns a set containing four plans:
* - [ Waffles (breakfast), Vegetable Soup (lunch), Potato Gratin (dinner), Cake (dessert)] * - [Vegetable Soup (lunch), Potato Gratin (dinner), Cake (dessert), Waffles (breakfast)] * - [Potato Gratin (dinner), Cake (dessert), Waffles (breakfast), Vegetable Soup (lunch)] * - [Cake (dessert), Waffles (breakfast), Vegetable Soup (lunch), Potato Gratin (dinner)] This is what the enum and the Food type looks like
public enum Meal { BREAKFAST, LUNCH, DINNER, DESSERT } public static class Food { String dish; public Meal meal; public Food(String dish, Meal meal) { this.dish = dish; this.meal = meal; } This is what I have I can't quite get the sorting to work. Any ideas on how I can approach this?
public static Set<List<Food>> getAllMealPlans(Set<Food> foods, int numMeals) { Set<List<Food>> set = new HashSet<>(); List<Food> aList = new ArrayList<Food>(foods); List<String> sortedList = aList.stream().map(Meal::valueOf).sorted(Meal::compareTo).map(Meal::toString).collect(Collectors.toList()); System.out.println(sortedList); return set; }
Foods into groups of 4, each group contains at most one breakfast, one lunch, one dinner, and one dessert, and joins all the groups together to form a list?