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

logging added in several classes

parent 2658e5d7
No related branches found
No related tags found
No related merge requests found
......@@ -40,12 +40,16 @@ public class CategoryManager {
}
public boolean deleteCategory(Category c) {
log.info("Category {} deleted successfully.");
return allCategories.remove(c);
}
public boolean deleteCategory(String name) {
Category c = getCategoryByName(name).orElseThrow(() -> new NullPointerException("Category not found."));
log.info("Category {} deleted successfully.");
return allCategories.remove(c);
}
public List<Category> getAllCategories(){
......@@ -54,6 +58,7 @@ public class CategoryManager {
public void clearCategories() {
allCategories.clear();
log.info("List allCategories cleared successfully.");
}
private Optional<Category> getCategoryByName(String name) {
......
......@@ -29,8 +29,9 @@ public class IngredientManager {
*/
public boolean addIngredient(Ingredient in) {
if (allIngredients.contains(in)) {
log.error("Ingredient: {} not added because it already exists", in.getName());
log.error("Ingredient {} not added because it already exists.", in.getName());
return false;
//TODO: Exception or false?
} else {
log.info("Ingredient {} added successfully.", in.getName());
allIngredients.add(in);
......@@ -44,6 +45,7 @@ public class IngredientManager {
}
public Ingredient deleteIngredient(int i) {
log.info("Ingredient {} deleted successfully.");
return allIngredients.remove(i);
}
......@@ -53,10 +55,12 @@ public class IngredientManager {
return ingredient.isPresent() && allIngredients.remove(ingredient);*/
Ingredient ingredient = getIngredientByName(name).orElseThrow(() -> new InvalidIngredientException("No ingredient with name " + name));
log.info("Ingredient {} deleted successfully.");
return allIngredients.remove(ingredient);
}
public void clearIngredients() {
log.info("List allIngredients cleared successfully.");
allIngredients.clear();
}
......
......@@ -3,8 +3,12 @@ package mi.hdm.recipes;
import mi.hdm.mealPlan.MealPlan;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class NutritionCalculator {
private static final Logger log = LogManager.getLogger(NutritionCalculator.class);
/**
* Method to calculate the nutrition table for a recipe out of its ingredients.
*
......@@ -12,6 +16,7 @@ public class NutritionCalculator {
*/
public static NutritionTable calculateNutritionTable(Map<RecipeComponent, Integer> ingredients) {
if (ingredients == null || ingredients.isEmpty()) {
log.info("Map ingredients is null or empty. Therefore new nutritionTable() was generated.");
return NutritionTable.empty();
}
......@@ -32,7 +37,7 @@ public class NutritionCalculator {
totalFibers += nutritionTable.get(Nutrition.FIBERS) * ingredients.get(entry) / 100;
totalSalt += nutritionTable.get(Nutrition.SALT) * ingredients.get(entry) / 100;
}
log.info("NutritionTable calculated successfully.");
return new NutritionTable(totalCals, totalCarbs, totalFats, totalProteins, totalFibers, totalSalt);
}
......
package mi.hdm.recipes;
import mi.hdm.exceptions.InvalidRecipeException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.time.LocalDateTime;
import java.util.ArrayList;
......@@ -8,6 +10,7 @@ import java.util.List;
import java.util.Map;
public class Recipe implements RecipeComponent {
private static final Logger log = LogManager.getLogger(Recipe.class);
private final Map<RecipeComponent, Integer> ingredients;
private String name;
private String description;
......@@ -85,6 +88,7 @@ public class Recipe implements RecipeComponent {
throw new InvalidRecipeException("Cannot set name to " + name);
}
this.name = name;
log.info("Name set successfully.");
}
public String getName() {
......@@ -97,6 +101,7 @@ public class Recipe implements RecipeComponent {
public void setDescription(String description) {
this.description = description;
log.info("Description set successfully.");
}
public List<String> getPreparation() {
......@@ -105,6 +110,7 @@ public class Recipe implements RecipeComponent {
public void setPreparation(List<String> preparation) {
this.preparation = preparation;
log.info("Preparation set successfully.");
}
public List<Category> getCategories() {
......@@ -117,10 +123,12 @@ public class Recipe implements RecipeComponent {
}
this.categories = categories;
log.info("Categories set successfully.");
}
public void addCategory(Category category) {
categories.add(category);
log.info("Category {} added successfully.");
}
public int getPreparationTimeMins() {
......@@ -132,6 +140,7 @@ public class Recipe implements RecipeComponent {
throw new InvalidRecipeException("PreparationTime must be a positive value");
}
this.preparationTimeMins = preparationTimeMins;
log.info("PreparationTimeMins set successfully.");
}
public LocalDateTime getCreationTime() {
......@@ -143,6 +152,7 @@ public class Recipe implements RecipeComponent {
throw new InvalidRecipeException("Nutrition Table does not exist");
}
this.nutritionTable = nutritionTable;
log.info("NutritionTable set successfully.");
}
public NutritionTable getNutritionTable() {
......
......@@ -22,19 +22,25 @@ public class RecipeManager {
}
public void addRecipe(Recipe recipe){
if (getRecipeByName(recipe.getName()).isEmpty()) {
recipes.add(recipe);
log.info("Recipe {} added successfully.");
} else {
log.error("Recipe {} not added because it already exists.");
throw new InvalidRecipeException("Recipe name already exists");
}
//TODO: Exception or false?
}
public Recipe deleteRecipe(int i) {
log.info("Recipe {} deleted successfully.");
return recipes.remove(i);
}
public boolean deleteRecipe(String name) {
Recipe r = getRecipeByName(name).orElseThrow();
log.info("Recipe {} deleted successfully.");
return recipes.remove(r);
}
......
......@@ -3,6 +3,7 @@ package mi.hdm.recipes;
import java.util.List;
public class RecipeSearch {
//TODO: implement class
List<Recipe> recipesToSearch;
public RecipeSearch (List<Recipe> recipesToSearch) {}
......
......@@ -9,6 +9,7 @@ import java.util.Map;
* 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 final Map<Ingredient, Boolean> list;
private static final ShoppingList shoppingList = new ShoppingList();
......
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