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.usability.result;
|
---|
16 |
|
---|
17 | import java.util.Collections;
|
---|
18 | import java.util.EnumMap;
|
---|
19 | import java.util.Map;
|
---|
20 |
|
---|
21 | import com.google.common.base.Optional;
|
---|
22 | import com.google.common.base.Predicate;
|
---|
23 | import com.google.common.collect.BiMap;
|
---|
24 | import com.google.common.collect.HashBiMap;
|
---|
25 | import com.google.common.collect.Maps;
|
---|
26 |
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * <p>
|
---|
30 | * TODO comment
|
---|
31 | * </p>
|
---|
32 | *
|
---|
33 | * @author Alexander Deicke
|
---|
34 | */
|
---|
35 | public 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;
|
---|
116 | }
|
---|
117 |
|
---|
118 | };
|
---|
119 | }
|
---|
120 |
|
---|
121 | }
|
---|