Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mrd/jelly/distribution/Normal.java


1   /*
2    * Normal.java
3    *
4    * Created on May 27, 2002, 5:40 PM
5    */
6   
7   package org.mrd.jelly.distribution;
8   
9   import org.apache.commons.jelly.MissingAttributeException;
10  import org.apache.commons.jelly.TagSupport;
11  import org.apache.commons.jelly.expression.Expression;
12  import cern.jet.random.*;
13  /** This is a random number generation class that produces pseudo-random
14   * doubles acording to a configured Normal Distribution. It uses the
15   * cern.jet.random.Normal Class to support this distribution.
16   *
17   * The distribution can be configured by supplying a mean and a standard 
18   * devation. A seed can also be provided.
19   *
20   * @author  Mark R. Diggory
21   */
22  public class Normal extends DistributionTagBase {
23  
24      /** Holds value of property mean. */
25      private double mean = Double.MIN_VALUE;
26      
27      /** Holds value of property std. */
28      private double std = Double.MIN_VALUE;
29      
30      /** Used by Ant to check if the appropriate attributes have been filled out.
31       * @throws BuildException if attribute is not correctly filled in.
32       */ 
33      public void doStartTag(org.apache.commons.jelly.XMLOutput xMLOutput) throws Exception{
34  
35          if (getVar() == null) 
36              throw new MissingAttributeException("var");
37          
38          if(!(mean > Double.MIN_VALUE))
39              throw new MissingAttributeException("mean");
40  
41          if(!(std > Double.MIN_VALUE))
42              throw new MissingAttributeException("std");
43      }
44  
45      /** Simply put, it is where the execution of the tag occurs.
46       * @throws BuildException (Currently does not).
47       */   
48      public void doEndTag(org.apache.commons.jelly.XMLOutput xMLOutput) throws Exception {
49          if( context.getVariable(getVar()) == null ){
50              context.setVariable(getVar(),new cern.jet.random.Normal(mean,std,this.getRandomElement()));
51          }
52      }
53      
54      /** Getter for property mean.
55       * @return Value of property mean.
56       */
57      public double getMean() {
58          return mean;
59      }
60      
61      /** Setter for property mean.
62       * @param mean New value of property mean.
63       */
64      public void setMean(double mean) {
65          this.mean = mean;
66      }
67      
68      /** Getter for property std.
69       * @return Value of property std.
70       */
71      public double getStd() {
72          return std;
73      }
74      
75      /** Setter for property std.
76       * @param std New value of property std.
77       */
78      public void setStd(double std) {
79          this.std = std;
80      }
81     
82  }