Explorar el Código

Fix NPE w/ Ingredient handling.

Sam Jaffe hace 5 años
padre
commit
6fc4579b65

+ 4 - 0
src/main/lombok/org/leumasjaffe/recipe/model/Ingredient.java

@@ -13,6 +13,10 @@ public class Ingredient extends Observable.Instance {
 	String preparation = "";
 	Amount amount;
 	
+	boolean hasPreparation() {
+		return preparation != null && !preparation.isEmpty();
+	}
+	
 	Ingredient plus(final Ingredient rhs) {
 		if (!name.equals(rhs.name)) {
 			throw new IllegalArgumentException("Combining ingredients of differing types");

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

@@ -19,7 +19,7 @@ public class Preparation implements RecipeComponent {
 	
 	@JsonIgnore
 	public List<Ingredient> getIngredients() {
-		return producer.get().stream().filter(i -> !i.getPreparation().isEmpty())
+		return producer.get().stream().filter(Ingredient::hasPreparation)
 				.collect(Collectors.toList());
 	}
 }