| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package org.leumasjaffe.recipe.model;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- import java.util.stream.Stream;
- import org.leumasjaffe.observer.Observable;
- import lombok.Data;
- import lombok.EqualsAndHashCode;
- import lombok.NonNull;
- @Data @EqualsAndHashCode(callSuper=false)
- public class Phase extends Observable.Instance implements CompoundRecipeComponent {
- int id = 0; // TODO Fix this
- int[] dependsOn = {}; // decltype(id)[]
- String vessel = "";
- Preparation preparation = new Preparation();
- List<Step> cooking = new ArrayList<>();
- Optional<Rest> rest = Optional.empty();
-
- public Stream<Ingredient> getIngredientsAsStream() {
- return cooking.stream().flatMap(RecipeComponent::getIngredientsAsStream);
- }
-
- // TODO Include Rest and Preparation
- public Stream<? extends RecipeComponent> getComponents() {
- return cooking.stream();
- }
-
- public CollatedDuration getCollatedDuration() {
- final Duration prep = preparation.getIngredients().isEmpty() ?
- Duration.ZERO : preparation.getDuration();
- final Duration rest = this.rest.map(Rest::getDuration).orElse(Duration.ZERO);
- final Duration cooking = this.cooking.stream().map(Step::getDuration)
- .reduce(Duration.ZERO, Duration::plus);
- return new CollatedDuration(prep, cooking, prep.plus(cooking).plus(rest));
- }
-
- public void setPreparation(final @NonNull Preparation p) {
- preparation = new Preparation(p.duration, this::getIngredients);
- }
- }
|