View Javadoc

1   /*
2    * @(#) ManufacturerStatistics.java May 6, 2005
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software are proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.gameactors.statistics;
14  
15  import java.awt.Point;
16  import java.io.Serializable;
17  import java.util.HashSet;
18  import java.util.Iterator;
19  import java.util.Set;
20  
21  import nl.tudelft.simulation.logger.Logger;
22  import nl.tudelft.simulation.supplychain.content.Order;
23  
24  import org.gscg.gameactors.GameManufacturer;
25  
26  /***
27   * This class keeps track of all kind of statistics for all the manufacturers
28   * present in a game.
29   * <p>
30   * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
31   * University of Technology </a>, the Netherlands. <br>
32   * See for project information <a
33   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
34   * 
35   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
36   * Delft, the Netherlands. All rights reserved.
37   * 
38   * See for project information <a href="http://www.simulation.tudelft.nl/">
39   * www.simulation.tudelft.nl </a>.
40   * 
41   * The source code and binary code of this software are proprietary information
42   * of Delft University of Technology.
43   * 
44   * @author <a
45   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
46   *         van Houten </a>
47   * @version $Revision: 1.1 $ $Date: 2005/08/03 08:52:49 $
48   * @since 1.1.3
49   */
50  public class ManufacturerStatistics implements Serializable
51  {
52  	/*** the prefix for the manufacturers to use */
53  	public static final String PREFIX = "MANUFACTURER_CONTENT_ORDER_AVERAGE_UNIT_PRICE";
54  
55  	/*** the serial version uid */
56  	private static final long serialVersionUID = 11L;
57  
58  	/*** the set with available regions */
59  	private Set regions = null;
60  
61  	/*** the manufacturer statistics instance; used for serialization */
62  	private static ManufacturerStatistics manufacturerStatistics = null;
63  
64  	/***
65  	 * constructs a new ManufacturerStatistics
66  	 */
67  	public ManufacturerStatistics()
68  	{
69  		super();
70  
71  		if (ManufacturerStatistics.manufacturerStatistics == null)
72  		{
73  			ManufacturerStatistics.manufacturerStatistics = this;
74  
75  			this.regions = new HashSet();
76  
77  			// add the north-american region
78  			RegionInterface usRegion = new Region("us region", new Point(-125,
79  					49), new Point(-68, 23));
80  			usRegion.addStatisticHandler(Order.class,
81  					new StatisticOrderAverageUnitPriceHandler(usRegion,
82  							ManufacturerStatistics.PREFIX));
83  			this.regions.add(usRegion);
84  
85  			// add the european region
86  			RegionInterface europeanRegion = new Region("european region",
87  					new Point(-11, 67), new Point(34, 33));
88  			europeanRegion.addStatisticHandler(Order.class,
89  					new StatisticOrderAverageUnitPriceHandler(europeanRegion,
90  							ManufacturerStatistics.PREFIX));
91  			this.regions.add(europeanRegion);
92  
93  			// add the asian region
94  			RegionInterface asianRegion = new Region("asian region", new Point(
95  					69, 44), new Point(147, -11));
96  			asianRegion.addStatisticHandler(Order.class,
97  					new StatisticOrderAverageUnitPriceHandler(asianRegion,
98  							ManufacturerStatistics.PREFIX));
99  			this.regions.add(asianRegion);
100 		}
101 	}
102 
103 	/***
104 	 * adds an manufacturer to gather statistics for
105 	 * 
106 	 * @param manufacturer the manufacturer to add
107 	 */
108 	public static void addManufacturer(final GameManufacturer manufacturer)
109 	{
110 		if (ManufacturerStatistics.manufacturerStatistics.regions.size() > 0)
111 		{
112 			boolean result = false;
113 			for (Iterator it = ManufacturerStatistics.manufacturerStatistics.regions
114 					.iterator(); it.hasNext();)
115 			{
116 				RegionInterface region = (RegionInterface) it.next();
117 				boolean succes = region.addSupplyChainActor(manufacturer);
118 				if (succes)
119 				{
120 					result = true;
121 				}
122 			}
123 			if (!result)
124 			{
125 				Logger
126 						.warning(
127 								ManufacturerStatistics.class,
128 								"addManufacturer",
129 								"Tried to add a manufacturer, but there is no region that contains the location of: "
130 										+ manufacturer.getName()
131 										+ " with location: "
132 										+ manufacturer.getLocation());
133 			}
134 		} else
135 		{
136 			Logger
137 					.warning(ManufacturerStatistics.class, "addManufacturer",
138 							"Tried to add a manufacturer, but there are no regions defined yet.");
139 		}
140 	}
141 
142 	/***
143 	 * @return returns the set of regions
144 	 */
145 	public static Set getRegions()
146 	{
147 		return ManufacturerStatistics.manufacturerStatistics.regions;
148 	}
149 }