1 33 34 package com.icesoft.icefaces.samples.showcase.components.dragDrop; 35 36 import java.text.NumberFormat ; 37 import java.util.Hashtable ; 38 39 46 public class StoreTable extends Hashtable { 47 private static final int DEFAULT_SIZE = 4; 49 50 public static final NumberFormat CURRENCY_FORMAT = 52 NumberFormat.getCurrencyInstance(); 53 54 private int id = 0; 56 private String skuBase = "#skuITEM"; 57 58 61 public StoreTable() { 62 super(DEFAULT_SIZE); 63 } 64 65 70 public StoreTable(int initialCapacity) { 71 super(initialCapacity); 72 } 73 74 81 public String addItem(CartItem toAdd) { 82 toAdd.setKey(getNextKey()); 83 put(toAdd.getKey(), toAdd); 84 85 return (toAdd.getKey()); 86 } 87 88 95 public boolean purchaseItem(CartItem item) { 96 if (item.getQuantity() >= 1) { 98 item.decreaseQuantity(); 99 return (true); 100 } 101 102 return (false); 103 } 104 105 112 public void returnItem(CartItem item) { 113 item.increaseQuantity(); 114 } 115 116 122 public CartItem getItem(String key) { 123 return ((CartItem) get(key)); 124 } 125 126 132 private String getNextKey() { 133 id++; 134 return (skuBase + id); 135 } 136 } | Popular Tags |