Selaa lähdekoodia

Make PreparationPanel always match what is shown in the steps.

Sam Jaffe 5 vuotta sitten
vanhempi
commit
3260eaafb8

+ 7 - 6
src/main/lombok/org/leumasjaffe/recipe/model/Card.java

@@ -9,9 +9,10 @@ import org.leumasjaffe.observer.Observable;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.NonNull;
 
 @Data @EqualsAndHashCode(callSuper=false)
-public class Card extends Observable.Instance implements CompoundRecipeComponent {
+public class Card extends Observable.Instance implements CompoundRecipeComponent {	
 	int id = 0; // TODO Fix this
 	int[] dependsOn = {}; // decltype(id)[]
 	String vessel = "";
@@ -24,10 +25,10 @@ public class Card extends Observable.Instance implements CompoundRecipeComponent
 	}
 	
 	public Stream<? extends RecipeComponent> getComponents() {
-		if (preparation.isPresent()) {
-			return Stream.of(preparation.get());
-		} else {
-			return cooking.stream();
-		}
+		return cooking.stream();
+	}
+	
+	public void setPreparation(final @NonNull Preparation p) {
+		preparation = Optional.of(new Preparation(p.duration, this::getIngredients));
 	}
 }

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

@@ -1,12 +1,24 @@
 package org.leumasjaffe.recipe.model;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.function.Supplier;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
-@Data
+@Data @AllArgsConstructor @NoArgsConstructor
 public class Preparation implements RecipeComponent {
-	List<Ingredient> ingredients = new ArrayList<>();
 	Duration duration;
+	@JsonIgnore Supplier<Collection<Ingredient>> producer = Collections::emptyList;
+	
+	@JsonIgnore
+	public List<Ingredient> getIngredients() {
+		return new ArrayList<>(producer.get());
+	}
 }

+ 0 - 19
src/test/resources/example.json

@@ -10,25 +10,6 @@
           "dependsOn": [],
           "vessel": "",
           "preparation": {
-            "ingredients": [
-              {
-                "name": "onion",
-                "preparation": "chopped",
-                "amount": "100 g"
-              },
-              {
-                "name": "onion",
-                "amount": "1"
-              },
-              {
-              	"name": "oil",
-              	"amount": "1 Tbsp"
-            	},
-              {
-              	"name": "oil",
-              	"amount": "1 Tbsp"
-            	}
-            ],
             "duration": {
               "displayAs": "MINUTES",
               "approximate": true,