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 /** 014 * ID for serialization. 015 */ 016 private static final long serialVersionUID = 1L; 017 018 public CCustomerStats() { 019 super("Kundenstatistik"); 020 } 021 022 /** 023 * @param id the ID of the customer whose statistics are to be got. 024 * @return the desired customer statistics. 025 */ 026 public CICustomerStats get(String id) { 027 try { 028 return (CICustomerStats)super.get(id, null, false); 029 } 030 catch (VetoException ex) { 031 return null; 032 } 033 } 034 035 /** 036 * @param id the ID of the customer whose statistics are to be removed. 037 */ 038 public void remove(String id) { 039 try { 040 super.remove(id, null); 041 } 042 catch (VetoException ex) {} 043 } 044 045 /** 046 * Updates the customer's statistics whenever he made a purchase. 047 * 048 * @param uc the customer to whose statistics the value should be added. 049 * @param v the value to be added to the statistics. 050 */ 051 public void addSales(UCustomer uc, Value v) { 052 get(uc.getName()).add(Integer.parseInt(v.toString())); 053 } 054 }