View Javadoc

1   /*
2    * @(#) Suppliers.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.Supplier;
24  
25  import org.gscg.gameactors.GameSupplier;
26  
27  /***
28   * Suppliers contains all the suppliers 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.1 $ $Date: 2005/08/09 15:43:40 $
44   * @since 1.0.0
45   */
46  public final class Suppliers
47  {
48  	/*** the map with suppliers */
49  	private static SortedMap suppliers = Collections
50  			.synchronizedSortedMap(new TreeMap());
51  
52  	/***
53  	 * constructs a new Suppliers
54  	 */
55  	protected Suppliers()
56  	{
57  		// utility class
58  		super();
59  	}
60  
61  	/***
62  	 * Method addSupplier adds a supplier to the collection of suppliers to be
63  	 * used.
64  	 * 
65  	 * @param supplier the supplier to add
66  	 * @return returns false if the product could not be added
67  	 */
68  	public static boolean addSupplier(final Supplier supplier)
69  	{
70  		if (Suppliers.suppliers.containsKey(supplier.getName()))
71  		{
72  			return false;
73  		}
74  		Suppliers.suppliers.put(supplier.getName(), supplier);
75  		return true;
76  	}
77  
78  	/***
79  	 * Method getSupplier returns a GameSupplier
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 GameSupplier getSupplier(final String name)
85  	{
86  		return (GameSupplier) Suppliers.suppliers.get(name);
87  	}
88  
89  	/***
90  	 * Method getSuppliersArray returns an array of the suppliers.
91  	 * 
92  	 * @return returns an array with suppliers
93  	 */
94  	public static GameSupplier[] getSuppliersArray()
95  	{
96  		List result = new ArrayList();
97  		for (Iterator it = Suppliers.suppliers.keySet().iterator(); it
98  				.hasNext();)
99  		{
100 			result.add(Suppliers.suppliers.get(it.next()));
101 		}
102 		return (GameSupplier[]) result.toArray(new GameSupplier[result.size()]);
103 	}
104 }