1 | package de.uka.ipd.sdq.stoex.analyser.operations; |
2 | |
3 | import java.util.List; |
4 | |
5 | import de.uka.ipd.sdq.probfunction.math.IProbabilityMassFunction; |
6 | import de.uka.ipd.sdq.probfunction.math.ISample; |
7 | |
8 | /** |
9 | * Implements the operation "equals" for different kinds of operands. |
10 | * |
11 | * @author koziolek |
12 | */ |
13 | public class EqualsOperation extends CompareOperation { |
14 | |
15 | protected IProbabilityMassFunction getComparePMF(boolean left, boolean right) { |
16 | if (left == right) |
17 | return getBoolPMF(1.0); |
18 | else |
19 | return getBoolPMF(0.0); |
20 | } |
21 | |
22 | protected IProbabilityMassFunction getComparePMF(double left, double right) { |
23 | if (left == right) |
24 | return getBoolPMF(1.0); |
25 | else |
26 | return getBoolPMF(0.0); |
27 | } |
28 | |
29 | protected IProbabilityMassFunction getComparePMF(double left, |
30 | IProbabilityMassFunction right) { |
31 | return compare(right, left); |
32 | } |
33 | |
34 | protected IProbabilityMassFunction getComparePMF( |
35 | IProbabilityMassFunction left, double right) { |
36 | return getBoolPMF(getProbabilityForValue(left, right)); |
37 | } |
38 | |
39 | protected IProbabilityMassFunction getComparePMF( |
40 | IProbabilityMassFunction left, IProbabilityMassFunction right) { |
41 | return getBoolPMF(comparePointWise(left, right, this)); |
42 | } |
43 | |
44 | protected IProbabilityMassFunction getComparePMF(String left, |
45 | IProbabilityMassFunction right) { |
46 | List<ISample> list = right.getSamples(); |
47 | for (ISample sample : list) { |
48 | String sampleString = (String) sample.getValue(); |
49 | if (left.equals(sampleString)) { |
50 | return getBoolPMF(sample.getProbability()); |
51 | } |
52 | } |
53 | return getBoolPMF(0.0); |
54 | } |
55 | |
56 | protected IProbabilityMassFunction getComparePMF(String left, String right) { |
57 | if (left.equals(right)) |
58 | return getBoolPMF(1.0); |
59 | else |
60 | return getBoolPMF(0.0); |
61 | } |
62 | } |