[1150] | 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.rules.patterns.visitors;
|
---|
| 16 |
|
---|
[1152] | 17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
[1150] | 18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
|
---|
| 19 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
|
---|
[1152] | 20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
[1150] | 21 | import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePattern;
|
---|
| 22 | import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePatternVisitor;
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * <p>
|
---|
| 26 | * TODO comment
|
---|
| 27 | * </p>
|
---|
| 28 | *
|
---|
| 29 | * @author Alexander Deicke
|
---|
| 30 | */
|
---|
| 31 | public 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) {
|
---|
[1152] | 48 | checkTaskAndReturnIfPatternIsPresent(iteration.getMarkedTask());
|
---|
[1150] | 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 |
|
---|
[1152] | 58 | private void checkAllChildrenAndReturnIfPatternIsPresent(ISequence sequence) {
|
---|
| 59 | for (ITask child : sequence.getChildren()) {
|
---|
| 60 | if(checkTaskAndReturnIfPatternIsPresent(child)) {
|
---|
[1161] | 61 | this.present = true;
|
---|
[1150] | 62 | break;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[1152] | 67 | private boolean checkTaskAndReturnIfPatternIsPresent(ITask task) {
|
---|
[1161] | 68 | if(isEvent(task)) return false;
|
---|
| 69 | return this.containedPattern.containedIn(task);
|
---|
[1150] | 70 | }
|
---|
[1152] | 71 |
|
---|
| 72 | private boolean isEvent(ITask task) {
|
---|
| 73 | return task instanceof IEventTask;
|
---|
| 74 | }
|
---|
[1150] | 75 |
|
---|
| 76 | }
|
---|