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

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

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

File size: 4.4 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.tasktrees.treeifc.IEventTask;
20import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
23
24// TODO: Auto-generated Javadoc
25/**
26 * <p>
27 * This rule identifies two tasks as lexically equal, if they are both event
28 * tasks and if their respective event types and targets equal.
29 * </p>
30 *
31 * @author Patrick Harms
32 */
33public class EventTaskComparisonRule implements TaskComparisonRule {
34
35        /*
36         * (non-Javadoc)
37         *
38         * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask)
39         */
40        @Override
41        public boolean areLexicallyEqual(ITask task1, ITask task2) {
42                final Collection<ITaskInstance> taskInstances1 = task1.getInstances();
43                final Collection<ITaskInstance> taskInstances2 = task2.getInstances();
44
45                for (final ITaskInstance instance1 : taskInstances1) {
46                        boolean found = false;
47
48                        for (final ITaskInstance instance2 : taskInstances2) {
49                                if (areLexicallyEqual(instance1, instance2)) {
50                                        found = true;
51                                        break;
52                                }
53                        }
54
55                        if (!found) {
56                                return false;
57                        }
58                }
59
60                return true;
61        }
62
63        /*
64         * (non-Javadoc)
65         *
66         * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance)
67         */
68        @Override
69        public boolean areLexicallyEqual(ITaskInstance instance1,
70                        ITaskInstance instance2) {
71                final IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1;
72                final IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2;
73
74                return (eventTask1.getEvent().getType()
75                                .equals(eventTask2.getEvent().getType()) && eventTask1
76                                .getEvent().getTarget()
77                                .equals(eventTask2.getEvent().getTarget()));
78        }
79
80        /*
81         * (non-Javadoc)
82         *
83         * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask)
84         */
85        @Override
86        public boolean areSemanticallyEqual(ITask task1, ITask task2) {
87                return areLexicallyEqual(task1, task2);
88        }
89
90        /*
91         * (non-Javadoc)
92         *
93         * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance,
94         * ITaskInstance)
95         */
96        @Override
97        public boolean areSemanticallyEqual(ITaskInstance instance1,
98                        ITaskInstance instance2) {
99                return areLexicallyEqual(instance1, instance2);
100        }
101
102        /*
103         * (non-Javadoc)
104         *
105         * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask)
106         */
107        @Override
108        public boolean areSyntacticallyEqual(ITask task1, ITask task2) {
109                return areLexicallyEqual(task1, task2);
110        }
111
112        /*
113         * (non-Javadoc)
114         *
115         * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance,
116         * ITaskInstance)
117         */
118        @Override
119        public boolean areSyntacticallyEqual(ITaskInstance instance1,
120                        ITaskInstance instance2) {
121                return areLexicallyEqual(instance1, instance2);
122        }
123
124        /*
125         * (non-Javadoc)
126         *
127         * @see TaskComparisonRule#compare(ITask, ITask)
128         */
129        @Override
130        public TaskEquality compare(ITask task1, ITask task2) {
131                if (areLexicallyEqual(task1, task2)) {
132                        return TaskEquality.LEXICALLY_EQUAL;
133                } else {
134                        return TaskEquality.UNEQUAL;
135                }
136        }
137
138        /*
139         * (non-Javadoc)
140         *
141         * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance)
142         */
143        @Override
144        public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) {
145                if (areLexicallyEqual(instance1, instance2)) {
146                        return TaskEquality.LEXICALLY_EQUAL;
147                } else {
148                        return TaskEquality.UNEQUAL;
149                }
150        }
151
152        /*
153         * (non-Javadoc)
154         *
155         * @see TaskComparisonRule#isApplicable(ITask, ITask)
156         */
157        @Override
158        public boolean isApplicable(ITask task1, ITask task2) {
159                return (task1 instanceof IEventTask) && (task2 instanceof IEventTask);
160        }
161
162        /*
163         * (non-Javadoc)
164         *
165         * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance)
166         */
167        @Override
168        public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) {
169                return (instance1 instanceof IEventTaskInstance)
170                                && (instance2 instanceof IEventTaskInstance);
171        }
172
173}
Note: See TracBrowser for help on using the repository browser.