Bladeren bron

Restore Product, since it seems like a useful concept (e.g. Sauce + Meat, etc.)

Sam Jaffe 5 jaren geleden
bovenliggende
commit
518dd41cac

+ 26 - 0
src/main/lombok/org/leumasjaffe/recipe/model/Product.java

@@ -0,0 +1,26 @@
+package org.leumasjaffe.recipe.model;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import lombok.Data;
+
+@Data
+public class Product {
+	String name;
+	List<Card> cards;
+	
+	@JsonIgnore
+	Collection<Ingredient> getIngredients() {
+		return getIngredientsAsStream().collect(Collectors.toList());
+	}
+	
+	@JsonIgnore
+	Stream<Ingredient> getIngredientsAsStream() {
+		return cards.stream().flatMap(Card::getIngredientsAsStream);
+	}
+}

+ 2 - 2
src/main/lombok/org/leumasjaffe/recipe/model/Recipe.java

@@ -19,10 +19,10 @@ public class Recipe {
 	Object nutrition;
 	int servings;
 	Optional<ImageIcon> photo; // TODO JSONIZATION	
-	List<Card> cards = new ArrayList<>();
+	List<Product> products = new ArrayList<>();
 	
 	@JsonIgnore
 	Collection<Ingredient> getIngredients() {
-		return cards.stream().flatMap(Card::getIngredientsAsStream).collect(Collectors.toList());
+		return products.stream().flatMap(Product::getIngredientsAsStream).collect(Collectors.toList());
 	}
 }