AbstractDiscreteDistScalar.java

  1. package org.opentrafficsim.core.units.distributions;

  2. import java.io.Serializable;

  3. import org.djunits.unit.Unit;

  4. import nl.tudelft.simulation.jstats.distributions.DistDiscrete;
  5. import nl.tudelft.simulation.jstats.distributions.DistDiscreteConstant;
  6. import nl.tudelft.simulation.jstats.streams.Java2Random;
  7. import nl.tudelft.simulation.jstats.streams.StreamInterface;

  8. /**
  9.  * Discrete distribution with unit.
  10.  * <p>
  11.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  13.  * <p>
  14.  * $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $,
  15.  * initial version Feb 2, 2015 <br>
  16.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  17.  */
  18. public abstract class AbstractDiscreteDistScalar implements Serializable
  19. {
  20.     /** */
  21.     private static final long serialVersionUID = 20150000L;

  22.     /** The wrapped distribution function. */
  23.     private final DistDiscrete distribution;

  24.     /** The unit. */
  25.     private final Unit<?> unit;

  26.     /** The dummy stream for the constant values. Is never really used. */
  27.     private static final StreamInterface DUMMY_STREAM = new Java2Random();

  28.     /**
  29.      * @param distribution DistDiscrete; the wrapped distribution function.
  30.      * @param unit Unit&lt;?&gt;; the unit.
  31.      */
  32.     protected AbstractDiscreteDistScalar(final DistDiscrete distribution, final Unit<?> unit)
  33.     {
  34.         super();
  35.         this.distribution = distribution;
  36.         this.unit = unit;
  37.     }

  38.     /**
  39.      * @param constant long; the constant value.
  40.      * @param unit Unit&lt;?&gt;; the unit.
  41.      */
  42.     protected AbstractDiscreteDistScalar(final long constant, final Unit<?> unit)
  43.     {
  44.         this(new DistDiscreteConstant(DUMMY_STREAM, constant), unit);
  45.     }

  46.     /**
  47.      * @return distribution.
  48.      */
  49.     public final DistDiscrete getDistribution()
  50.     {
  51.         return this.distribution;
  52.     }

  53.     /**
  54.      * @return the unit
  55.      */
  56.     public final Unit<?> getUnit()
  57.     {
  58.         return this.unit;
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     @SuppressWarnings("checkstyle:designforextension")
  63.     public String toString()
  64.     {
  65.         return "DiscreteDistScalar [distribution=" + this.distribution + ", unit=" + this.unit + "]";
  66.     }
  67. }