View Javadoc
1   package org.opentrafficsim.core.distributions;
2   
3   /**
4    * Generator implementation for a constant value.
5    * <p>
6    * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
8    * <p>
9    * @version $Revision$, $LastChangedDate$, by $Author$, initial version 9 dec. 2017 <br>
10   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
11   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
12   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
13   * @param <O> type of the object returned by the draw method
14   */
15  public class ConstantGenerator<O> implements Generator<O>
16  {
17  
18      /** Value. */
19      private final O value;
20  
21      /**
22       * Constructor.
23       * @param value O; value
24       */
25      public ConstantGenerator(final O value)
26      {
27          this.value = value;
28      }
29  
30      /** {@inheritDoc} */
31      @Override
32      public O draw()
33      {
34          return this.value;
35      }
36  
37      /**
38       * Returns the value.
39       * @return O; value
40       */
41      public O getValue()
42      {
43          return this.value;
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public String toString()
49      {
50          return "ConstantGenerator [value=" + this.value + "]";
51      }
52  
53  }