source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/result/UsabilityDefect.java @ 1198

Last change on this file since 1198 was 1198, checked in by adeicke, 11 years ago

Return severity level also, when metric matches threshold direct.

  • Property svn:mime-type set to text/plain
File size: 3.5 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.usability.result;
16
17import java.util.Collections;
18import java.util.EnumMap;
19import java.util.Map;
20
21import com.google.common.base.Optional;
22import com.google.common.base.Predicate;
23import com.google.common.collect.BiMap;
24import com.google.common.collect.HashBiMap;
25import com.google.common.collect.Maps;
26
27
28/**
29 * <p>
30 * TODO comment
31 * </p>
32 *
33 * @author Alexander Deicke
34 */
35public class UsabilityDefect {
36
37    private UsabilityDefectSeverityLevel severityLevel = UsabilityDefectSeverityLevel.NONE;
38   
39    private String description;
40   
41    private final EnumMap<UsabilityDefectSeverityLevel, Double> severity;
42   
43    /**
44     * <p>
45     * TODO: comment
46     * </p>
47     *
48     * @param description
49     * @param severity
50     */
51    public UsabilityDefect(String description,
52                           EnumMap<UsabilityDefectSeverityLevel, Double> severity)
53    {
54        this.description = description;
55        this.severity = severity;
56    }
57
58    /**
59     * <p>
60     * TODO: comment
61     * </p>
62     *
63     * @return
64     */
65    public UsabilityDefectSeverityLevel getSeverityLevel() {
66        return this.severityLevel;
67    }
68
69    /**
70     * <p>
71     * TODO: comment
72     * </p>
73     *
74     * @param evaluationMetric
75     * @return
76     */
77    public Optional<UsabilityDefect> isPresent(float evaluationMetric) {
78        Optional<UsabilityDefect> defect = Optional.absent();
79        Map<UsabilityDefectSeverityLevel, Double> matchingSeverityLevels = Maps.filterValues(this.severity, severityForMetric(evaluationMetric));
80        if(matchingSeverityLevels.isEmpty()) {
81            return defect;
82        }
83        setDefectAttributes(matchingSeverityLevels, evaluationMetric);
84        return Optional.of(this);
85    }
86
87    /**
88     * <p>
89     * TODO: comment
90     * </p>
91     *
92     * @param matchingSeverityLevels
93     * @param evaluationMetric
94     */
95    private void setDefectAttributes(Map<UsabilityDefectSeverityLevel, Double> matchingSeverityLevels,
96                                     float evaluationMetric)
97    {
98        BiMap<Double, UsabilityDefectSeverityLevel> inverse = HashBiMap.create(matchingSeverityLevels).inverse();
99        this.severityLevel = inverse.get(Collections.max(inverse.keySet()));
100        this.description = String.format(this.description, evaluationMetric);
101    }
102
103    /**
104     * <p>
105     * TODO: comment
106     * </p>
107     * @param evaluationMetric
108     *
109     * @return
110     */
111    private Predicate< Double> severityForMetric(final float evaluationMetric) {
112        return new Predicate<Double>() {
113           
114            public boolean apply(Double severityThreshold) {
115                return evaluationMetric == severityThreshold || evaluationMetric > severityThreshold;
116            }
117           
118        };
119    }
120
121}
Note: See TracBrowser for help on using the repository browser.