Skip to content
Snippets Groups Projects
Commit 4e83a531 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

Merge remote-tracking branch 'origin/main' into main

parents bc6d69a2 8238efc3
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import mi.hdm.recipes.Recipe; ...@@ -7,6 +7,7 @@ import mi.hdm.recipes.Recipe;
* Allow the user to create a meal plan for the week. The user can check out his nutrition scores for the week. * Allow the user to create a meal plan for the week. The user can check out his nutrition scores for the week.
*/ */
public class MealPlan { public class MealPlan {
//TODO: implement class<
private static final MealPlan mealPlan = new MealPlan(); private static final MealPlan mealPlan = new MealPlan();
public static MealPlan getInstance() { public static MealPlan getInstance() {
......
package mi.hdm.shoppingList; package mi.hdm.shoppingList;
import mi.hdm.exceptions.InvalidIngredientException;
import mi.hdm.recipes.Ingredient; import mi.hdm.recipes.Ingredient;
import mi.hdm.recipes.IngredientManager;
import mi.hdm.recipes.NutritionCalculator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* Shopping list that the user can add ingredients to. The elements on the list can be marked as done or undone. * Shopping list that the user can add ingredients to. The elements on the list can be marked as done or undone.
*/ */
public class ShoppingList { public class ShoppingList {
//TODO: implement class //TODO: implement class
private static final Logger log = LogManager.getLogger(ShoppingList.class);
private final Map<Ingredient, Boolean> list; private final Map<Ingredient, Boolean> list;
private static final ShoppingList shoppingList = new ShoppingList(); private static final ShoppingList shoppingList = new ShoppingList();
...@@ -22,13 +30,32 @@ public class ShoppingList { ...@@ -22,13 +30,32 @@ public class ShoppingList {
return shoppingList; return shoppingList;
} }
public void clear() {} public void clear() {
list.clear();
log.info("ShoppingList cleared successfully.");
}
public void markDone(int id) {} public void markDone(Ingredient in) {
list.put(in, true);
log.info("Ingredient {} marked as done", in);
}
public void markDone(String name){
Ingredient in = getIngredientByName(name).orElseThrow(() -> new InvalidIngredientException("No ingredient with name " + name));;
markDone(in);
}
public void markUndone(int id) {} public void markUndone(int id) {}
public Map<Ingredient, Boolean> getList() { public Map<Ingredient, Boolean> getList() {
return list; return list;
} }
private Optional<Ingredient> getIngredientByName(String name) {
for (final Ingredient i : list.keySet()) {
if (name.equals(i.getName())) {
return Optional.of(i);
}
}
return Optional.empty();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment