From d88a2e72c53eec52e3ca1e45a180c36c2a05d1ba Mon Sep 17 00:00:00 2001 From: HSoreide <sofie.scisly@gmail.com> Date: Mon, 13 Mar 2023 12:51:10 +0100 Subject: [PATCH] Write first draft of the class IngredientsAtHand --- .../demo/data/recipes/IngredientsAtHand.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/no/ntnu/idatt1002/demo/data/recipes/IngredientsAtHand.java diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/IngredientsAtHand.java b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/IngredientsAtHand.java new file mode 100644 index 00000000..aa62e5f0 --- /dev/null +++ b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/IngredientsAtHand.java @@ -0,0 +1,31 @@ +package no.ntnu.idatt1002.demo.data.recipes; + +import java.util.List; + +public class IngredientsAtHand { + + private List<Ingredient> ingredientsAtHand; + + public List<Ingredient> getIngredientsAtHand() { + return ingredientsAtHand; + } + + public void setIngredientsAtHand(List<Ingredient> ingredientsAtHand) { + this.ingredientsAtHand = ingredientsAtHand; + } + + public void addIngredient(Ingredient ingredient) { + this.ingredientsAtHand.add(ingredient); + } + + /** + * Returns null if no ingredient of the requested type is found in the collection. + * @param ingredientType + * @return + */ + public Ingredient getIngredient(FoodItem ingredientType) { + return this.getIngredientsAtHand().stream() + .filter((ingredient) -> ingredient.getFoodType() == ingredientType) + .findFirst().orElse(null); + } +} -- GitLab