コード例 #1
0
  /** Add new StockItem to table. */
  public void addItem(final SoldItem soldItem) throws SalesSystemException {

    StockItem stockItem = soldItem.getStockItem();
    long stockItemId = stockItem.getId();
    SoldItem existingItem = getForStockItem(stockItemId);

    if (existingItem != null) {
      int totalQuantity = existingItem.getQuantity() + soldItem.getQuantity();
      validateQuantityInStock(stockItem, totalQuantity);
      existingItem.setQuantity(totalQuantity);

      log.debug(
          "Found existing item "
              + soldItem.getName()
              + " increased quantity by "
              + soldItem.getQuantity());

    } else {
      validateQuantityInStock(soldItem.getStockItem(), soldItem.getQuantity());
      getRows().add(soldItem);
      log.debug("Added " + soldItem.getName() + " quantity of " + soldItem.getQuantity());
    }

    fireTableDataChanged();
  }
コード例 #2
0
 @Override
 protected Object getColumnValue(SoldItem item, int columnIndex) {
   switch (columnIndex) {
     case 0:
       return item.getId();
     case 1:
       return item.getName();
     case 2:
       return item.getPrice();
     case 3:
       return item.getQuantity();
     case 4:
       return item.getSum();
   }
   throw new IllegalArgumentException("Column index out of range");
 }
コード例 #3
0
  @Override
  public String toString() {
    final StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < headers.length; i++) buffer.append(headers[i] + "\t");
    buffer.append("\n");

    for (final SoldItem item : getRows()) {
      buffer.append(item.getId() + "\t");
      buffer.append(item.getName() + "\t");
      buffer.append(item.getPrice() + "\t");
      buffer.append(item.getQuantity() + "\t");
      buffer.append(item.getSum() + "\t");
      buffer.append("\n");
    }

    return buffer.toString();
  }