Skip to content
Snippets Groups Projects
Commit 8238efc3 authored by Blersch Lara's avatar Blersch Lara
Browse files

started to implement ShoppingList

parent 9878f2cf
No related branches found
No related tags found
No related merge requests found
......@@ -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.
*/
public class MealPlan {
//TODO: implement class<
private static final MealPlan mealPlan = new MealPlan();
public static MealPlan getInstance() {
......
package mi.hdm.shoppingList;
import mi.hdm.exceptions.InvalidIngredientException;
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.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.
*/
public class ShoppingList {
//TODO: implement class
private static final Logger log = LogManager.getLogger(ShoppingList.class);
private final Map<Ingredient, Boolean> list;
private static final ShoppingList shoppingList = new ShoppingList();
......@@ -22,13 +30,32 @@ public class 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 Map<Ingredient, Boolean> getList() {
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