diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java new file mode 100644 index 0000000000000000000000000000000000000000..8023b0c1fad25ac3e318e8482e0ac6c1e96d7ee6 --- /dev/null +++ b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java @@ -0,0 +1,60 @@ +package no.ntnu.idatt1002.demo.data.recipes; + +public class Ingredient { + + private FoodItem foodType; + private double amount; + private MeasuringUnit unit; + + public Ingredient(FoodItem ingredient, double amount, MeasuringUnit unit) { + if(ingredient == null | amount < 0.0f | unit == null) { + throw new IllegalArgumentException("The ingredient must have a type, amount and measuring unit."); + } + this.foodType = ingredient; + this.amount = amount; + this.unit = unit; + } + + public FoodItem getFoodType() { + return foodType; + } + + public void setFoodType(FoodItem foodType) { + if(foodType == null) { + throw new IllegalArgumentException("The food type must be set to a valid value of FoodItem."); + } + this.foodType = foodType; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + if(amount < 0.0f) { + throw new IllegalArgumentException("The amount of an ingredient cannot be zero or negative."); + } + this.amount = amount; + } + + public MeasuringUnit getUnit() { + return unit; + } + + public void setUnit(MeasuringUnit unit) { + if(unit == null) { + throw new IllegalArgumentException("The food's measuring unit must be set to a valid value of MeasuringUnit."); + } + this.unit = unit; + } + + @Override + public String toString() { + return "Ingredient{" + + "foodType=" + foodType.label + + ", amount=" + amount + + ", unit=" + unit.label + + '}'; + } + +}