1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.treeifc; |
---|
16 | |
---|
17 | import java.text.DecimalFormat; |
---|
18 | |
---|
19 | // TODO: Auto-generated Javadoc |
---|
20 | /** |
---|
21 | * <p> |
---|
22 | * represents different metrics available or calculatable for tasks. Measure for |
---|
23 | * the metrics are calculated by a task model and added to the task infos of a |
---|
24 | * specific task. |
---|
25 | * </p> |
---|
26 | * |
---|
27 | * @author Patrick Harms |
---|
28 | */ |
---|
29 | public enum TaskMetric { |
---|
30 | |
---|
31 | /** The count. */ |
---|
32 | COUNT("count", "number of all occurrences of the task in the model"), /** The depth. */ |
---|
33 | DEPTH( |
---|
34 | "depth", |
---|
35 | "the maximum depth of the task, i.e., the number of children levels including the " |
---|
36 | + "level of the task itself"), |
---|
37 | /** The event coverage. */ |
---|
38 | EVENT_COVERAGE( |
---|
39 | "covered events", |
---|
40 | "number of all event task instances covered by the task"), |
---|
41 | /** The event coverage ratio. */ |
---|
42 | EVENT_COVERAGE_RATIO( |
---|
43 | "event coverage ratio", |
---|
44 | "the ratio of events covered by this task in relation to all events " |
---|
45 | + "covered by all tasks in their instances in per mille", |
---|
46 | 0.1, "%"), |
---|
47 | /** The event coverage quantile. */ |
---|
48 | EVENT_COVERAGE_QUANTILE("event coverage ratio quantile", |
---|
49 | "the quantile of with respect to all event coverages begining with " |
---|
50 | + "the lowest", 0.1, "%"); |
---|
51 | |
---|
52 | /** <p> the name of the metric </p>. */ |
---|
53 | private String name; |
---|
54 | |
---|
55 | /** <p> a human readable description of the metric </p>. */ |
---|
56 | private String description; |
---|
57 | |
---|
58 | /** <p> a scale applied for the metric when formatting the value </p>. */ |
---|
59 | private double formatScale; |
---|
60 | |
---|
61 | /** <p> the unit of the metric used when formatting the value </p>. */ |
---|
62 | private String formatUnit; |
---|
63 | |
---|
64 | /** |
---|
65 | * <p> |
---|
66 | * initializes the metric with a name and a description |
---|
67 | * </p>. |
---|
68 | * |
---|
69 | * @param name the name |
---|
70 | * @param description the description |
---|
71 | */ |
---|
72 | private TaskMetric(String name, String description) { |
---|
73 | this.name = name; |
---|
74 | this.description = description; |
---|
75 | this.formatScale = 1.0; |
---|
76 | this.formatUnit = null; |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * <p> |
---|
81 | * initializes the metric with a name and a description, as well as with a |
---|
82 | * scale and a unit for formatting it. |
---|
83 | * </p> |
---|
84 | * |
---|
85 | * @param name the name |
---|
86 | * @param description the description |
---|
87 | * @param formatScale the format scale |
---|
88 | * @param formatUnit the format unit |
---|
89 | */ |
---|
90 | private TaskMetric(String name, String description, double formatScale, |
---|
91 | String formatUnit) { |
---|
92 | this.name = name; |
---|
93 | this.description = description; |
---|
94 | this.formatScale = formatScale; |
---|
95 | this.formatUnit = formatUnit; |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * <p> |
---|
100 | * formats the provided value of a measure of the metric using the internal |
---|
101 | * format scale and unit. |
---|
102 | * </p> |
---|
103 | * |
---|
104 | * @param value the value |
---|
105 | * @return the formatted value depending on the scale and unit of the metric |
---|
106 | */ |
---|
107 | public String formatValue(int value) { |
---|
108 | String formattedValue; |
---|
109 | |
---|
110 | if (formatScale != 1.0) { |
---|
111 | final double effectiveValue = formatScale * value; |
---|
112 | formattedValue = new DecimalFormat("#,##0.0;(#)") |
---|
113 | .format(effectiveValue); |
---|
114 | } else { |
---|
115 | formattedValue = Integer.toString(value); |
---|
116 | } |
---|
117 | |
---|
118 | if (formatUnit != null) { |
---|
119 | formattedValue += formatUnit; |
---|
120 | } |
---|
121 | |
---|
122 | return formattedValue; |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * <p> |
---|
127 | * returns the human readable description of the metric |
---|
128 | * </p>. |
---|
129 | * |
---|
130 | * @return the human readable description of the metric |
---|
131 | */ |
---|
132 | public String getDescription() { |
---|
133 | return description; |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * <p> |
---|
138 | * returns the name of the metric |
---|
139 | * </p>. |
---|
140 | * |
---|
141 | * @return the name of the metric |
---|
142 | */ |
---|
143 | public String getName() { |
---|
144 | return name; |
---|
145 | } |
---|
146 | } |
---|