source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeAndIterationComparisonRule.java @ 1113

Last change on this file since 1113 was 1113, checked in by pharms, 11 years ago
  • added license statement
File size: 3.5 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.tasktrees.nodeequality;
16
17import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
18import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
19
20/**
21 * <p>
22 * This class is capable of comparing any task tree node which is not an iteration with an
23 * iteration. This is needed, because iterations may iterate exactly that node. In this
24 * case, the iteration would be equal to that node if it was executed exactly once. The rule
25 * returns lexically equal, it the child of the iteration is lexically equal to the node
26 * or if the child of the iteration is a selection and this selections contains a lexically equal
27 * node. The same applies for syntactical and semantical equality.
28 * </p>
29
30 * @author Patrick Harms
31 */
32public class NodeAndIterationComparisonRule implements NodeComparisonRule {
33   
34    /** the rule manager for internally comparing task tree nodes */
35    private NodeEqualityRuleManager mRuleManager;
36
37    /**
38     * <p>
39     * simple constructor to provide the rule with the node equality rule manager to be able
40     * to perform comparisons of the children of provided task tree nodes
41     * </p>
42     *
43     * @param ruleManager the rule manager for comparing task tree nodes
44     */
45    NodeAndIterationComparisonRule(NodeEqualityRuleManager ruleManager) {
46        super();
47        mRuleManager = ruleManager;
48    }
49
50    /*
51     * (non-Javadoc)
52     *
53     * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode)
54     */
55    @Override
56    public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {
57        IIteration iteration = null;
58        ITaskTreeNode node = null;
59       
60        if (node1 instanceof IIteration) {
61            if (node2 instanceof IIteration) {
62                // the rule is not responsible for two iterations
63                return null;
64            }
65           
66            iteration = (IIteration) node1;
67            node = node2;
68        }
69        else if (node2 instanceof IIteration) {
70            if (node1 instanceof IIteration) {
71                // the rule is not responsible for two iterations
72                return null;
73            }
74           
75            iteration = (IIteration) node2;
76            node = node1;
77        }
78        else {
79            return null;
80        }
81
82        // now, that we found the iteration and the node, lets compare the child of the iteration
83        // with the node.
84        if (iteration.getChildren().size() < 1) {
85            return null;
86        }
87
88        NodeEquality nodeEquality = mRuleManager.applyRules(iteration.getChildren().get(0), node);
89
90        // although the subtask may be identical to the node, we can not return identical, as
91        // the iteration is not identical to the node, but at most lexically equal
92        if (nodeEquality == NodeEquality.IDENTICAL) {
93            return NodeEquality.LEXICALLY_EQUAL;
94        }
95        else {
96            return nodeEquality;
97        }
98
99    }
100}
Note: See TracBrowser for help on using the repository browser.