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 * ID for serialization. 019 */ 020 private static final long serialVersionUID = 3200770948911522923L; 021 022 /** 023 * Keeps track of a customer's purchases. 024 */ 025 private List<HistoryEntry> history = new LinkedList<HistoryEntry>(); 026 027 /** 028 * @param id the statistics entry's ID. It must be equal to the appropriate customer's ID. 029 */ 030 public CICustomerStats(String id) { 031 super(id); 032 } 033 034 /** 035 * Adds a purchase to the {@link #history}. 036 * @param value the value of the purchase. 037 */ 038 public void add(int value) { 039 history.add(new HistoryEntry((Calendar)SMarket.getTime().clone(), value)); 040 } 041 042 /** 043 * @return the {@link #history}. 044 */ 045 public List getHistory() { 046 return history; 047 } 048 049 public CatalogItemImpl getShallowClone() { 050 CICustomerStats cics = new CICustomerStats(getName()); 051 cics.history = this.history; 052 return cics; 053 } 054 }