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 0000000000000000000000000000000000000000..aa62e5f021d07af9d80f93ce1cbff6131c155e2c --- /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); + } +}