Пример #1
0
 // reorders a product if below reorder level and not discontinued
 public void reorderProduct(Product product, int productStockLevel) {
   if (productStockLevel < product.getReorderLevel() && !product.isDiscontinued()) {
     new ProductOrder(product);
   } else if (productStockLevel == 0 && product.isDiscontinued()) {
     ProductCatalogue.getCatalogue().removeProduct(product);
   }
   // else do nothing and let stock run down as the product is discontinued but still available.
 }
Пример #2
0
/**
 * The complete shop as a singleton
 *
 * <p>NOTE: Uses Java 1.7
 *
 * @author hajo
 */
public enum JPAShop {
  INSTANCE;
  private final IProductCatalogue productCatalogue = ProductCatalogue.newInstance("shop_pu");
  private final ICustomerRegistry customerRegistry = CustomerRegistry.newInstance("shop_pu");
  private final IOrderBook orderBook = OrderBook.newInstance("shop_pu");

  private JPAShop() {
    Logger.getAnonymousLogger().log(Level.INFO, "Shop alive {0}", this.hashCode());
  }

  public ICustomerRegistry getCustomerRegistry() {
    return customerRegistry;
  }

  public IOrderBook getOrderBook() {
    return orderBook;
  }

  public IProductCatalogue getProductCatalogue() {
    return productCatalogue;
  }
}