private OrderItemDisplay createItemToDisplay(OrderItem item) { OrderItemDisplay itemToDisplay = new OrderItemDisplay(); itemToDisplay.setId(item.getId()); if (item instanceof PizzaOrderItem) { itemToDisplay.setItemName(((PizzaOrderItem) item).pizzaName()); itemToDisplay.setPizzeria(((PizzaOrderItem) item).pizzeriaName()); itemToDisplay.setIngredients( stringFyIngredientsList( ((PizzaOrderItem) item).getPizzeria_pizza().getPizza().getPizzaIngredients(), ((PizzaOrderItem) item).getPizzaOrderIngredients())); } else if (item instanceof BeverageOrderItem) { itemToDisplay.setItemName(((BeverageOrderItem) item).beverageName()); itemToDisplay.setPizzeria(((BeverageOrderItem) item).pizzeriaName()); } itemToDisplay.setCost(item.getCost()); itemToDisplay.setNumber(item.getNumber()); itemToDisplay.setImageItem("not found"); return itemToDisplay; }
private ArrayList<CartBooking> createBookingsToDisplay(Cart cart) { ArrayList<CartBooking> bookings = new ArrayList<>(); int numb = 0; for (OrderItem item : cart.getOrderItems()) { boolean exist = false; OrderItemDisplay itemToDisplay = createItemToDisplay(item); for (CartBooking b : bookings) { if (itemToDisplay.getPizzeria() == b.getPizzeria()) { b.getItems().add(itemToDisplay); exist = true; break; } } if (!exist) { CartBooking booking = new CartBooking(); booking.setIdentifier("pizzeria" + numb); booking.setPizzeria(itemToDisplay.getPizzeria()); booking.getItems().add(itemToDisplay); bookings.add(booking); numb++; } } return bookings; }