|
|
@@ -1,18 +1,14 @@
|
|
|
package org.leumasjaffe.recipe.model;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
-import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
-import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
-
|
|
|
import lombok.Data;
|
|
|
|
|
|
@Data
|
|
|
-public class Card {
|
|
|
+public class Card implements CompoundRecipeComponent {
|
|
|
int id = 0; // TODO Fix this
|
|
|
int[] dependsOn = {}; // decltype(id)[]
|
|
|
String vessel = "";
|
|
|
@@ -20,14 +16,15 @@ public class Card {
|
|
|
List<Step> cooking = new ArrayList<>();
|
|
|
Optional<Rest> rest = Optional.empty();
|
|
|
|
|
|
- @JsonIgnore
|
|
|
- Collection<Ingredient> getIngredients() {
|
|
|
- return getIngredientsAsStream().collect(Collectors.toList());
|
|
|
+ public Stream<Ingredient> getIngredientsAsStream() {
|
|
|
+ return getComponents().flatMap(RecipeComponent::getIngredientsAsStream);
|
|
|
}
|
|
|
|
|
|
- @JsonIgnore
|
|
|
- Stream<Ingredient> getIngredientsAsStream() {
|
|
|
- return preparation.map(p -> p.getIngredients().stream())
|
|
|
- .orElse(cooking.stream().flatMap(s -> s.getIngredients().stream()));
|
|
|
+ public Stream<? extends RecipeComponent> getComponents() {
|
|
|
+ if (preparation.isPresent()) {
|
|
|
+ return Stream.of(preparation.get());
|
|
|
+ } else {
|
|
|
+ return cooking.stream();
|
|
|
+ }
|
|
|
}
|
|
|
}
|