ConstantGenerator.java

  1. package org.opentrafficsim.core.distributions;

  2. /**
  3.  * Generator implementation for a constant value.
  4.  * <p>
  5.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  6.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  7.  * </p>
  8.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  9.  * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  10.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  11.  * @param <O> type of the object returned by the draw method
  12.  */
  13. public class ConstantGenerator<O> implements Generator<O>
  14. {

  15.     /** Value. */
  16.     private final O value;

  17.     /**
  18.      * Constructor.
  19.      * @param value value
  20.      */
  21.     public ConstantGenerator(final O value)
  22.     {
  23.         this.value = value;
  24.     }

  25.     @Override
  26.     public O draw()
  27.     {
  28.         return this.value;
  29.     }

  30.     /**
  31.      * Returns the value.
  32.      * @return value
  33.      */
  34.     public O getValue()
  35.     {
  36.         return this.value;
  37.     }

  38.     @Override
  39.     public String toString()
  40.     {
  41.         return "ConstantGenerator [value=" + this.value + "]";
  42.     }

  43. }