| 12345678910111213141516171819202122232425 |
- 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<? extends RecipeComponent> getComponents();
- Stream<Ingredient> getIngredientsAsStream();
-
- @Override
- default Duration getDuration() {
- return getComponents().map(RecipeComponent::getDuration)
- .reduce(Duration.ZERO, Duration::plus);
- }
-
- @Override
- default Collection<Ingredient> getIngredients() {
- return Collator.collateBy(getIngredientsAsStream(), Ingredient::key, Ingredient::plus);
- }
- }
|