source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/TaskMetric.java @ 1733

Last change on this file since 1733 was 1733, checked in by rkrimmel, 10 years ago

Used Eclipse code cleanup

File size: 3.6 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeifc;
16
17import java.text.DecimalFormat;
18
19/**
20 * <p>
21 * represents different metrics available or calculatable for tasks. Measure for
22 * the metrics are calculated by a task model and added to the task infos of a
23 * specific task.
24 * </p>
25 *
26 * @author Patrick Harms
27 */
28public enum TaskMetric {
29
30        COUNT("count", "number of all occurrences of the task in the model"), DEPTH(
31                        "depth",
32                        "the maximum depth of the task, i.e., the number of children levels including the "
33                                        + "level of the task itself"), EVENT_COVERAGE(
34                        "covered events",
35                        "number of all event task instances covered by the task"), EVENT_COVERAGE_RATIO(
36                        "event coverage ratio",
37                        "the ratio of events covered by this task in relation to all events "
38                                        + "covered by all tasks in their instances in per mille",
39                        0.1, "%"), EVENT_COVERAGE_QUANTILE("event coverage ratio quantile",
40                        "the quantile of with respect to all event coverages begining with "
41                                        + "the lowest", 0.1, "%");
42
43        /**
44         * <p>
45         * the name of the metric
46         * </p>
47         */
48        private String name;
49
50        /**
51         * <p>
52         * a human readable description of the metric
53         * </p>
54         */
55        private String description;
56
57        /**
58         * <p>
59         * a scale applied for the metric when formatting the value
60         * </p>
61         */
62        private double formatScale;
63
64        /**
65         * <p>
66         * the unit of the metric used when formatting the value
67         * </p>
68         */
69        private String formatUnit;
70
71        /**
72         * <p>
73         * initializes the metric with a name and a description
74         * </p>
75         */
76        private TaskMetric(String name, String description) {
77                this.name = name;
78                this.description = description;
79                this.formatScale = 1.0;
80                this.formatUnit = null;
81        }
82
83        /**
84         * <p>
85         * initializes the metric with a name and a description, as well as with a
86         * scale and a unit for formatting it.
87         * </p>
88         */
89        private TaskMetric(String name, String description, double formatScale,
90                        String formatUnit) {
91                this.name = name;
92                this.description = description;
93                this.formatScale = formatScale;
94                this.formatUnit = formatUnit;
95        }
96
97        /**
98         * <p>
99         * formats the provided value of a measure of the metric using the internal
100         * format scale and unit.
101         * </p>
102         *
103         * @return the formatted value depending on the scale and unit of the metric
104         */
105        public String formatValue(int value) {
106                String formattedValue;
107
108                if (formatScale != 1.0) {
109                        final double effectiveValue = formatScale * value;
110                        formattedValue = new DecimalFormat("#,##0.0;(#)")
111                                        .format(effectiveValue);
112                } else {
113                        formattedValue = Integer.toString(value);
114                }
115
116                if (formatUnit != null) {
117                        formattedValue += formatUnit;
118                }
119
120                return formattedValue;
121        }
122
123        /**
124         * <p>
125         * returns the human readable description of the metric
126         * </p>
127         *
128         * @return the human readable description of the metric
129         */
130        public String getDescription() {
131                return description;
132        }
133
134        /**
135         * <p>
136         * returns the name of the metric
137         * </p>
138         *
139         * @return the name of the metric
140         */
141        public String getName() {
142                return name;
143        }
144}
Note: See TracBrowser for help on using the repository browser.