[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 | |
---|
[1146] | 15 | package de.ugoe.cs.autoquest.tasktrees.taskequality; |
---|
[807] | 16 | |
---|
[1294] | 17 | import java.util.Collection; |
---|
| 18 | |
---|
[922] | 19 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
[1294] | 20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1146] | 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
[1294] | 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
[807] | 23 | |
---|
| 24 | /** |
---|
| 25 | * <p> |
---|
[1146] | 26 | * This rule identifies two tasks as lexically equal, if they are both event tasks and |
---|
[807] | 27 | * if their respective event types and targets equal. |
---|
| 28 | * </p> |
---|
| 29 | * |
---|
| 30 | * @author Patrick Harms |
---|
| 31 | */ |
---|
[1146] | 32 | public class EventTaskComparisonRule implements TaskComparisonRule { |
---|
[807] | 33 | |
---|
[1125] | 34 | /* (non-Javadoc) |
---|
[1294] | 35 | * @see TaskComparisonRule#isApplicable(ITask, ITask) |
---|
[807] | 36 | */ |
---|
| 37 | @Override |
---|
[1146] | 38 | public boolean isApplicable(ITask task1, ITask task2) { |
---|
| 39 | return (task1 instanceof IEventTask) && (task2 instanceof IEventTask); |
---|
[1125] | 40 | } |
---|
[807] | 41 | |
---|
[1125] | 42 | /* (non-Javadoc) |
---|
[1294] | 43 | * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) |
---|
[1125] | 44 | */ |
---|
| 45 | @Override |
---|
[1146] | 46 | public boolean areLexicallyEqual(ITask task1, ITask task2) { |
---|
[1294] | 47 | Collection<ITaskInstance> taskInstances1 = task1.getInstances(); |
---|
| 48 | Collection<ITaskInstance> taskInstances2 = task2.getInstances(); |
---|
[807] | 49 | |
---|
[1294] | 50 | for (ITaskInstance instance1 : taskInstances1) { |
---|
| 51 | boolean found = false; |
---|
| 52 | |
---|
| 53 | for (ITaskInstance instance2 : taskInstances2) { |
---|
| 54 | if (areLexicallyEqual(instance1, instance2)) { |
---|
| 55 | found = true; |
---|
| 56 | break; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if (!found) { |
---|
| 61 | return false; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | return true; |
---|
[1125] | 66 | } |
---|
| 67 | |
---|
| 68 | /* (non-Javadoc) |
---|
[1294] | 69 | * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) |
---|
[1125] | 70 | */ |
---|
| 71 | @Override |
---|
[1146] | 72 | public boolean areSyntacticallyEqual(ITask task1, ITask task2) { |
---|
| 73 | return areLexicallyEqual(task1, task2); |
---|
[1125] | 74 | } |
---|
| 75 | |
---|
| 76 | /* (non-Javadoc) |
---|
[1294] | 77 | * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) |
---|
[1125] | 78 | */ |
---|
| 79 | @Override |
---|
[1146] | 80 | public boolean areSemanticallyEqual(ITask task1, ITask task2) { |
---|
| 81 | return areLexicallyEqual(task1, task2); |
---|
[1125] | 82 | } |
---|
| 83 | |
---|
[1294] | 84 | /* (non-Javadoc) |
---|
| 85 | * @see TaskComparisonRule#compare(ITask, ITask) |
---|
| 86 | */ |
---|
[1125] | 87 | @Override |
---|
[1146] | 88 | public TaskEquality compare(ITask task1, ITask task2) { |
---|
| 89 | if (areLexicallyEqual(task1, task2)) { |
---|
| 90 | return TaskEquality.LEXICALLY_EQUAL; |
---|
[807] | 91 | } |
---|
| 92 | else { |
---|
[1146] | 93 | return TaskEquality.UNEQUAL; |
---|
[807] | 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
[1294] | 97 | |
---|
| 98 | /* (non-Javadoc) |
---|
| 99 | * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) |
---|
| 100 | */ |
---|
| 101 | @Override |
---|
| 102 | public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 103 | return |
---|
| 104 | (instance1 instanceof IEventTaskInstance) && (instance2 instanceof IEventTaskInstance); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | /* (non-Javadoc) |
---|
| 108 | * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) |
---|
| 109 | */ |
---|
| 110 | @Override |
---|
| 111 | public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 112 | IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1; |
---|
| 113 | IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2; |
---|
| 114 | |
---|
| 115 | return (eventTask1.getEvent().getType().equals(eventTask2.getEvent().getType()) && |
---|
| 116 | eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /* (non-Javadoc) |
---|
| 120 | * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) |
---|
| 121 | */ |
---|
| 122 | @Override |
---|
| 123 | public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 124 | return areLexicallyEqual(instance1, instance2); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /* (non-Javadoc) |
---|
| 128 | * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) |
---|
| 129 | */ |
---|
| 130 | @Override |
---|
| 131 | public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 132 | return areLexicallyEqual(instance1, instance2); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /* (non-Javadoc) |
---|
| 136 | * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) |
---|
| 137 | */ |
---|
| 138 | @Override |
---|
| 139 | public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 140 | if (areLexicallyEqual(instance1, instance2)) { |
---|
| 141 | return TaskEquality.LEXICALLY_EQUAL; |
---|
| 142 | } |
---|
| 143 | else { |
---|
| 144 | return TaskEquality.UNEQUAL; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
[807] | 148 | } |
---|