View Javadoc

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