package org.leumasjaffe.recipe.model; import java.util.Collection; import java.util.stream.Stream; import org.leumasjaffe.recipe.util.Collator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties({"duration", "ingredients", "components", "ingredientsAsStream"}) interface CompoundRecipeComponent extends RecipeComponent { Stream getComponents(); Stream getIngredientsAsStream(); @Override default Duration getDuration() { return getComponents().map(RecipeComponent::getDuration) .reduce(Duration.ZERO, Duration::plus); } @Override default Collection getIngredients() { return Collator.collateBy(getIngredientsAsStream(), Ingredient::key, Ingredient::plus); } }