View Javadoc

1   /*
2    * @(#) Products.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.product.Product;
24  
25  /***
26   * Products contains all the products 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.1 $ $Date: 2005/06/16 12:34:00 $
42   * @since 1.0.0
43   */
44  public final class Products
45  {
46  	/*** the map with products */
47  	private static SortedMap products = Collections
48  			.synchronizedSortedMap(new TreeMap());
49  
50  	/***
51  	 * constructs a new Products
52  	 */
53  	protected Products()
54  	{
55  		// utility class
56  		super();
57  	}
58  
59  	/***
60  	 * Method addProduct adds a product to the collection of produdcts to be
61  	 * used.
62  	 * 
63  	 * @param product the product to add
64  	 * @return returns false if the product could not be added
65  	 */
66  	public static boolean addProduct(final Product product)
67  	{
68  		if (Products.products.containsKey(product.getName()))
69  		{
70  			return false;
71  		}
72  		Products.products.put(product.getName(), product);
73  		return true;
74  	}
75  
76  	/***
77  	 * Method getProduct returns a product based on its name
78  	 * 
79  	 * @param name the name of the product to get
80  	 * @return returns null if the product could not be found
81  	 */
82  	public static Product getProduct(final String name)
83  	{
84  		return (Product) Products.products.get(name);
85  	}
86  
87  	/***
88  	 * Method getProductsArray returns an array of the products.
89  	 * 
90  	 * @return returns an array with products
91  	 */
92  	public static Product[] getProductsArray()
93  	{
94  		List result = new ArrayList();
95  		for (Iterator it = Products.products.keySet().iterator(); it.hasNext();)
96  		{
97  			result.add(Products.products.get(it.next()));
98  		}
99  		return (Product[]) result.toArray(new Product[result.size()]);
100 	}
101 }