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 | * <p>
|
---|
29 | * Description for a usability problem.
|
---|
30 | * </p>
|
---|
31 | *
|
---|
32 | * @author Alexander Deicke
|
---|
33 | */
|
---|
34 | public class UsabilityProblemDescription {
|
---|
35 | /**
|
---|
36 | * <p>
|
---|
37 | * The severity of the defect.
|
---|
38 | * </p>
|
---|
39 | */
|
---|
40 |
|
---|
41 | private UsabilityProblemSeverityLevel severityLevel = UsabilityProblemSeverityLevel.NONE;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * <p>
|
---|
45 | * A detailed description of the defect.
|
---|
46 | * </p>
|
---|
47 | */
|
---|
48 | private String description;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * <p>
|
---|
52 | * Assignment of all possible severity values to a certain threshold. This is used, to determine
|
---|
53 | * the severity level during the usability evaluation.
|
---|
54 | * </p>
|
---|
55 | */
|
---|
56 | private final EnumMap<UsabilityProblemSeverityLevel, Double> severity;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * <p>
|
---|
60 | * Constructor. Creates a new UsabilityDefectDescription for given description and all possible
|
---|
61 | * severity level.
|
---|
62 | * </p>
|
---|
63 | *
|
---|
64 | * @param description
|
---|
65 | * description of the defect
|
---|
66 | * @param severity
|
---|
67 | * all possible severity level and their threshold
|
---|
68 | */
|
---|
69 | public UsabilityProblemDescription(String description,
|
---|
70 | EnumMap<UsabilityProblemSeverityLevel, Double> severity)
|
---|
71 | {
|
---|
72 | this.description = description;
|
---|
73 | this.severity = severity;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * <p>
|
---|
78 | * Gets the severity level of this defect.
|
---|
79 | * </p>
|
---|
80 | *
|
---|
81 | * @return severity level of this defect
|
---|
82 | */
|
---|
83 | public UsabilityProblemSeverityLevel getSeverityLevel() {
|
---|
84 | return this.severityLevel;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * <p>
|
---|
89 | * Checks, if a defect is present. Therefore it uses a value, which is used to determine the
|
---|
90 | * severity level.
|
---|
91 | * </p>
|
---|
92 | *
|
---|
93 | * @param evaluationMetric
|
---|
94 | * value, which determines the severity level of a defect
|
---|
95 | * @return iff defect is present, a {@linkplain UsabilityProblemDescription} of the defect
|
---|
96 | */
|
---|
97 | public Optional<UsabilityProblemDescription> isPresent(float evaluationMetric) {
|
---|
98 | Optional<UsabilityProblemDescription> defect = Optional.absent();
|
---|
99 | Map<UsabilityProblemSeverityLevel, Double> matchingSeverityLevels =
|
---|
100 | Maps.filterValues(this.severity, severityForMetric(evaluationMetric));
|
---|
101 | if (matchingSeverityLevels.isEmpty()) {
|
---|
102 | return defect;
|
---|
103 | }
|
---|
104 | setDefectAttributes(matchingSeverityLevels, evaluationMetric);
|
---|
105 | return Optional.of(this);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * <p>
|
---|
110 | * Initializes the properties of a {@linkplain UsabilityProblemDescription}.
|
---|
111 | * </p>
|
---|
112 | *
|
---|
113 | * @param matchingSeverityLevels
|
---|
114 | * all severity level, where {@linkplain evaluationMetric} exceeds the threshold
|
---|
115 | * @param evaluationMetric
|
---|
116 | * measure for the defect
|
---|
117 | */
|
---|
118 | private void setDefectAttributes(Map<UsabilityProblemSeverityLevel, Double> matchingSeverityLevels,
|
---|
119 | float evaluationMetric)
|
---|
120 | {
|
---|
121 | BiMap<Double, UsabilityProblemSeverityLevel> inverse =
|
---|
122 | HashBiMap.create(matchingSeverityLevels).inverse();
|
---|
123 | this.severityLevel = inverse.get(Collections.max(inverse.keySet()));
|
---|
124 | this.description = String.format(this.description, evaluationMetric);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * <p>
|
---|
129 | * Gets severity level depending on a measurement for the defect.
|
---|
130 | * </p>
|
---|
131 | *
|
---|
132 | * @param evaluationMetric
|
---|
133 | * measure for the defect
|
---|
134 | *
|
---|
135 | * @return severity level, if measurement is equal or bigger as the threshold of the severity
|
---|
136 | * level
|
---|
137 | */
|
---|
138 | private Predicate<Double> severityForMetric(final float evaluationMetric) {
|
---|
139 | return new Predicate<Double>() {
|
---|
140 |
|
---|
141 | public boolean apply(Double severityThreshold) {
|
---|
142 | return evaluationMetric == severityThreshold ||
|
---|
143 | evaluationMetric > severityThreshold;
|
---|
144 | }
|
---|
145 |
|
---|
146 | };
|
---|
147 | }
|
---|
148 |
|
---|
149 | }
|
---|