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. This distribution maskers a constant discrete
16 * value.
17 * <p>
18 * (c) copyright 2002-2004 <a href="http://www.simulation.tudelft.nl">Delft
19 * University of Technology </a>, the Netherlands. <br>
20 * See for project information <a href="http://www.simulation.tudelft.nl">
21 * www.simulation.tudelft.nl </a> <br>
22 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
23 * License (GPL) </a>, no warranty <br>
24 *
25 * @author <a href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">
26 * Alexander Verbraeck </a> <br>
27 * <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm"> Peter
28 * Jacobs </a>
29 * @version 1.11 2004-03-22
30 * @since 1.2
31 */
32 public class DistDiscreteConstant extends DistDiscrete
33 {
34 /*** value is the value of the distribution */
35 private long value;
36
37 /***
38 * creates a new discrete constant distribution
39 *
40 * @param stream the numberstream
41 * @param value the value for this distribution
42 */
43 public DistDiscreteConstant(final StreamInterface stream, final long value)
44 {
45 super(stream);
46 this.value = value;
47 }
48
49 /***
50 * @see DistDiscrete#draw()
51 */
52 public long draw()
53 {
54 this.stream.nextDouble();
55 return this.value;
56 }
57
58 /***
59 * @see nl.tudelft.simulation.jstats.distributions.DistDiscrete
60 * #probability(int)
61 */
62 public double probability(final int observation)
63 {
64 if (observation == this.value)
65 {
66 return 1.0;
67 }
68 return 0.0;
69 }
70
71 /***
72 * @see java.lang.Object#toString()
73 */
74 public String toString()
75 {
76 return "DiscreteConstant(" + this.value + ")";
77 }
78 }