[1113] | 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 | |
---|
[922] | 15 | package de.ugoe.cs.autoquest.tasktrees.nodeequality; |
---|
[807] | 16 | |
---|
[922] | 17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
[807] | 19 | |
---|
| 20 | /** |
---|
| 21 | * <p> |
---|
| 22 | * This rule identifies two task tree nodes as lexically equal, if they are both event tasks and |
---|
| 23 | * if their respective event types and targets equal. |
---|
| 24 | * </p> |
---|
| 25 | * |
---|
| 26 | * @author Patrick Harms |
---|
| 27 | */ |
---|
| 28 | public class EventTaskComparisonRule implements NodeComparisonRule { |
---|
| 29 | |
---|
[1125] | 30 | /* (non-Javadoc) |
---|
| 31 | * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) |
---|
[807] | 32 | */ |
---|
| 33 | @Override |
---|
[1125] | 34 | public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
| 35 | return (node1 instanceof IEventTask) && (node2 instanceof IEventTask); |
---|
| 36 | } |
---|
[807] | 37 | |
---|
[1125] | 38 | /* (non-Javadoc) |
---|
| 39 | * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) |
---|
| 40 | */ |
---|
| 41 | @Override |
---|
| 42 | public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
[807] | 43 | IEventTask task1 = (IEventTask) node1; |
---|
| 44 | IEventTask task2 = (IEventTask) node2; |
---|
| 45 | |
---|
[1125] | 46 | return (task1.getEventType().equals(task2.getEventType()) && |
---|
| 47 | task1.getEventTarget().equals(task2.getEventTarget())); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /* (non-Javadoc) |
---|
| 51 | * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) |
---|
| 52 | */ |
---|
| 53 | @Override |
---|
| 54 | public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
| 55 | return areLexicallyEqual(node1, node2); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* (non-Javadoc) |
---|
| 59 | * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) |
---|
| 60 | */ |
---|
| 61 | @Override |
---|
| 62 | public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
| 63 | return areLexicallyEqual(node1, node2); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | @Override |
---|
| 67 | public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
| 68 | if (areLexicallyEqual(node1, node2)) { |
---|
[807] | 69 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 70 | } |
---|
| 71 | else { |
---|
| 72 | return NodeEquality.UNEQUAL; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | } |
---|