1 | package de.uka.ipd.sdq.dsexplore.analysis.lqn; |
2 | |
3 | import java.text.DecimalFormat; |
4 | import java.text.DecimalFormatSymbols; |
5 | import java.text.ParseException; |
6 | import java.util.Locale; |
7 | |
8 | import org.eclipse.emf.common.util.EList; |
9 | |
10 | import LqnCore.ActivityDefType; |
11 | import LqnCore.OutputResultType; |
12 | import LqnCore.TaskType; |
13 | |
14 | import de.uka.ipd.sdq.dsexplore.analysis.AnalysisFailedException; |
15 | |
16 | /** |
17 | * Provides utility methods which are useful when working with LQN. |
18 | * |
19 | * @author pmerkle |
20 | * |
21 | */ |
22 | public class LQNUtils { |
23 | |
24 | /** |
25 | * Converts the given String in LQN specific scientific format (e.g. |
26 | * 1.0E-003) to the corresponding double value. |
27 | * |
28 | * @param toConvert |
29 | * @return |
30 | * @throws AnalysisFailedException |
31 | */ |
32 | public static double convertStringToDouble(String toConvert) throws ParseException { |
33 | double ret; |
34 | |
35 | toConvert = toConvert.replaceAll("e", "E"); |
36 | toConvert = toConvert.replaceAll("\\+", ""); |
37 | DecimalFormat format = new DecimalFormat("0.0E000", |
38 | DecimalFormatSymbols.getInstance(Locale.ENGLISH)); |
39 | ret = format.parse(toConvert).doubleValue(); |
40 | |
41 | return ret; |
42 | } |
43 | |
44 | public static double getResponseTimeOfSubActivities(TaskType task) throws ParseException { |
45 | // We add all result service times of the usage scenario to compute |
46 | // the response time |
47 | // TODO: check whether this works correctly if the usage scenario |
48 | // contains branches |
49 | double time = 0; |
50 | EList<ActivityDefType> activities = task.getTaskActivities() |
51 | .getActivity(); |
52 | for (ActivityDefType activity : activities) { |
53 | EList<OutputResultType> results = activity.getResultActivity(); |
54 | for (OutputResultType outputResultType : results) { |
55 | |
56 | time += LQNUtils |
57 | .convertStringToDouble((String) outputResultType |
58 | .getServiceTime()); |
59 | } |
60 | |
61 | } |
62 | return time; |
63 | } |
64 | |
65 | |
66 | } |