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.taskequality; |
---|
16 | |
---|
17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
19 | |
---|
20 | /** |
---|
21 | * <p> |
---|
22 | * This rule identifies two tasks 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 TaskComparisonRule { |
---|
29 | |
---|
30 | /* (non-Javadoc) |
---|
31 | * @see NodeComparisonRule#isApplicable(ITask, ITask) |
---|
32 | */ |
---|
33 | @Override |
---|
34 | public boolean isApplicable(ITask task1, ITask task2) { |
---|
35 | return (task1 instanceof IEventTask) && (task2 instanceof IEventTask); |
---|
36 | } |
---|
37 | |
---|
38 | /* (non-Javadoc) |
---|
39 | * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) |
---|
40 | */ |
---|
41 | @Override |
---|
42 | public boolean areLexicallyEqual(ITask task1, ITask task2) { |
---|
43 | IEventTask eventTask1 = (IEventTask) task1; |
---|
44 | IEventTask eventTask2 = (IEventTask) task2; |
---|
45 | |
---|
46 | return (eventTask1.getEventType().equals(eventTask2.getEventType()) && |
---|
47 | eventTask1.getEventTarget().equals(eventTask2.getEventTarget())); |
---|
48 | } |
---|
49 | |
---|
50 | /* (non-Javadoc) |
---|
51 | * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) |
---|
52 | */ |
---|
53 | @Override |
---|
54 | public boolean areSyntacticallyEqual(ITask task1, ITask task2) { |
---|
55 | return areLexicallyEqual(task1, task2); |
---|
56 | } |
---|
57 | |
---|
58 | /* (non-Javadoc) |
---|
59 | * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) |
---|
60 | */ |
---|
61 | @Override |
---|
62 | public boolean areSemanticallyEqual(ITask task1, ITask task2) { |
---|
63 | return areLexicallyEqual(task1, task2); |
---|
64 | } |
---|
65 | |
---|
66 | @Override |
---|
67 | public TaskEquality compare(ITask task1, ITask task2) { |
---|
68 | if (areLexicallyEqual(task1, task2)) { |
---|
69 | return TaskEquality.LEXICALLY_EQUAL; |
---|
70 | } |
---|
71 | else { |
---|
72 | return TaskEquality.UNEQUAL; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | } |
---|