source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/RuleEvaluator.java @ 1040

Last change on this file since 1040 was 1040, checked in by adeicke, 11 years ago
  • Removed lombok related annotations and util class
  • Added comments and formating due to match project defaults
  • Property svn:mime-type set to text/plain
File size: 4.0 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.evaluation.rule.evaluator;
16
17import java.util.Map;
18
19import com.google.common.base.Optional;
20import com.google.common.collect.Maps;
21
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
23import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefect;
24import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectFactory;
25import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
26import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectXmlDescriptionResolver;
27import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
28import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
29import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatisticCache;
30import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeNodeFilter;
31
32/**
33 * <p>
34 * TODO comment
35 * </p>
36 *
37 * @author Alexander Deicke
38 */
39public abstract class RuleEvaluator {
40
41    protected final UsabilityRule evaluatedUsabilityRule;
42
43    protected final FilterStatistic filteredNodes;
44
45    protected Map<String, String> defectDescriptionMessageParameterValues = Maps.newHashMap();
46
47    public RuleEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) {
48        this.evaluatedUsabilityRule = evaluatedUsabilityRule;
49        this.filteredNodes = nodesUnderEvaluation(taskTree);
50    }
51
52    protected abstract FilterStatistic nodesUnderEvaluation(ITaskTree taskTree);
53
54    @SuppressWarnings("rawtypes")
55    protected Optional<FilterStatistic> loadFromCache(TaskTreeNodeFilter nodeFilter) {
56        return FilterStatisticCache.instance().getFilterStatistic(nodeFilter);
57    }
58
59    @SuppressWarnings("rawtypes")
60    protected FilterStatistic cacheAndReturnNodes(ITaskTree taskTree, TaskTreeNodeFilter nodeFilter)
61    {
62        FilterStatistic textInputEvents = extractNodesFromTaskTree(taskTree);
63        FilterStatisticCache.instance().addFilterStatistic(nodeFilter, textInputEvents);
64        return textInputEvents;
65    }
66
67    protected abstract FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree);
68
69    public Optional<UsabilityDefect> evaluationResult() {
70        Optional<UsabilityDefect> ruleEvaluationResult = Optional.absent();
71        float evaluationMetric = calculateEvaluationMetric();
72        Optional<UsabilityDefectSeverityLevel> severityLevel =
73            determineSeverityLevel(evaluationMetric);
74        if (severityLevel.isPresent()) {
75            ruleEvaluationResult = Optional.of(createRuleEvaluationResult(severityLevel.get()));
76        }
77        return ruleEvaluationResult;
78    }
79
80    protected abstract float calculateEvaluationMetric();
81
82    protected void storeEvaluationMetricForDefectDescription(String key, String value) {
83        defectDescriptionMessageParameterValues.put(key, value);
84    }
85
86    protected abstract Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric);
87
88    public UsabilityDefect createRuleEvaluationResult(UsabilityDefectSeverityLevel severityLevelOfDefect)
89    {
90        return new UsabilityDefectFactory(UsabilityDefectXmlDescriptionResolver.instance())
91            .createUsabilityGuidlineRecommendation(severityLevelOfDefect, evaluatedUsabilityRule,
92                                                   defectDescriptionMessageParameterValues);
93    }
94}
Note: See TracBrowser for help on using the repository browser.