1
2
3
4
5
6
7
8
9
10
11
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.GameDistributor;
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 DistributorStatistics implements Serializable
51 {
52 /*** the prefix for the manufacturers to use */
53 public static final String PREFIX = "DISTRIBUTOR_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 DistributorStatistics distributorStatistics = null;
63
64 /***
65 * constructs a new DistributorStatistics
66 */
67 public DistributorStatistics()
68 {
69 super();
70
71 if (DistributorStatistics.distributorStatistics == null)
72 {
73 DistributorStatistics.distributorStatistics = this;
74
75 this.regions = new HashSet();
76
77
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 DistributorStatistics.PREFIX));
83 this.regions.add(usRegion);
84
85
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 DistributorStatistics.PREFIX));
91 this.regions.add(europeanRegion);
92
93
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 DistributorStatistics.PREFIX));
99 this.regions.add(asianRegion);
100 }
101 }
102
103 /***
104 * adds an distributor to gather statistics for
105 *
106 * @param distributor the manufacturer to add
107 */
108 public static void addDistributor(final GameDistributor distributor)
109 {
110 if (DistributorStatistics.distributorStatistics.regions.size() > 0)
111 {
112 boolean result = false;
113 for (Iterator it = DistributorStatistics.distributorStatistics.regions
114 .iterator(); it.hasNext();)
115 {
116 RegionInterface region = (RegionInterface) it.next();
117 boolean succes = region.addSupplyChainActor(distributor);
118 if (succes)
119 {
120 result = true;
121 }
122 }
123 if (!result)
124 {
125 Logger
126 .warning(
127 DistributorStatistics.class,
128 "addDistributor",
129 "Tried to add a distributor, but there is no region that contains the location of: "
130 + distributor.getName()
131 + " with location: "
132 + distributor.getLocation());
133 }
134 } else
135 {
136 Logger
137 .warning(DistributorStatistics.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 DistributorStatistics.distributorStatistics.regions;
148 }
149 }