[2161] | 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 java.util.Collection; |
---|
| 18 | |
---|
| 19 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
| 20 | import de.ugoe.cs.autoquest.eventcore.gui.Scroll; |
---|
| 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
| 23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * <p> |
---|
| 28 | * TODO comment |
---|
| 29 | * </p> |
---|
| 30 | * |
---|
| 31 | * @author Patrick Harms |
---|
| 32 | */ |
---|
| 33 | public class InefficientActionsComparisonRule implements TaskComparisonRule { |
---|
| 34 | |
---|
| 35 | /* (non-Javadoc) |
---|
| 36 | * @see TaskComparisonRule#isApplicable(ITask, ITask) |
---|
| 37 | */ |
---|
| 38 | @Override |
---|
| 39 | public boolean isApplicable(ITask task1, ITask task2) { |
---|
| 40 | if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) { |
---|
| 41 | IEventTaskInstance instance1 = |
---|
| 42 | (IEventTaskInstance) task1.getInstances().iterator().next(); |
---|
| 43 | |
---|
| 44 | IEventTaskInstance instance2 = |
---|
| 45 | (IEventTaskInstance) task2.getInstances().iterator().next(); |
---|
| 46 | |
---|
| 47 | return isApplicable(instance1, instance2); |
---|
| 48 | } |
---|
| 49 | else { |
---|
| 50 | return false; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /* (non-Javadoc) |
---|
| 55 | * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) |
---|
| 56 | */ |
---|
| 57 | @Override |
---|
| 58 | public boolean areLexicallyEqual(ITask task1, ITask task2) { |
---|
| 59 | Collection<ITaskInstance> taskInstances1 = task1.getInstances(); |
---|
| 60 | Collection<ITaskInstance> taskInstances2 = task2.getInstances(); |
---|
| 61 | |
---|
| 62 | for (ITaskInstance instance1 : taskInstances1) { |
---|
| 63 | boolean found = false; |
---|
| 64 | |
---|
| 65 | for (ITaskInstance instance2 : taskInstances2) { |
---|
| 66 | if (areLexicallyEqual(instance1, instance2)) { |
---|
| 67 | found = true; |
---|
| 68 | break; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (!found) { |
---|
| 73 | return false; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | return true; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /* (non-Javadoc) |
---|
| 81 | * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) |
---|
| 82 | */ |
---|
| 83 | @Override |
---|
| 84 | public boolean areSyntacticallyEqual(ITask task1, ITask task2) { |
---|
| 85 | return areLexicallyEqual(task1, task2); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /* (non-Javadoc) |
---|
| 89 | * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) |
---|
| 90 | */ |
---|
| 91 | @Override |
---|
| 92 | public boolean areSemanticallyEqual(ITask task1, ITask task2) { |
---|
| 93 | return areLexicallyEqual(task1, task2); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /* (non-Javadoc) |
---|
| 97 | * @see TaskComparisonRule#compare(ITask, ITask) |
---|
| 98 | */ |
---|
| 99 | @Override |
---|
| 100 | public TaskEquality compare(ITask task1, ITask task2) { |
---|
| 101 | if (areLexicallyEqual(task1, task2)) { |
---|
| 102 | return TaskEquality.LEXICALLY_EQUAL; |
---|
| 103 | } |
---|
| 104 | else { |
---|
| 105 | return TaskEquality.UNEQUAL; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | /* (non-Javadoc) |
---|
| 111 | * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) |
---|
| 112 | */ |
---|
| 113 | @Override |
---|
| 114 | public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 115 | return |
---|
| 116 | (instance1 instanceof IEventTaskInstance) && |
---|
| 117 | (instance2 instanceof IEventTaskInstance) && |
---|
| 118 | (isInefficientAction(((IEventTaskInstance) instance1).getEvent())) && |
---|
| 119 | (isInefficientAction(((IEventTaskInstance) instance2).getEvent())); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /* (non-Javadoc) |
---|
| 123 | * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) |
---|
| 124 | */ |
---|
| 125 | @Override |
---|
| 126 | public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 127 | return |
---|
| 128 | (isInefficientAction(((IEventTaskInstance) instance1).getEvent())) && |
---|
| 129 | (isInefficientAction(((IEventTaskInstance) instance2).getEvent())); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /* (non-Javadoc) |
---|
| 133 | * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) |
---|
| 134 | */ |
---|
| 135 | @Override |
---|
| 136 | public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 137 | return areLexicallyEqual(instance1, instance2); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /* (non-Javadoc) |
---|
| 141 | * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) |
---|
| 142 | */ |
---|
| 143 | @Override |
---|
| 144 | public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 145 | return areLexicallyEqual(instance1, instance2); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /* (non-Javadoc) |
---|
| 149 | * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) |
---|
| 150 | */ |
---|
| 151 | @Override |
---|
| 152 | public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { |
---|
| 153 | if (areLexicallyEqual(instance1, instance2)) { |
---|
| 154 | return TaskEquality.LEXICALLY_EQUAL; |
---|
| 155 | } |
---|
| 156 | else { |
---|
| 157 | return TaskEquality.UNEQUAL; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | * <p> |
---|
| 163 | * TODO: comment |
---|
| 164 | * </p> |
---|
| 165 | * |
---|
| 166 | * @param event |
---|
| 167 | * @return |
---|
| 168 | */ |
---|
| 169 | private boolean isInefficientAction(Event event) { |
---|
| 170 | return (event.getType() instanceof Scroll) || |
---|
| 171 | ("headRotated".equals(event.getType().toString())) || |
---|
| 172 | ("headMoved".equals(event.getType().toString())); |
---|
| 173 | } |
---|
| 174 | } |
---|