View Javadoc
1   package org.opentrafficsim.core.units.distributions;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.Unit;
6   
7   import nl.tudelft.simulation.jstats.distributions.DistDiscrete;
8   import nl.tudelft.simulation.jstats.distributions.DistDiscreteConstant;
9   import nl.tudelft.simulation.jstats.streams.Java2Random;
10  import nl.tudelft.simulation.jstats.streams.StreamInterface;
11  
12  /**
13   * Discrete distribution with unit.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $,
19   * initial version Feb 2, 2015 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   */
22  public abstract class AbstractDiscreteDistScalar implements Serializable
23  {
24      /** */
25      private static final long serialVersionUID = 20150000L;
26  
27      /** The wrapped distribution function. */
28      private final DistDiscrete distribution;
29  
30      /** The unit. */
31      private final Unit<?> unit;
32  
33      /** The dummy stream for the constant values. Is never really used. */
34      private static final StreamInterface DUMMY_STREAM = new Java2Random();
35  
36      /**
37       * @param distribution DistDiscrete; the wrapped distribution function.
38       * @param unit Unit&lt;?&gt;; the unit.
39       */
40      protected AbstractDiscreteDistScalar(final DistDiscrete distribution, final Unit<?> unit)
41      {
42          super();
43          this.distribution = distribution;
44          this.unit = unit;
45      }
46  
47      /**
48       * @param constant long; the constant value.
49       * @param unit Unit&lt;?&gt;; the unit.
50       */
51      protected AbstractDiscreteDistScalar(final long constant, final Unit<?> unit)
52      {
53          this(new DistDiscreteConstant(DUMMY_STREAM, constant), unit);
54      }
55  
56      /**
57       * @return distribution.
58       */
59      public final DistDiscrete getDistribution()
60      {
61          return this.distribution;
62      }
63  
64      /**
65       * @return the unit
66       */
67      public final Unit<?> getUnit()
68      {
69          return this.unit;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      @SuppressWarnings("checkstyle:designforextension")
75      public String toString()
76      {
77          return "DiscreteDistScalar [distribution=" + this.distribution + ", unit=" + this.unit + "]";
78      }
79  }