source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/patterns/visitors/ContainsPatternVisitor.java @ 1161

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

Adjustments due to change from TaskTree? to TaskModel?.

  • Property svn:mime-type set to text/plain
File size: 2.6 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.rules.patterns.visitors;
16
17import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
18import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
19import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
21import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePattern;
22import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePatternVisitor;
23
24/**
25 * <p>
26 * TODO comment
27 * </p>
28 *
29 * @author Alexander Deicke
30 */
31public class ContainsPatternVisitor extends UsagePatternVisitor {
32
33    /**
34     * <p>
35     * TODO: comment
36     * </p>
37     *
38     * @param containsPattern
39     */
40    public ContainsPatternVisitor(UsagePattern containsPattern) {
41        this.containedPattern = containsPattern;
42    }
43
44    /* (non-Javadoc)
45     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration)
46     */
47    public void visit(IIteration iteration) {
48        checkTaskAndReturnIfPatternIsPresent(iteration.getMarkedTask());
49    }
50
51    /* (non-Javadoc)
52     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence)
53     */
54    public void visit(ISequence sequence) {
55        checkAllChildrenAndReturnIfPatternIsPresent(sequence);
56    }
57   
58    private void checkAllChildrenAndReturnIfPatternIsPresent(ISequence sequence) {
59        for (ITask child : sequence.getChildren()) {
60            if(checkTaskAndReturnIfPatternIsPresent(child)) {
61                this.present = true;
62                break;
63            }
64        }
65    }
66   
67    private boolean checkTaskAndReturnIfPatternIsPresent(ITask task) {
68        if(isEvent(task)) return false;
69        return this.containedPattern.containedIn(task);
70    }
71   
72    private boolean isEvent(ITask task) {
73        return task instanceof IEventTask;
74    }
75
76}
Note: See TracBrowser for help on using the repository browser.