Browse Source

DRY - 81d735d

Sam Jaffe 5 years ago
parent
commit
fc53288983
1 changed files with 4 additions and 14 deletions
  1. 4 14
      src/main/lombok/org/leumasjaffe/recipe/model/Product.java

+ 4 - 14
src/main/lombok/org/leumasjaffe/recipe/model/Product.java

@@ -16,23 +16,13 @@ public class Product extends Observable.Instance implements CompoundRecipeCompon
 
 	@Override
 	public Stream<Ingredient> getIngredientsAsStream() {
-		return Collator.collateBy(cards.stream().flatMap(Card::getIngredientsAsStream),
-				Product::key, Product::mergeIngredients).stream();
+		return Collator.collateBy(cards.stream().flatMap(Card::getIngredientsAsStream)
+				.map(i -> new Ingredient(i.getName(), "", i.getAmount())),
+				Ingredient::key, Ingredient::plus).stream();
 	}
 
 	@Override
 	public Stream<? extends RecipeComponent> getComponents() {
 		return cards.stream();
-	}
-	
-	private static String key(Ingredient ingredient) {
-		return ingredient.getName() + ingredient.getAmount().getUnit();
-	}
-	
-	static Ingredient mergeIngredients(final Ingredient lhs, final Ingredient rhs) {
-		if (!lhs.getName().equals(rhs.getName())) {
-			throw new IllegalArgumentException("Combining ingredients of differing types");
-		}
-		return new Ingredient(lhs.getName(), "", lhs.getAmount().plus(rhs.getAmount()));
-	}
+	}	
 }