001 package market.statistics;
002
003 import market.UCustomer;
004 import data.Value;
005 import data.events.VetoException;
006 import data.ooimpl.CatalogImpl;
007
008 /**
009 * Catalog that contains the statistics of the market's customers.
010 */
011 public class CCustomerStats extends CatalogImpl {
012
013 public CCustomerStats() {
014 super("Kundenstatistik");
015 }
016
017 /**
018 * @param id the ID of the customer whose statistics are to be got.
019 * @return the desired customer statistics.
020 */
021 public CICustomerStats get(String id) {
022 try {
023 return (CICustomerStats)super.get(id, null, false);
024 }
025 catch (VetoException ex) {
026 return null;
027 }
028 }
029
030 /**
031 * @param id the ID of the customer whose statistics are to be removed.
032 */
033 public void remove(String id) {
034 try {
035 super.remove(id, null);
036 }
037 catch (VetoException ex) {}
038 }
039
040 /**
041 * Updates the customer's statistics whenever he made a purchase.
042 *
043 * @param uc the customer to whose statistics the value should be added.
044 * @param v the value to be added to the statistics.
045 */
046 public void addSales(UCustomer uc, Value v) {
047 get(uc.getName()).add(Integer.parseInt(v.toString()));
048 }
049 }