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.tasktrees.nodeequality; |
---|
16 | |
---|
17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
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 | |
---|
30 | /* |
---|
31 | * (non-Javadoc) |
---|
32 | * |
---|
33 | * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) |
---|
34 | */ |
---|
35 | @Override |
---|
36 | public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
37 | if ((!(node1 instanceof IEventTask)) || (!(node2 instanceof IEventTask))) { |
---|
38 | return null; |
---|
39 | } |
---|
40 | |
---|
41 | if (node1 == node2) { |
---|
42 | return NodeEquality.IDENTICAL; |
---|
43 | } |
---|
44 | |
---|
45 | IEventTask task1 = (IEventTask) node1; |
---|
46 | IEventTask task2 = (IEventTask) node2; |
---|
47 | |
---|
48 | if (task1.getEventType().equals(task2.getEventType()) && |
---|
49 | task1.getEventTarget().equals(task2.getEventTarget())) |
---|
50 | { |
---|
51 | return NodeEquality.LEXICALLY_EQUAL; |
---|
52 | } |
---|
53 | else { |
---|
54 | return NodeEquality.UNEQUAL; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | } |
---|