Newer
Older
import mi.hdm.exceptions.InvalidIngredientException;
public class Ingredient implements RecipeComponent {
private final Measurement unit;
private final String name;
private final NutritionTable nutritionTable;
public Ingredient(Measurement unit, String name, NutritionTable nutritionTable) {
if (name == null || name.equals("")) {
throw new InvalidIngredientException("Can not add ingredient with name " + name);
}
if (nutritionTable == null) {
throw new InvalidIngredientException("Can not add ingredient without Nutrition Table");
}
this.unit = unit;
this.name = name;
this.nutritionTable = nutritionTable;
}
public String getName() {

Karsch Lukas
committed
public NutritionTable getNutritionTable() {
return nutritionTable;

Karsch Lukas
committed
public Measurement getMeasurement() {
return unit;
}
@Override
public boolean equals(Object o) {

Karsch Lukas
committed
if (o instanceof Ingredient in) {
return this.name.equals(in.getName()) && this.unit.equals(in.getMeasurement()) && this.nutritionTable.equals(in.getNutritionTable());

Karsch Lukas
committed
@Override
public String toString() {
return "Ingredient{" +
"unit=" + unit +
", name='" + name + '\'' +
", nutritionTable=" + nutritionTable +
'}';
}