source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/GUIEventTaskComparisonRule.java

Last change on this file was 1734, checked in by rkrimmel, 10 years ago

Added automatically created javadoc, still needs to be commented properly though

File size: 24.1 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.taskequality;
16
17import java.util.Collection;
18
19import de.ugoe.cs.autoquest.eventcore.IEventTarget;
20import de.ugoe.cs.autoquest.eventcore.gui.IInteraction;
21import de.ugoe.cs.autoquest.eventcore.gui.KeyInteraction;
22import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed;
23import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased;
24import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped;
25import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonDown;
26import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
27import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonUp;
28import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
29import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick;
30import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop;
31import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
32import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
33import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
34import de.ugoe.cs.autoquest.eventcore.guimodel.IButton;
35import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox;
36import de.ugoe.cs.autoquest.eventcore.guimodel.IComboBox;
37import de.ugoe.cs.autoquest.eventcore.guimodel.IImage;
38import de.ugoe.cs.autoquest.eventcore.guimodel.IListBox;
39import de.ugoe.cs.autoquest.eventcore.guimodel.IMenu;
40import de.ugoe.cs.autoquest.eventcore.guimodel.IMenuButton;
41import de.ugoe.cs.autoquest.eventcore.guimodel.IRadioButton;
42import de.ugoe.cs.autoquest.eventcore.guimodel.IShape;
43import de.ugoe.cs.autoquest.eventcore.guimodel.IText;
44import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip;
45import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
46import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
47import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
48
49// TODO: Auto-generated Javadoc
50/**
51 * <p>
52 * This rule compares GUI event tasks (i.e. it is more concrete, than the
53 * {@link EventTaskComparisonRule}). Two GUI event tasks are only equal if their
54 * event type and target are equal. The returned equality is even more
55 * fine-grained for events whose type is {@link TextInput} and
56 * {@link ValueSelection}. For text inputs, lexical equality is returned if the
57 * same text is entered using the same key interactions. Syntactical equality is
58 * returned if the same text is entered using different key interactions.
59 * Semantical equality is returned if different text is entered, but into the
60 * same event target. Value selections are syntactically equal, if the same
61 * value is selected. Otherwise they are semantically equal.
62 * </p>
63 *
64 * @author Patrick Harms
65 */
66public class GUIEventTaskComparisonRule implements TaskComparisonRule {
67
68        /*
69         * (non-Javadoc)
70         *
71         * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask)
72         */
73        @Override
74        public boolean areLexicallyEqual(ITask task1, ITask task2) {
75                final TaskEquality equality = getEquality(task1, task2,
76                                TaskEquality.LEXICALLY_EQUAL);
77                return (equality != null)
78                                && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL));
79        }
80
81        /*
82         * (non-Javadoc)
83         *
84         * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#
85         * areLexicallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance,
86         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
87         */
88        @Override
89        public boolean areLexicallyEqual(ITaskInstance instance1,
90                        ITaskInstance instance2) {
91                final TaskEquality equality = getEquality(instance1, instance2,
92                                TaskEquality.LEXICALLY_EQUAL);
93                return (equality != null)
94                                && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL));
95        }
96
97        /*
98         * (non-Javadoc)
99         *
100         * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask)
101         */
102        @Override
103        public boolean areSemanticallyEqual(ITask task1, ITask task2) {
104                final TaskEquality equality = getEquality(task1, task2,
105                                TaskEquality.SEMANTICALLY_EQUAL);
106                return (equality != null)
107                                && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL));
108        }
109
110        /*
111         * (non-Javadoc)
112         *
113         * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#
114         * areSemanticallyEqual
115         * (de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance,
116         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
117         */
118        @Override
119        public boolean areSemanticallyEqual(ITaskInstance instance1,
120                        ITaskInstance instance2) {
121                final TaskEquality equality = getEquality(instance1, instance2,
122                                TaskEquality.SEMANTICALLY_EQUAL);
123                return (equality != null)
124                                && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL));
125        }
126
127        /*
128         * (non-Javadoc)
129         *
130         * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask)
131         */
132        @Override
133        public boolean areSyntacticallyEqual(ITask task1, ITask task2) {
134                final TaskEquality equality = getEquality(task1, task2,
135                                TaskEquality.SYNTACTICALLY_EQUAL);
136                return (equality != null)
137                                && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL));
138        }
139
140        /*
141         * (non-Javadoc)
142         *
143         * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#
144         * areSyntacticallyEqual
145         * (de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance,
146         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
147         */
148        @Override
149        public boolean areSyntacticallyEqual(ITaskInstance instance1,
150                        ITaskInstance instance2) {
151                final TaskEquality equality = getEquality(instance1, instance2,
152                                TaskEquality.SYNTACTICALLY_EQUAL);
153                return (equality != null)
154                                && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL));
155        }
156
157        /**
158         * <p>
159         * Checks, if the coordinates of a click or double click on the provided
160         * event target makes a lexical difference. Mouse clicks and double clicks
161         * on buttons, check boxes, combo boxes, images, list boxes, menu buttons,
162         * radio buttons, shapes, uneditable text, and tool tips have no lexical
163         * difference as long as they happen on the same event target. The concrete
164         * coordinates are not relevant.
165         * </p>
166         *
167         * @param eventTarget
168         *            the event target on which the interaction occurred
169         *
170         * @return if the coordinates are important to be considered for clicks and
171         *         double clicks, false else
172         */
173        private boolean clickCoordinatesMakeLexicalDifference(
174                        IEventTarget eventTarget) {
175                if ((eventTarget instanceof IButton)
176                                || (eventTarget instanceof ICheckBox)
177                                || (eventTarget instanceof IComboBox)
178                                || (eventTarget instanceof IImage)
179                                || (eventTarget instanceof IListBox)
180                                || (eventTarget instanceof IMenu)
181                                || (eventTarget instanceof IMenuButton)
182                                || (eventTarget instanceof IRadioButton)
183                                || (eventTarget instanceof IShape)
184                                || (eventTarget instanceof IText)
185                                || (eventTarget instanceof IToolTip)) {
186                        return false;
187                } else {
188                        return true;
189                }
190        }
191
192        /*
193         * (non-Javadoc)
194         *
195         * @see TaskComparisonRule#compare(ITask, ITask)
196         */
197        @Override
198        public TaskEquality compare(ITask task1, ITask task2) {
199                return getEquality(task1, task2, null);
200        }
201
202        /*
203         * (non-Javadoc)
204         *
205         * @see
206         * de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#compare
207         * (de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance,
208         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
209         */
210        @Override
211        public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) {
212                return getEquality(instance1, instance2, null);
213        }
214
215        /**
216         * <p>
217         * compares two interactions. The method delegates to other, more specific
218         * compare method, e.g., {@link #compareTextInputs(TextInput, TextInput)}
219         * and {@link #compareValueSelections(ValueSelection, ValueSelection)}, if
220         * any exist for the concrete interaction types. Otherwise it uses the
221         * equals method of the interactions for comparison. In this case, if the
222         * interactions equals method returns true, this method returns lexical
223         * equality.
224         * </p>
225         * <p>
226         * The provided equality level can be used to restrict the quality check to
227         * the given level. This is done for optimization purposes. The returned
228         * equality level can be at most as concrete as the provided one. If the
229         * provided one is null, it is expected to be lexical equality.
230         * </p>
231         *
232         * @param interaction1
233         *            the first interaction to compare
234         * @param interaction2
235         *            the second interaction to compare
236         * @param eventTarget
237         *            the event target on which the interactions happened (used
238         *            within special comparisons like mouse clicks on buttons, where
239         *            the coordinates can be ignored)
240         * @param equalityLevel
241         *            the equality level to be checked for
242         *
243         * @return as described
244         */
245        private TaskEquality compareInteractions(IInteraction interaction1,
246                        IInteraction interaction2, IEventTarget eventTarget,
247                        TaskEquality equalityLevel) {
248                TaskEquality level = equalityLevel;
249
250                if (level == null) {
251                        level = TaskEquality.LEXICALLY_EQUAL;
252                }
253
254                if (interaction1 == interaction2) {
255                        return TaskEquality.LEXICALLY_EQUAL;
256                } else if ((interaction1 instanceof KeyInteraction)
257                                && (interaction2 instanceof KeyInteraction)) {
258                        return compareKeyInteractions((KeyInteraction) interaction1,
259                                        (KeyInteraction) interaction2, level);
260                } else if ((interaction1 instanceof MouseButtonInteraction)
261                                && (interaction2 instanceof MouseButtonInteraction)) {
262                        return compareMouseButtonInteractions(
263                                        (MouseButtonInteraction) interaction1,
264                                        (MouseButtonInteraction) interaction2, eventTarget, level);
265                } else if ((interaction1 instanceof Scroll)
266                                && (interaction2 instanceof Scroll)) {
267                        return compareScrolls((Scroll) interaction1, (Scroll) interaction2,
268                                        level);
269                } else if ((interaction1 instanceof TextInput)
270                                && (interaction2 instanceof TextInput)) {
271                        return compareTextInputs((TextInput) interaction1,
272                                        (TextInput) interaction2, level);
273                } else if ((interaction1 instanceof ValueSelection)
274                                && (interaction2 instanceof ValueSelection)) {
275                        return compareValueSelections((ValueSelection<?>) interaction1,
276                                        (ValueSelection<?>) interaction2, level);
277                } else if (interaction1.equals(interaction2)) {
278                        return TaskEquality.LEXICALLY_EQUAL;
279                } else {
280                        return TaskEquality.UNEQUAL;
281                }
282        }
283
284        /**
285         * <p>
286         * compares two key interactions. If both are of the same type and if both
287         * have the same key, they are lexically equal. If both are only of the same
288         * type, they are semantically equal. Otherwise, they are unequal.
289         * </p>
290         * <p>
291         * The provided equality level can be used to restrict the quality check to
292         * the given level. This is done for optimization purposes. The returned
293         * equality level is as concrete as the provided one. It may be more
294         * concrete if there is no difference regarding the comparison on the
295         * levels.
296         * </p>
297         *
298         * @param interaction1
299         *            the first key interaction
300         * @param interaction2
301         *            the second key interaction
302         * @param equalityLevel
303         *            the equality level to be checked for
304         *
305         * @return as described
306         */
307        private TaskEquality compareKeyInteractions(KeyInteraction interaction1,
308                        KeyInteraction interaction2, TaskEquality equalityLevel) {
309                if (((interaction1 instanceof KeyPressed) && (interaction2 instanceof KeyPressed))
310                                || ((interaction1 instanceof KeyReleased) && (interaction2 instanceof KeyReleased))
311                                || ((interaction1 instanceof KeyTyped) && (interaction2 instanceof KeyTyped))) {
312                        if ((equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL))
313                                        && (interaction1.getKey() == interaction2.getKey())) {
314                                return TaskEquality.LEXICALLY_EQUAL;
315                        } else {
316                                return TaskEquality.SEMANTICALLY_EQUAL;
317                        }
318                }
319
320                return TaskEquality.UNEQUAL;
321        }
322
323        /**
324         * <p>
325         * compares two mouse button interactions such as clicks, mouse button down,
326         * or double clicks. If both interactions have the same coordinates, they
327         * are lexically equal. Otherwise, they are semantically equal. Mouse clicks
328         * for which the coordinates make no lexical difference (see
329         * {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated
330         * as lexically equal.
331         * </p>
332         * <p>
333         * The provided equality level can be used to restrict the quality check to
334         * the given level. This is done for optimization purposes. The returned
335         * equality level is as concrete as the provided one. It may be more
336         * concrete if there is no difference regarding the comparison on the
337         * levels.
338         * </p>
339         *
340         * @param interaction1
341         *            the first mouse button interaction to compare
342         * @param interaction2
343         *            the second mouse button interaction to compare
344         * @param eventTarget
345         *            the event target on which the interactions happened (used
346         *            within special comparisons like mouse clicks on buttons, where
347         *            the coordinates can be ignored)
348         * @param equalityLevel
349         *            the equality level to be checked for
350         *
351         * @return as described
352         */
353        private TaskEquality compareMouseButtonInteractions(
354                        MouseButtonInteraction interaction1,
355                        MouseButtonInteraction interaction2, IEventTarget eventTarget,
356                        TaskEquality equalityLevel) {
357                boolean coordinatesMatch = true;
358
359                if ((interaction1 instanceof MouseDragAndDrop)
360                                && (interaction2 instanceof MouseDragAndDrop)) {
361                        return compareMouseDragAndDrops((MouseDragAndDrop) interaction1,
362                                        (MouseDragAndDrop) interaction2, equalityLevel);
363                } else if (interaction1.getButton() != interaction2.getButton()) {
364                        return TaskEquality.UNEQUAL;
365                } else if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)
366                                && clickCoordinatesMakeLexicalDifference(eventTarget)) {
367                        final int x1 = interaction1.getX();
368                        final int x2 = interaction2.getX();
369                        final int y1 = interaction1.getY();
370                        final int y2 = interaction2.getY();
371
372                        if ((x1 != x2) || (y1 != y2)) {
373                                coordinatesMatch = false;
374                        }
375                }
376
377                // up to now, they can be equal. Now check the types. Do it as last
378                // action as these
379                // checks take the most time and should, therefore, only be done latest
380                if (((interaction1 instanceof MouseClick) && (interaction2 instanceof MouseClick))
381                                || ((interaction1 instanceof MouseDoubleClick) && (interaction2 instanceof MouseDoubleClick))
382                                || ((interaction1 instanceof MouseButtonDown) && (interaction2 instanceof MouseButtonDown))
383                                || ((interaction1 instanceof MouseButtonUp) && (interaction2 instanceof MouseButtonUp))) {
384                        if (coordinatesMatch) {
385                                return TaskEquality.LEXICALLY_EQUAL;
386                        } else {
387                                return TaskEquality.SEMANTICALLY_EQUAL;
388                        }
389                }
390
391                return TaskEquality.UNEQUAL;
392        }
393
394        /**
395         * <p>
396         * compares two mouse drag and drops. If both drag and drops have the same
397         * start and end coordinates, they are lexically equal. Otherwise, they are
398         * semantically equal.
399         * </p>
400         * <p>
401         * The provided equality level can be used to restrict the quality check to
402         * the given level. This is done for optimization purposes. The returned
403         * equality level is as concrete as the provided one. It may be more
404         * concrete if there is no difference regarding the comparison on the
405         * levels.
406         * </p>
407         *
408         * @param interaction1
409         *            the first mouse drag and drop to compare
410         * @param interaction2
411         *            the second mouse drag and drop to compare
412         * @param equalityLevel
413         *            the equality level to be checked for
414         *
415         * @return as described
416         */
417        private TaskEquality compareMouseDragAndDrops(
418                        MouseDragAndDrop interaction1, MouseDragAndDrop interaction2,
419                        TaskEquality equalityLevel) {
420                if (interaction1.getButton() != interaction2.getButton()) {
421                        return TaskEquality.UNEQUAL;
422                }
423
424                if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
425                        final int x1 = interaction1.getX();
426                        final int x1Start = interaction1.getXStart();
427                        final int x2 = interaction2.getX();
428                        final int x2Start = interaction2.getXStart();
429                        final int y1 = interaction1.getY();
430                        final int y1Start = interaction1.getYStart();
431                        final int y2 = interaction2.getY();
432                        final int y2Start = interaction2.getYStart();
433
434                        if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start)
435                                        && (y1 == y2)) {
436                                return TaskEquality.LEXICALLY_EQUAL;
437                        }
438                }
439
440                return TaskEquality.SEMANTICALLY_EQUAL;
441        }
442
443        /**
444         * <p>
445         * compares two mouse button interactions such as clicks, mouse button down,
446         * or double clicks. If both interactions have the same coordinates, they
447         * are lexically equal. Otherwise, they are semantically equal. Mouse clicks
448         * for which the coordinates make no lexical difference (see
449         * {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated
450         * as lexically equal.
451         * </p>
452         * <p>
453         * The provided equality level can be used to restrict the quality check to
454         * the given level. This is done for optimization purposes. The returned
455         * equality level is as concrete as the provided one. It may be more
456         * concrete if there is no difference regarding the comparison on the
457         * levels.
458         * </p>
459         *
460         * @param interaction1            the first mouse button interaction to compare
461         * @param interaction2            the second mouse button interaction to compare
462         * @param equalityLevel            the equality level to be checked for
463         * @return as described
464         */
465        private TaskEquality compareScrolls(Scroll interaction1,
466                        Scroll interaction2, TaskEquality equalityLevel) {
467                if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
468                        final int x1 = interaction1.getXPosition();
469                        final int x2 = interaction2.getXPosition();
470                        final int y1 = interaction1.getYPosition();
471                        final int y2 = interaction2.getYPosition();
472
473                        if ((x1 == x2) && (y1 == y2)) {
474                                return TaskEquality.LEXICALLY_EQUAL;
475                        }
476                }
477
478                return TaskEquality.SEMANTICALLY_EQUAL;
479        }
480
481        /**
482         * <p>
483         * compares two text inputs. If both text inputs have the same entered text
484         * and text input events, they are lexically equal. If they only have the
485         * same entered text, they are syntactically equal. If they are only both
486         * text inputs, they are semantically equal. (the equality of the event
487         * targets is checked beforehand).
488         * </p>
489         * <p>
490         * The provided equality level can be used to restrict the quality check to
491         * the given level. This is done for optimization purposes. The returned
492         * equality level is as concrete as the provided one. It may be more
493         * concrete if there is no difference regarding the comparison on the
494         * levels.
495         * </p>
496         *
497         * @param interaction1
498         *            the first text input to compare
499         * @param interaction2
500         *            the second text input to compare
501         * @param equalityLevel
502         *            the equality level to be checked for
503         *
504         * @return as described
505         */
506        private TaskEquality compareTextInputs(TextInput interaction1,
507                        TextInput interaction2, TaskEquality equalityLevel) {
508                switch (equalityLevel) {
509                case LEXICALLY_EQUAL:
510                        if (interaction1.getTextInputEvents().equals(
511                                        interaction2.getTextInputEvents())) {
512                                return TaskEquality.LEXICALLY_EQUAL;
513                        }
514                        // fall through
515                case SYNTACTICALLY_EQUAL:
516                        if (interaction1.getEnteredText().equals(
517                                        interaction2.getEnteredText())) {
518                                return TaskEquality.SYNTACTICALLY_EQUAL;
519                        }
520                        // fall through
521                case SEMANTICALLY_EQUAL:
522                        return TaskEquality.SEMANTICALLY_EQUAL;
523                default:
524                        return TaskEquality.UNEQUAL;
525                }
526        }
527
528        /**
529         * <p>
530         * compares two value selections. If both value selections have the same
531         * selected value, they are syntactically equal, otherwise they are
532         * semantically equal. (the equality of the event targets is checked
533         * beforehand).
534         * </p>
535         * <p>
536         * The provided equality level can be used to restrict the quality check to
537         * the given level. This is done for optimization purposes. The returned
538         * equality level is as concrete as the provided one. It may be more
539         * concrete if there is no difference regarding the comparison on the
540         * levels.
541         * </p>
542         *
543         * @param interaction1
544         *            the first value selection to compare
545         * @param interaction2
546         *            the second value selection to compare
547         * @param equalityLevel
548         *            the equality level to be checked for
549         *
550         * @return as described
551         */
552        private TaskEquality compareValueSelections(ValueSelection<?> interaction1,
553                        ValueSelection<?> interaction2, TaskEquality equalityLevel) {
554                if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
555                        final Object value1 = interaction1.getSelectedValue();
556                        final Object value2 = interaction2.getSelectedValue();
557
558                        if ((value1 == value2)
559                                        || ((value1 != null) && (value1.equals(value2)))) {
560                                return TaskEquality.LEXICALLY_EQUAL;
561                        }
562                }
563
564                return TaskEquality.SEMANTICALLY_EQUAL;
565        }
566
567        /**
568         * Gets the equality.
569         *
570         * @param task1 the task1
571         * @param task2 the task2
572         * @param requiredEqualityLevel the required equality level
573         * @return the equality
574         */
575        private TaskEquality getEquality(ITask task1, ITask task2,
576                        TaskEquality requiredEqualityLevel) {
577                final Collection<ITaskInstance> taskInstances1 = task1.getInstances();
578                final Collection<ITaskInstance> taskInstances2 = task2.getInstances();
579
580                final TaskEquality checkedEquality = requiredEqualityLevel != null ? requiredEqualityLevel
581                                : TaskEquality.SEMANTICALLY_EQUAL;
582
583                TaskEquality commonDenominator = TaskEquality.LEXICALLY_EQUAL;
584
585                for (final ITaskInstance instance1 : taskInstances1) {
586                        TaskEquality mostConcreteEquality = null;
587
588                        for (final ITaskInstance instance2 : taskInstances2) {
589                                final TaskEquality equality = getEquality(instance1, instance2,
590                                                requiredEqualityLevel);
591
592                                if ((equality != null)
593                                                && ((mostConcreteEquality == null) || (equality
594                                                                .isAtLeast(mostConcreteEquality)))) {
595                                        mostConcreteEquality = equality;
596
597                                        if (((requiredEqualityLevel != null) && (mostConcreteEquality
598                                                        .isAtLeast(requiredEqualityLevel)))
599                                                        || (mostConcreteEquality
600                                                                        .isAtLeast(TaskEquality.LEXICALLY_EQUAL))) {
601                                                break;
602                                        }
603                                }
604                        }
605
606                        commonDenominator = commonDenominator
607                                        .getCommonDenominator(mostConcreteEquality);
608
609                        if (!commonDenominator.isAtLeast(checkedEquality)) {
610                                return TaskEquality.UNEQUAL;
611                        }
612                }
613
614                return commonDenominator;
615        }
616
617        /**
618         * Gets the equality.
619         *
620         * @param instance1 the instance1
621         * @param instance2 the instance2
622         * @param requiredEqualityLevel the required equality level
623         * @return the equality
624         */
625        private TaskEquality getEquality(ITaskInstance instance1,
626                        ITaskInstance instance2, TaskEquality requiredEqualityLevel) {
627                final IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1;
628                final IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2;
629
630                if (!eventTask1.getEvent().getTarget()
631                                .equals(eventTask2.getEvent().getTarget())) {
632                        return TaskEquality.UNEQUAL;
633                }
634
635                final IInteraction interaction1 = (IInteraction) eventTask1.getEvent()
636                                .getType();
637                final IInteraction interaction2 = (IInteraction) eventTask2.getEvent()
638                                .getType();
639
640                return compareInteractions(interaction1, interaction2, eventTask1
641                                .getEvent().getTarget(), requiredEqualityLevel);
642        }
643
644        /*
645         * (non-Javadoc)
646         *
647         * @see TaskComparisonRule#isApplicable(ITask, ITask)
648         */
649        @Override
650        public boolean isApplicable(ITask task1, ITask task2) {
651                for (final ITaskInstance instance : task1.getInstances()) {
652                        if ((!(instance instanceof IEventTaskInstance))
653                                        || (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) {
654                                return false;
655                        }
656                }
657
658                for (final ITaskInstance instance : task2.getInstances()) {
659                        if ((!(instance instanceof IEventTaskInstance))
660                                        || (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) {
661                                return false;
662                        }
663                }
664
665                return true;
666        }
667
668        /*
669         * (non-Javadoc)
670         *
671         * @see
672         * de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#isApplicable
673         * (de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance,
674         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
675         */
676        @Override
677        public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) {
678                return (instance1 instanceof IEventTaskInstance)
679                                && (instance2 instanceof IEventTaskInstance)
680                                && (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction)
681                                && (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction);
682        }
683
684}
Note: See TracBrowser for help on using the repository browser.