fix: magic numbers

This commit is contained in:
Mei Chang van der Werff 2026-01-22 14:50:48 +01:00
commit 8238e9b462

View file

@ -15,6 +15,11 @@ public class FormalIngredient extends RecipeIngredient implements Scalable<Forma
private double amount; private double amount;
private String unitSuffix; private String unitSuffix;
private static final int tbspToPoundConvert = 32;
private static final int tbspToCupConvert = 16;
private static final int tbspToOunceConvert = 2;
private static final int OunceToPoundConvert = 16;
public double getAmount() { public double getAmount() {
return amount; return amount;
} }
@ -31,6 +36,8 @@ public class FormalIngredient extends RecipeIngredient implements Scalable<Forma
this.unitSuffix = unitSuffix; this.unitSuffix = unitSuffix;
} }
public FormalIngredient(Long id, Ingredient ingredient, double amount, String unitSuffix) { public FormalIngredient(Long id, Ingredient ingredient, double amount, String unitSuffix) {
// For testing // For testing
super(id, ingredient); super(id, ingredient);
@ -80,18 +87,18 @@ public class FormalIngredient extends RecipeIngredient implements Scalable<Forma
if(currentUnit == Unit.TABLESPOON){ if(currentUnit == Unit.TABLESPOON){
if(amount>=32){ if(amount>=tbspToPoundConvert){
return amount/32 + Unit.POUND.suffix; return amount/tbspToPoundConvert + Unit.POUND.suffix;
} }
if(amount>=16){ if(amount>=tbspToCupConvert){
return amount /16 + Unit.CUP.suffix; return amount /tbspToCupConvert + Unit.CUP.suffix;
} }
if(amount>=2){ if(amount>=tbspToOunceConvert){
return amount /2 + Unit.OUNCE.suffix; return amount /tbspToOunceConvert + Unit.OUNCE.suffix;
} }
} }
if (currentUnit == Unit.OUNCE && baseAmount >= 16) { if (currentUnit == Unit.OUNCE && baseAmount >= OunceToPoundConvert) {
return amount / 16 + Unit.POUND.suffix; return amount / OunceToPoundConvert + Unit.POUND.suffix;
} }
return amount + currentUnit.suffix; return amount + currentUnit.suffix;