private List<CartItem> addCount(String str, List<CartItem> cartitemList) throws IOException { String[] fields = str.split("-"); String barcode = fields[0]; double count = this.getCount(fields); Product product = this.getProduct(barcode); int index = this.getIndex(barcode, cartitemList); if (index == -1) { CartItem cartitem = new CartItem(product, count); cartitemList.add(cartitem); } else { CartItem cartitem = cartitemList.get(index); cartitem.setCount(cartitem.getCount() + 1); cartitemList.set(index, cartitem); } return cartitemList; }