1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.jstats.distributions;
11
12 import nl.tudelft.simulation.jstats.streams.StreamInterface;
13
14 /***
15 * The Constant distribution. For more information on this distribution see <a
16 * href="http://mathworld.wolfram.com/ContinuousDistribution.html">
17 * http://mathworld.wolfram.com/ContinuousDistribution.html </a>
18 * <p>
19 * (c) copyright 2002-2004 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a href="http://www.simulation.tudelft.nl">
22 * www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
24 * License (GPL) </a>, no warranty <br>
25 *
26 * @author <a href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">
27 * Alexander Verbraeck </a> <br>
28 * <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm"> Peter
29 * Jacobs </a>
30 * @version 1.10 2004-03-22
31 * @since 1.2
32 */
33 public class DistConstant extends DistContinuous
34 {
35 /*** value is the value of the constant distribution */
36 private double value;
37
38 /***
39 * constructs a new constant distribution
40 *
41 * @param stream the numberstream
42 * @param value the value
43 */
44 public DistConstant(final StreamInterface stream, final double value)
45 {
46 super(stream);
47 this.value = value;
48 }
49
50 /***
51 * @see DistContinuous#draw()
52 */
53 public double draw()
54 {
55 this.stream.nextDouble();
56 return this.value;
57 }
58
59 /***
60 * @see nl.tudelft.simulation.jstats.distributions.DistContinuous
61 * #probDensity(double)
62 */
63 public double probDensity(final double observation)
64 {
65 if (observation == this.value)
66 {
67 return 1.0;
68 }
69 return 0.0;
70 }
71
72 /***
73 * @see java.lang.Object#toString()
74 */
75 public String toString()
76 {
77 return "Constant(" + this.value + ")";
78 }
79 }