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.GameDistributor;
24
25 /***
26 * Distributors contains all the distributors to be used in the game.
27 *
28 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
29 * Delft, the Netherlands. All rights reserved.
30 *
31 * See for project information <a href="http://www.simulation.tudelft.nl/">
32 * www.simulation.tudelft.nl </a>.
33 *
34 * The source code and binary code of this software is proprietary information
35 * of Delft University of Technology.
36 *
37 * @author <a
38 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
39 * van Houten </a>
40 * @version $Revision: 1.3 $ $Date: 2005/08/09 15:43:40 $
41 * @since 1.0.0
42 */
43 public final class Distributors
44 {
45 /*** the map with distributors */
46 private static SortedMap distributors = Collections
47 .synchronizedSortedMap(new TreeMap());
48
49 /***
50 * constructs a new Distributors
51 */
52 protected Distributors()
53 {
54
55 super();
56 }
57
58 /***
59 * Method addDistributor adds a distributor to the collection of distributors to
60 * be used.
61 *
62 * @param distributor the distributor to add
63 * @return returns false if the product could not be added
64 */
65 public static boolean addDistributor(final GameDistributor distributor)
66 {
67 if (Distributors.distributors.containsKey(distributor.getName()))
68 {
69 return false;
70 }
71 Distributors.distributors.put(distributor.getName(), distributor);
72 return true;
73 }
74
75 /***
76 * Method getDistributor returns a GameDistributor
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 GameDistributor getDistributor(final String name)
82 {
83 return (GameDistributor) Distributors.distributors.get(name);
84 }
85
86 /***
87 * Method getDistributorsArray returns an array of the distributors.
88 *
89 * @return returns an array with distributors
90 */
91 public static GameDistributor[] getDistributorsArray()
92 {
93 List result = new ArrayList();
94 for (Iterator it = Distributors.distributors.keySet().iterator(); it
95 .hasNext();)
96 {
97 result.add(Distributors.distributors.get(it.next()));
98 }
99 return (GameDistributor[]) result.toArray(new GameDistributor[result.size()]);
100 }
101 }