CompoundRecipeComponent.java 768 B

12345678910111213141516171819202122232425
  1. package org.leumasjaffe.recipe.model;
  2. import java.util.Collection;
  3. import java.util.stream.Stream;
  4. import org.leumasjaffe.recipe.util.Collator;
  5. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  6. @JsonIgnoreProperties({"duration", "ingredients", "components", "ingredientsAsStream"})
  7. interface CompoundRecipeComponent extends RecipeComponent {
  8. Stream<? extends RecipeComponent> getComponents();
  9. Stream<Ingredient> getIngredientsAsStream();
  10. @Override
  11. default Duration getDuration() {
  12. return getComponents().map(RecipeComponent::getDuration)
  13. .reduce(Duration.ZERO, Duration::plus);
  14. }
  15. @Override
  16. default Collection<Ingredient> getIngredients() {
  17. return Collator.collateBy(getIngredientsAsStream(), Ingredient::key, Ingredient::plus);
  18. }
  19. }