示例#1
0
 private ShoppingCartItem findItem(String itemId) {
   ShoppingCartItem item = null;
   int size = getSize();
   for (int i = 0; i < size; i++) {
     ShoppingCartItem cartItem = (ShoppingCartItem) items.get(i);
     if (itemId.equals(Integer.toString(cartItem.getItemId()))) {
       item = cartItem;
       break;
     }
   }
   return item;
 }
示例#2
0
  public void addItem(ShoppingCartItem newItem) {

    // Check to see if this item is already present, if so, inc the qty
    int size = getSize();
    ShoppingCartItem cartItem = findItem(Integer.toString(newItem.getItemId()));
    if (cartItem != null) {
      cartItem.setQuantity(cartItem.getQuantity() + newItem.getQuantity());
    } else {

      // Must have been a different item, so add it to the cart
      items.add(newItem);
    }
  }