View Javadoc
1   package eu.simuline.relana.model;
2   
3   import java.math.BigDecimal;
4   
5   import java.util.Set;
6   import java.util.Map;
7   
8   /**
9    * Resolvation of a property within an {@link SClass} 
10   * into elementary stochastically independent properties. 
11   *
12   * Created: Mon Apr 25 15:18:32 2005
13   *
14   * @author <a href="mailto:ernst.reissner@simuline.eu">Ernst Reissner</a>
15   * @version 1.0
16   */
17  public final class DeficiencySetNode {
18  
19      /* -------------------------------------------------------------------- *
20       * attributes.                                                          *
21       * -------------------------------------------------------------------- */
22  
23      /**
24       * The <code>Deficiency</code> to be resolved. 
25       */
26      private final Deficiency deficiency;
27  
28      /**
29       * The set of elementary <code>Deficiency</code>s 
30       * resolving {@link #deficiency}. 
31       */
32      private final Set<Deficiency> deficiencySet;
33  
34  
35      /* -------------------------------------------------------------------- *
36       * constructors.                                                        *
37       * -------------------------------------------------------------------- */
38  
39      public DeficiencySetNode(Deficiency deficiency,
40  			     Set<Deficiency> deficiencySet) {
41  	this.deficiency    = deficiency;
42  	this.deficiencySet = deficiencySet;
43      }
44  
45  
46      /* -------------------------------------------------------------------- *
47       * methods.                                                             *
48       * -------------------------------------------------------------------- */
49  
50      /**
51       * Returns the <code>Deficiency</code> to be resolved. 
52       *
53       * @return 
54       *    the <code>Deficiency</code> to be resolved. 
55       */
56      public Deficiency getDeficiency() {
57  	return this.deficiency;
58      }
59  
60      /**
61       * Returns the set of elementary <code>Deficiency</code>s 
62       * resolving {@link #deficiency}. 
63       *
64       * @return 
65       *    the set of elementary <code>Deficiency</code>s 
66       *    resolving {@link #deficiency}. 
67       */
68      public Set<Deficiency> getDeficiencySet() {
69  	return this.deficiencySet;
70      }
71  
72      /**
73       * Returns the probability of the wrapped deficiency {@link #deficiency} 
74       * if replaced by the set {@link #deficiencySet} of deficiencies 
75       * which are assumed to be independent. 
76       *
77       * @param def2prob
78       *    a probability distribution 
79       *    the key set of which contains {@link #deficiencySet}. 
80       * @return 
81       *    the <code>double</code> value 
82       *    representing the probability of the deficiency {@link #deficiency} 
83       *    or equivalently the probability of the simultaneous occurence of 
84       *    {@link #deficiencySet}, independence assumed. 
85       */
86      public BigDecimal getProb(Map<Deficiency, BigDecimal> def2prob) {
87  	BigDecimal res = BigDecimal.ONE;
88  	for (Deficiency def : this.deficiencySet) {
89  	    res = res.multiply(def2prob.get(def));
90  	}
91  	return res;
92      }
93  
94      public String toString() {
95  	StringBuffer res = new StringBuffer();
96  	res.append("<DeficiencySetNode deficiency=\"");
97  	res.append(this.deficiency);
98  	res.append("\">");
99  	res.append(this.deficiencySet);
100 	res.append("</DeficiencySetNode>");
101 	return res.toString();
102     }
103 } // DeficiencySetNode