001 package market.statistics; 002 003 import java.util.Calendar; 004 import java.util.LinkedList; 005 import java.util.List; 006 007 import market.SMarket; 008 import data.ooimpl.CatalogItemImpl; 009 010 /** 011 * Every customer has a dedicated statistics item, which is represented by this class.<br> 012 * The statistics are saved as a list that contains date and value of every purchase the customer has 013 * made. That makes it possible to get filtered statistics for a special range of time. 014 */ 015 public class CICustomerStats extends CatalogItemImpl { 016 017 /** 018 * Keeps track of a customer's purchases. 019 */ 020 private List history = new LinkedList(); 021 022 /** 023 * @param id the statistics entry's ID. It must be equal to the appropriate customer's ID. 024 */ 025 public CICustomerStats(String id) { 026 super(id); 027 } 028 029 /** 030 * Adds a purchase to the {@link #history}. 031 * @param value the value of the purchase. 032 */ 033 public void add(int value) { 034 history.add(new HistoryEntry((Calendar)SMarket.getTime().clone(), value)); 035 } 036 037 /** 038 * @return the {@link #history}. 039 */ 040 public List getHistory() { 041 return history; 042 } 043 044 public CatalogItemImpl getShallowClone() { 045 CICustomerStats cics = new CICustomerStats(getName()); 046 cics.history = this.history; 047 return cics; 048 } 049 }