feat(commons/kcal): kcal eval infrastructure
This commit is contained in:
parent
06dde451f3
commit
8422734a3f
4 changed files with 28 additions and 1 deletions
|
|
@ -76,4 +76,15 @@ public class FormalIngredient extends RecipeIngredient implements Scalable<Forma
|
|||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), amount, unitSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double kcal() {
|
||||
final double PER_GRAMS = 100;
|
||||
return ingredient.kcalPer100g() * amountInBaseUnit() / PER_GRAMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double amount() {
|
||||
return amountInBaseUnit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,12 @@ public class Recipe {
|
|||
default -> throw new IllegalStateException("Unexpected value: " + ri);
|
||||
}).toList();
|
||||
return new Recipe(recipe.getId(), recipe.getName(), recipe.getLocale(), i, recipe.getPreparationSteps());
|
||||
|
||||
}
|
||||
public double kcal() {
|
||||
final double PER = 100; // Gram
|
||||
return
|
||||
this.ingredients.stream().mapToDouble(RecipeIngredient::kcal).sum() /
|
||||
this.ingredients.stream().mapToDouble(RecipeIngredient::amount).sum() * PER;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -92,4 +92,6 @@ public abstract class RecipeIngredient {
|
|||
public int hashCode() {
|
||||
return Objects.hash(id, ingredient);
|
||||
}
|
||||
public abstract double kcal();
|
||||
public abstract double amount();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,13 @@ public class VagueIngredient extends RecipeIngredient {
|
|||
public int hashCode() {
|
||||
return Objects.hashCode(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double kcal() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double amount() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue