1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.gscg.experiment;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.SortedMap;
21 import java.util.TreeMap;
22
23 import org.gscg.gameactors.GameMarket;
24
25 /***
26 * Markets contains all the markets to be used in the game.
27 * <p>
28 *
29 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
30 * Delft, the Netherlands. All rights reserved.
31 *
32 * See for project information <a href="http://www.simulation.tudelft.nl/">
33 * www.simulation.tudelft.nl </a>.
34 *
35 * The source code and binary code of this software is proprietary information
36 * of Delft University of Technology.
37 *
38 * @author <a
39 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
40 * van Houten </a>
41 * @version $Revision: 1.3 $ $Date: 2005/08/09 15:43:40 $
42 * @since 1.0.0
43 */
44 public final class Markets
45 {
46 /*** the map with markets */
47 private static SortedMap markets = Collections
48 .synchronizedSortedMap(new TreeMap());
49
50 /***
51 * constructs a new Markets
52 */
53 protected Markets()
54 {
55
56 super();
57 }
58
59 /***
60 * Method addMarket adds a market to the collection of markets to be used.
61 *
62 * @param market the market to add
63 * @return returns false if the product could not be added
64 */
65 public static boolean addMarket(final GameMarket market)
66 {
67 if (Markets.markets.containsKey(market.getName()))
68 {
69 return false;
70 }
71 Markets.markets.put(market.getName(), market);
72 return true;
73 }
74
75 /***
76 * Method getMarket returns a PCMarket
77 *
78 * @param name the name of the distributor to get
79 * @return returns null if the distributor could not be found
80 */
81 public static GameMarket getMarket(final String name)
82 {
83 return (GameMarket) Markets.markets.get(name);
84 }
85
86 /***
87 * Method getMarketsArray returns an array of the distributors.
88 *
89 * @return returns an array with distributors
90 */
91 public static GameMarket[] getMarketsArray()
92 {
93 List result = new ArrayList();
94 for (Iterator it = Markets.markets.keySet().iterator(); it.hasNext();)
95 {
96 result.add(Markets.markets.get(it.next()));
97 }
98 return (GameMarket[]) result.toArray(new GameMarket[result.size()]);
99 }
100 }