@Getter public class Dish { BigDecimal price; }Necesito calcular el precio total de todos los platos pedidos , pero no puedo escribir el método de reducción. Esta es una firma de método (el argumento tiene un mapa de Dish y cuántas veces se ordenó).
Así que debe ser algo así como la sum of every dish.getPrice * dishQuantaty
private BigDecimal getOrderTotalPrice(Map<Dish, Integer> dishQuantityMap) { }El código de error sobre el que me preguntaron
return dishQuantityMap.entrySet().stream() .reduce(BigDecimal.ZERO, (dishIntegerEntry) -> dishIntegerEntry.getKey().getPrice() .multiply(BigDecimal.valueOf(dishIntegerEntry.getValue())));¿Quiso decir algo como esto?
private BigDecimal getOrderTotalPrice(Map<Dish, Integer> dishQuantityMap) { return dishQuantityMap.entrySet().stream() .map(d -> d.getKey().getPrice().multiply(new BigDecimal(d.getValue()))) .reduce(BigDecimal.ZERO, BigDecimal::add); }