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