コード例 #1
0
  /** Constructor that takes an order. */
  public NewOrderController(Order order) {

    _currentOrder = order;
    _modifying = true;

    // Recover the quantity map.Recover the side quantity map: start with a sorted side
    // food item list.
    ArrayList<FoodItem> itemList = SideFoodItem.getDb().list();
    Collections.sort(itemList);

    // Create the map and initialize all of the values to zero.
    _quantityMap = new HashMap<SideFoodItem, Integer>();
    for (FoodItem sfi : SideFoodItem.getDb().list()) {
      _quantityMap.put((SideFoodItem) sfi, 0);
    }

    // Go through the SFIs in the given list and increment the corresponding
    // element of the map.
    ArrayList<PizzaFoodItem> pizzaFoodItems = new ArrayList<PizzaFoodItem>();
    for (FoodItem item : _currentOrder.getFoodItems()) {
      if (item instanceof SideFoodItem) {
        int value = _quantityMap.get((SideFoodItem) item);
        _quantityMap.put((SideFoodItem) item, value + 1);
      } else {
        pizzaFoodItems.add((PizzaFoodItem) item);
      }
    }

    // Now clear the order's list and add in back in all of the pizzas.
    _currentOrder.getFoodItems().clear();
    for (PizzaFoodItem item : pizzaFoodItems) {
      _currentOrder.addFoodItem(item);
    }
  }
コード例 #2
0
  /** Updates the food item list stored in the order based on the quantity map. */
  private void updateOrderFoodItemList() {

    // Filter out the list of pizzas in the order.
    ArrayList<PizzaFoodItem> pizzaList = new ArrayList<PizzaFoodItem>();
    for (FoodItem item : _currentOrder.getFoodItems()) {
      if (item instanceof PizzaFoodItem) {
        pizzaList.add((PizzaFoodItem) item);
      }
    }

    // Remove everything from the list.
    _currentOrder.getFoodItems().clear();

    // Add the pizzas.
    _currentOrder.getFoodItems().addAll(pizzaList);

    // Add the sides to the order according to the
    // quantity map.
    for (SideFoodItem side : _quantityMap.keySet()) {

      // Duplicate this side the appropriate number of times.
      for (int i = 0; i < _quantityMap.get(side); i++) {

        SideFoodItem duplicateItem =
            new SideFoodItem(
                side.getName(),
                side.getPrice(),
                side.getPrepTime(),
                side.getCookTime(),
                side.getOvenSpaceUnits());
        _currentOrder.addFoodItem(duplicateItem);
      }
    }
  }