diff --git a/commons/src/main/java/commons/FormalIngredient.java b/commons/src/main/java/commons/FormalIngredient.java index 231abd3..05ed839 100644 --- a/commons/src/main/java/commons/FormalIngredient.java +++ b/commons/src/main/java/commons/FormalIngredient.java @@ -10,7 +10,7 @@ import java.util.Optional; * @see RecipeIngredient */ @Entity -public class FormalIngredient extends RecipeIngredient { +public class FormalIngredient extends RecipeIngredient implements Scalable { private double amount; private String unitSuffix; @@ -50,4 +50,14 @@ public class FormalIngredient extends RecipeIngredient { public String toString() { return amount + unitSuffix + " of " + ingredient.name; } + + @Override + public FormalIngredient scaleBy(int numPortions) { + return new FormalIngredient(getIngredient(), amount * numPortions, unitSuffix); + } + + @Override + public FormalIngredient scaleBy(double factor) { + return new FormalIngredient(getIngredient(), amount, unitSuffix); + } } diff --git a/commons/src/main/java/commons/RecipeIngredient.java b/commons/src/main/java/commons/RecipeIngredient.java index 8569334..3dbc129 100644 --- a/commons/src/main/java/commons/RecipeIngredient.java +++ b/commons/src/main/java/commons/RecipeIngredient.java @@ -57,4 +57,20 @@ public abstract class RecipeIngredient { //store it in the field this.ingredient = ingredient; } + + public void setId(Long id) { + this.id = id; + } + + public void setIngredient(Ingredient ingredient) { + this.ingredient = ingredient; + } + + public Long getId() { + return id; + } + + public Ingredient getIngredient() { + return ingredient; + } } diff --git a/commons/src/main/java/commons/Scalable.java b/commons/src/main/java/commons/Scalable.java new file mode 100644 index 0000000..7cb8a14 --- /dev/null +++ b/commons/src/main/java/commons/Scalable.java @@ -0,0 +1,6 @@ +package commons; + +public interface Scalable { + IngredientType scaleBy(int numPortions); + IngredientType scaleBy(double factor); +} diff --git a/commons/src/main/java/commons/Unit.java b/commons/src/main/java/commons/Unit.java index 89146f6..407dcf4 100644 --- a/commons/src/main/java/commons/Unit.java +++ b/commons/src/main/java/commons/Unit.java @@ -16,6 +16,21 @@ public enum Unit { KILOGRAMME("kg", true, 1_000.0 ), TONNE("t", true, 1_000_000.0), + // TODO Consider more fine-tuned volume unit definitions + // TODO Use density-based calculations? + /* + Volume units are used with the assumption that 1L of ingredient = 1kg. + */ + LITRE("l", true, 1_000.0), + MILLILITRE("ml", true, 1.0), + + // We love our American friends!! + // Source: + // https://whatscookingamerica.net/equiv.htm + TABLESPOON("tbsp", true, 14.0), + OUNCE("oz", true, 28.35), + POUND("lb", true, 453.6), + CUP("cup", true, 225), // A special informal unit INFORMAL("", false, 0.0);