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

Last change on this file since 1293 was 1217, checked in by adeicke, 11 years ago
  • Added proper formating and JavaDoc?.
  • Several renaming refactorings.
  • Property svn:mime-type set to text/plain
File size: 4.9 KB
RevLine 
[1138]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 * <p>
[1217]29 * Description for a usability problem.
[1138]30 * </p>
31 *
32 * @author Alexander Deicke
33 */
[1217]34public class UsabilityProblemDescription {
35    /**
36     * <p>
37     * The severity of the defect.
38     * </p>
39     */
[1138]40
[1217]41    private UsabilityProblemSeverityLevel severityLevel = UsabilityProblemSeverityLevel.NONE;
42
43    /**
44     * <p>
45     * A detailed description of the defect.
46     * </p>
47     */
[1138]48    private String description;
[1217]49
[1138]50    /**
51     * <p>
[1217]52     * Assignment of all possible severity values to a certain threshold. This is used, to determine
53     * the severity level during the usability evaluation.
[1138]54     * </p>
[1217]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     *
[1138]64     * @param description
[1217]65     *            description of the defect
[1138]66     * @param severity
[1217]67     *            all possible severity level and their threshold
[1138]68     */
[1217]69    public UsabilityProblemDescription(String description,
70                                      EnumMap<UsabilityProblemSeverityLevel, Double> severity)
[1138]71    {
72        this.description = description;
73        this.severity = severity;
74    }
75
76    /**
77     * <p>
[1217]78     * Gets the severity level of this defect.
[1138]79     * </p>
[1217]80     *
81     * @return severity level of this defect
[1138]82     */
[1217]83    public UsabilityProblemSeverityLevel getSeverityLevel() {
[1138]84        return this.severityLevel;
85    }
86
87    /**
88     * <p>
[1217]89     * Checks, if a defect is present. Therefore it uses a value, which is used to determine the
90     * severity level.
[1138]91     * </p>
[1217]92     *
[1138]93     * @param evaluationMetric
[1217]94     *            value, which determines the severity level of a defect
95     * @return iff defect is present, a {@linkplain UsabilityProblemDescription} of the defect
[1138]96     */
[1217]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()) {
[1138]102            return defect;
103        }
104        setDefectAttributes(matchingSeverityLevels, evaluationMetric);
105        return Optional.of(this);
106    }
107
108    /**
109     * <p>
[1217]110     * Initializes the properties of a {@linkplain UsabilityProblemDescription}.
[1138]111     * </p>
[1217]112     *
[1138]113     * @param matchingSeverityLevels
[1217]114     *            all severity level, where {@linkplain evaluationMetric} exceeds the threshold
[1138]115     * @param evaluationMetric
[1217]116     *            measure for the defect
[1138]117     */
[1217]118    private void setDefectAttributes(Map<UsabilityProblemSeverityLevel, Double> matchingSeverityLevels,
[1138]119                                     float evaluationMetric)
120    {
[1217]121        BiMap<Double, UsabilityProblemSeverityLevel> inverse =
122            HashBiMap.create(matchingSeverityLevels).inverse();
[1138]123        this.severityLevel = inverse.get(Collections.max(inverse.keySet()));
124        this.description = String.format(this.description, evaluationMetric);
125    }
126
127    /**
128     * <p>
[1217]129     * Gets severity level depending on a measurement for the defect.
[1138]130     * </p>
[1217]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
[1138]137     */
[1217]138    private Predicate<Double> severityForMetric(final float evaluationMetric) {
[1138]139        return new Predicate<Double>() {
[1217]140
[1138]141            public boolean apply(Double severityThreshold) {
[1217]142                return evaluationMetric == severityThreshold ||
143                    evaluationMetric > severityThreshold;
[1138]144            }
[1217]145
[1138]146        };
147    }
148
149}
Note: See TracBrowser for help on using the repository browser.