View Javadoc
1   package org.opentrafficsim.water.demand;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * Give the shipper a name.
8    * <p>
9    * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * <p>
13   * Based on software from the IDVV project, which is Copyright (c) 2013 Rijkswaterstaat - Dienst Water, Verkeer en Leefomgeving
14   * and licensed without restrictions to Delft University of Technology, including the right to sub-license sources and derived
15   * products to third parties.
16   * </p>
17   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
18   * initial version Nov 6, 2016 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class ShipperNameGenerator
22  {
23      /** counter. */
24      private static int counter = 0;
25  
26      /** names to choose from. */
27      private static List<String> names = new ArrayList<String>();
28  
29      /** specific instance of the generator. */
30      private static ShipperNameGenerator instance = null;
31  
32      /**
33       * Create a name generator.
34       * @return a new generator.
35       */
36      public static ShipperNameGenerator getInstance()
37      {
38          if (instance == null)
39          {
40              instance = new ShipperNameGenerator();
41          }
42          return instance;
43      }
44  
45      /**
46       * Add a name, e.g. from a large name file.
47       * @param name the name to add
48       */
49      public final void addShipperName(final String name)
50      {
51          names.add(name);
52      }
53  
54      /**
55       * Give a name.
56       * @return name
57       */
58      public final String getShipperName()
59      {
60          String name = "RandomName" + counter;
61          if (counter < names.size())
62          {
63              name = names.get(counter);
64          }
65  
66          counter++;
67          return name;
68      }
69  }