1 | package de.uka.ipd.sdq.probfunction.print; |
2 | |
3 | import java.util.List; |
4 | |
5 | import de.uka.ipd.sdq.probfunction.BoxedPDF; |
6 | import de.uka.ipd.sdq.probfunction.ContinuousSample; |
7 | import de.uka.ipd.sdq.probfunction.ProbabilityFunction; |
8 | import de.uka.ipd.sdq.probfunction.ProbabilityMassFunction; |
9 | import de.uka.ipd.sdq.probfunction.Sample; |
10 | import de.uka.ipd.sdq.probfunction.util.ProbfunctionSwitch; |
11 | |
12 | public class ProbFunctionCSVPrint extends ProbfunctionSwitch<String> { |
13 | |
14 | /* |
15 | * (non-Javadoc) |
16 | * |
17 | * @see de.uka.ipd.sdq.probfunction.util.ProbfunctionSwitch#caseBoxedPDF(de.uka.ipd.sdq.probfunction.BoxedPDF) |
18 | */ |
19 | /** |
20 | * Prints a {@link ProbabilityFunction} as comma separated values using the generated EMF visitor. |
21 | */ |
22 | @Override |
23 | public String caseBoxedPDF(BoxedPDF object) { |
24 | String sampleString = ""; |
25 | for (ContinuousSample s : (List<ContinuousSample>) object.getSamples()) { |
26 | double value = s.getProbability(); |
27 | //double precision = 0.00001; |
28 | //double precision = 0.00000001; |
29 | |
30 | /*value *= 1 / precision; |
31 | long temp = Math.round(value); |
32 | double prob = temp * precision; |
33 | DecimalFormat df = new DecimalFormat("0.00000000", new DecimalFormatSymbols(Locale.US));*/ |
34 | |
35 | //sampleString += " (" + s.getValue() + "; " + df.format(prob) |
36 | sampleString += s.getValue() + ";" + value + "\n"; |
37 | } |
38 | |
39 | return sampleString; |
40 | } |
41 | |
42 | /* |
43 | * (non-Javadoc) |
44 | * |
45 | * @see de.uka.ipd.sdq.probfunction.util.ProbfunctionSwitch#caseProbabilityMassFunction(de.uka.ipd.sdq.probfunction.ProbabilityMassFunction) |
46 | */ |
47 | @Override |
48 | public String caseProbabilityMassFunction(ProbabilityMassFunction object) { |
49 | |
50 | String sampleString = ""; |
51 | String leftSeparator = ""; |
52 | String rightSeparator = ";"; |
53 | |
54 | |
55 | for (Sample s : (List<Sample>) object.getSamples()) { |
56 | sampleString += leftSeparator + s.getValue() |
57 | + rightSeparator + s.getProbability() + "\n"; |
58 | } |
59 | return sampleString; |
60 | } |
61 | |
62 | |
63 | |
64 | } |