Changeset 557
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 5 deleted
- 31 edited
- 24 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManagerTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.manager; … … 15 13 import org.junit.Test; 16 14 17 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;18 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;19 import de.ugoe.cs.quest.eventcore. userinteraction.InteractionEvent;15 import de.ugoe.cs.quest.eventcore.Event; 16 import de.ugoe.cs.quest.eventcore.IEventTarget; 17 import de.ugoe.cs.quest.eventcore.IEventType; 20 18 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 21 19 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; … … 23 21 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 24 22 25 //-------------------------------------------------------------------------------------------------26 23 /** 27 24 * TODO comment 28 * 25 * 29 26 * @version $Revision: $ $Date: $ 30 * @author 27 * @author 2011, last modified by $Author: $ 31 28 */ 32 //------------------------------------------------------------------------------------------------- 33 34 public class TaskTreeManagerTest 35 { 36 /** */ 37 TaskTreeManager mManager; 38 39 //----------------------------------------------------------------------------------------------- 40 /** 41 * 42 */ 43 //----------------------------------------------------------------------------------------------- 44 @Before 45 public void setUp() 46 { 47 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 29 public class TaskTreeManagerTest { 48 30 49 mManager = new TaskTreeManager(); 50 } 51 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * 55 */ 56 //----------------------------------------------------------------------------------------------- 57 @After 58 public void tearDown() 59 { 60 mManager = null; 61 ComponentManager.clearInstance(); 62 } 63 64 //----------------------------------------------------------------------------------------------- 65 /** 66 * 67 */ 68 //----------------------------------------------------------------------------------------------- 69 @Test 70 public void testOneInteractionOnOneElement() 71 { 72 simulateInteraction(new DummyGUIElement("elem1"), new DummyInteraction("bla", 1)); 73 new TaskTreeChecker().assertTaskTree 74 ("Sequence sequence {" + 75 " Interaction bla {}" + 76 "}", mManager.getTaskTree()); 77 } 78 79 //----------------------------------------------------------------------------------------------- 80 /** 81 * 82 */ 83 //----------------------------------------------------------------------------------------------- 84 @Test 85 public void testManyInteractionsOnOneElement() 86 { 87 GUIElement element = new DummyGUIElement("elem1"); 88 simulateInteraction(element, new DummyInteraction("bla", 1)); 89 simulateInteraction(element, new DummyInteraction("bli", 1)); 90 simulateInteraction(element, new DummyInteraction("blo", 1)); 91 simulateInteraction(element, new DummyInteraction("blu", 1)); 92 simulateInteraction(element, new DummyInteraction("bla", 1)); 93 94 new TaskTreeChecker().assertTaskTree 95 ("Sequence sequence {" + 96 " Interaction bla {}" + 97 " Interaction bli {}" + 98 " Interaction blo {}" + 99 " Interaction blu {}" + 100 " Interaction bla {}" + 101 "}", mManager.getTaskTree()); 102 } 103 104 //----------------------------------------------------------------------------------------------- 105 /** 106 * 107 */ 108 //----------------------------------------------------------------------------------------------- 109 @Test 110 public void testOneInteractionOnManyElements() 111 { 112 GUIElement element1 = new DummyGUIElement("elem1"); 113 GUIElement element2 = new DummyGUIElement("elem2"); 114 GUIElement element3 = new DummyGUIElement("elem3"); 115 GUIElement element4 = new DummyGUIElement("elem4"); 116 GUIElement element5 = new DummyGUIElement("elem5"); 117 GUIElement element6 = new DummyGUIElement("elem6"); 118 simulateInteraction(element1, new DummyInteraction("bla", 1)); 119 simulateInteraction(element2, new DummyInteraction("bli", 1)); 120 simulateInteraction(element3, new DummyInteraction("bla", 1)); 121 simulateInteraction(element4, new DummyInteraction("bli", 1)); 122 simulateInteraction(element5, new DummyInteraction("blo", 1)); 123 simulateInteraction(element6, new DummyInteraction("bla", 1)); 124 125 new TaskTreeChecker().assertTaskTree 126 ("Sequence sequence0 {" + 127 " Sequence sequence1 {" + 128 " Interaction bla {}" + 129 " }" + 130 " Sequence sequence2 {" + 131 " Interaction bli {}" + 132 " }" + 133 " Sequence sequence3 {" + 134 " Interaction bla {}" + 135 " }" + 136 " Sequence sequence4 {" + 137 " Interaction bli {}" + 138 " }" + 139 " Sequence sequence5 {" + 140 " Interaction blo {}" + 141 " }" + 142 " Sequence sequence6 {" + 143 " Interaction bla {}" + 144 " }" + 145 "}", mManager.getTaskTree()); 146 } 147 148 //----------------------------------------------------------------------------------------------- 149 /** 150 * 151 */ 152 //----------------------------------------------------------------------------------------------- 153 @Test 154 public void testManyInteractionsOnManyElements() 155 { 156 GUIElement element1 = new DummyGUIElement("elem1"); 157 GUIElement element2 = new DummyGUIElement("elem2"); 158 GUIElement element3 = new DummyGUIElement("elem3"); 159 GUIElement element4 = new DummyGUIElement("elem4"); 160 GUIElement element5 = new DummyGUIElement("elem5"); 161 GUIElement element6 = new DummyGUIElement("elem6"); 162 simulateInteraction(element1, new DummyInteraction("bla", 1)); 163 simulateInteraction(element1, new DummyInteraction("bli", 1)); 164 simulateInteraction(element1, new DummyInteraction("bla", 1)); 165 simulateInteraction(element2, new DummyInteraction("bli", 1)); 166 simulateInteraction(element2, new DummyInteraction("blo", 1)); 167 simulateInteraction(element3, new DummyInteraction("bla", 1)); 168 simulateInteraction(element4, new DummyInteraction("bli", 1)); 169 simulateInteraction(element4, new DummyInteraction("bla", 1)); 170 simulateInteraction(element4, new DummyInteraction("bli", 1)); 171 simulateInteraction(element4, new DummyInteraction("blo", 1)); 172 simulateInteraction(element5, new DummyInteraction("bla", 1)); 173 simulateInteraction(element6, new DummyInteraction("bli", 1)); 174 simulateInteraction(element6, new DummyInteraction("bla", 1)); 175 simulateInteraction(element6, new DummyInteraction("bli", 1)); 176 simulateInteraction(element6, new DummyInteraction("blo", 1)); 177 178 new TaskTreeChecker().assertTaskTree 179 ("Sequence sequence0 {" + 180 " Sequence sequence1 {" + 181 " Interaction bla {}" + 182 " Interaction bli {}" + 183 " Interaction bla {}" + 184 " }" + 185 " Sequence sequence2 {" + 186 " Interaction bli {}" + 187 " Interaction blo {}" + 188 " }" + 189 " Sequence sequence3 {" + 190 " Interaction bla {}" + 191 " }" + 192 " Sequence sequence4 {" + 193 " Interaction bli {}" + 194 " Interaction bla {}" + 195 " Interaction bli {}" + 196 " Interaction blo {}" + 197 " }" + 198 " Sequence sequence5 {" + 199 " Interaction bla {}" + 200 " }" + 201 " Sequence sequence6 {" + 202 " Interaction bli {}" + 203 " Interaction bla {}" + 204 " Interaction bli {}" + 205 " Interaction blo {}" + 206 " }" + 207 "}", mManager.getTaskTree()); 208 } 209 210 //----------------------------------------------------------------------------------------------- 211 /** 212 * 213 */ 214 //----------------------------------------------------------------------------------------------- 215 @Test 216 public void testInteractionIterationDetection() throws Exception 217 { 218 GUIElement element1 = new DummyGUIElement("elem1"); 219 Interaction interaction1 = new DummyInteraction("bla", 1); 220 simulateInteraction(element1, interaction1); 221 new TaskTreeChecker().assertTaskTree 222 ("Sequence sequence1 {" + 223 " Interaction bla {}" + 224 "}", mManager.getTaskTree()); 225 226 simulateInteraction(element1, interaction1); 227 new TaskTreeChecker().assertTaskTree 228 ("Sequence sequence1 {" + 229 " Iteration iteration1 {" + 230 " Interaction bla {}" + 231 " }" + 232 "}", mManager.getTaskTree()); 233 234 simulateInteraction(element1, interaction1); 235 new TaskTreeChecker().assertTaskTree 236 ("Sequence sequence1 {" + 237 " Iteration iteration1 {" + 238 " Interaction bla {}" + 239 " }" + 240 "}", mManager.getTaskTree()); 241 242 for (int i = 0; i < 10; i++) 243 { 244 simulateInteraction(element1, interaction1); 245 } 246 247 new TaskTreeChecker().assertTaskTree 248 ("Sequence sequence1 {" + 249 " Iteration iteration1 {" + 250 " Interaction bla {}" + 251 " }" + 252 "}", mManager.getTaskTree()); 253 254 // now test with preceding and trailing other interactions 255 Interaction interaction2 = new DummyInteraction("bli", 1); 256 Interaction interaction3 = new DummyInteraction("blup", 1); 257 258 simulateInteraction(element1, interaction2); 259 simulateInteraction(element1, interaction3); 260 for (int i = 0; i < 10; i++) 261 { 262 simulateInteraction(element1, interaction1); 263 } 264 simulateInteraction(element1, interaction3); 265 simulateInteraction(element1, interaction2); 266 267 new TaskTreeChecker().assertTaskTree 268 ("Sequence sequence1 {" + 269 " Iteration iteration1 {" + 270 " Interaction bla {}" + 271 " }" + 272 " Interaction bli {}" + 273 " Interaction blup {}" + 274 " Iteration iteration2 {" + 275 " Interaction bla {}" + 276 " }" + 277 " Interaction blup {}" + 278 " Interaction bli {}" + 279 "}", mManager.getTaskTree()); 280 281 // now test with iterations of iterations 282 283 for (int i = 0; i < 10; i++) 284 { 285 for (int j = 0; j < 5; j++) 286 { 287 simulateInteraction(element1, interaction1); 288 } 289 for (int j = 0; j < 5; j++) 290 { 291 simulateInteraction(element1, interaction2); 292 } 293 for (int j = 0; j < 5; j++) 294 { 295 simulateInteraction(element1, interaction3); 296 } 297 } 298 299 new TaskTreeChecker().assertTaskTree 300 ("Sequence sequence0 {" + 301 " Iteration iteration0 {" + 302 " Interaction bla {}" + 303 " }" + 304 " Interaction bli {}" + 305 " Interaction blup {}" + 306 " Iteration iteration1 {" + 307 " Interaction bla {}" + 308 " }" + 309 " Interaction blup {}" + 310 " Interaction bli {}" + 311 " Iteration iteration2 {" + 312 " Sequence sequence1 {" + 313 " Iteration iteration3 {" + 314 " Interaction bla {}" + 315 " }" + 316 " Iteration iteration4 {" + 317 " Interaction bli {}" + 318 " }" + 319 " Iteration iteration5 {" + 320 " Interaction blup {}" + 321 " }" + 322 " }" + 323 " }" + 324 "}", mManager.getTaskTree()); 325 326 } 327 328 //----------------------------------------------------------------------------------------------- 329 /** 330 * 331 */ 332 //----------------------------------------------------------------------------------------------- 333 @Test 334 public void testSequenceIterationDetection() throws Exception 335 { 336 GUIElement element1 = new DummyGUIElement("elem1"); 337 Interaction interaction1 = new DummyInteraction("bla", 1); 338 Interaction interaction2 = new DummyInteraction("bli", 1); 339 Interaction interaction3 = new DummyInteraction("blup", 1); 340 simulateInteraction(element1, interaction1); 341 simulateInteraction(element1, interaction2); 342 simulateInteraction(element1, interaction3); 343 new TaskTreeChecker().assertTaskTree 344 ("Sequence sequence1 {" + 345 " Interaction bla {}" + 346 " Interaction bli {}" + 347 " Interaction blup {}" + 348 "}", mManager.getTaskTree()); 349 350 simulateInteraction(element1, interaction1); 351 simulateInteraction(element1, interaction2); 352 simulateInteraction(element1, interaction3); 353 new TaskTreeChecker().assertTaskTree 354 ("Sequence sequence1 {" + 355 " Iteration iteration1 {" + 356 " Sequence sequence2 {" + 357 " Interaction bla {}" + 358 " Interaction bli {}" + 359 " Interaction blup {}" + 360 " }" + 361 " }" + 362 "}", mManager.getTaskTree()); 363 364 simulateInteraction(element1, interaction1); 365 simulateInteraction(element1, interaction2); 366 simulateInteraction(element1, interaction3); 367 new TaskTreeChecker().assertTaskTree 368 ("Sequence sequence1 {" + 369 " Iteration iteration1 {" + 370 " Sequence sequence2 {" + 371 " Interaction bla {}" + 372 " Interaction bli {}" + 373 " Interaction blup {}" + 374 " }" + 375 " }" + 376 "}", mManager.getTaskTree()); 377 378 for (int i = 0; i < 10; i++) 379 { 380 simulateInteraction(element1, interaction1); 381 simulateInteraction(element1, interaction2); 382 simulateInteraction(element1, interaction3); 383 } 384 385 new TaskTreeChecker().assertTaskTree 386 ("Sequence sequence1 {" + 387 " Iteration iteration1 {" + 388 " Sequence sequence2 {" + 389 " Interaction bla {}" + 390 " Interaction bli {}" + 391 " Interaction blup {}" + 392 " }" + 393 " }" + 394 "}", mManager.getTaskTree()); 395 396 // now test with preceding and trailing other interactions 397 Interaction interaction4 = new DummyInteraction("ble", 1); 398 Interaction interaction5 = new DummyInteraction("blo", 1); 399 Interaction interaction6 = new DummyInteraction("blu", 1); 400 simulateInteraction(element1, interaction4); 401 simulateInteraction(element1, interaction5); 402 simulateInteraction(element1, interaction6); 403 for (int i = 0; i < 10; i++) 404 { 405 simulateInteraction(element1, interaction1); 406 simulateInteraction(element1, interaction2); 407 simulateInteraction(element1, interaction3); 408 } 409 simulateInteraction(element1, interaction6); 410 simulateInteraction(element1, interaction5); 411 simulateInteraction(element1, interaction4); 412 413 new TaskTreeChecker().assertTaskTree 414 ("Sequence sequence1 {" + 415 " Iteration iteration1 {" + 416 " Sequence sequence2 {" + 417 " Interaction bla {}" + 418 " Interaction bli {}" + 419 " Interaction blup {}" + 420 " }" + 421 " }" + 422 " Interaction ble {}" + 423 " Interaction blo {}" + 424 " Interaction blu {}" + 425 " Iteration iteration2 {" + 426 " Sequence sequence3 {" + 427 " Interaction bla {}" + 428 " Interaction bli {}" + 429 " Interaction blup {}" + 430 " }" + 431 " }" + 432 " Interaction blu {}" + 433 " Interaction blo {}" + 434 " Interaction ble {}" + 435 "}", mManager.getTaskTree()); 436 437 // now test with iterations of iterations 438 for (int i = 0; i < 10; i++) 439 { 440 for (int j = 0; j < 5; j++) 441 { 442 simulateInteraction(element1, interaction1); 443 simulateInteraction(element1, interaction2); 444 simulateInteraction(element1, interaction3); 445 } 446 for (int j = 0; j < 5; j++) 447 { 448 simulateInteraction(element1, interaction2); 449 simulateInteraction(element1, interaction1); 450 simulateInteraction(element1, interaction3); 451 } 452 for (int j = 0; j < 5; j++) 453 { 454 simulateInteraction(element1, interaction1); 455 simulateInteraction(element1, interaction2); 456 simulateInteraction(element1, interaction3); 457 } 458 } 459 460 new TaskTreeChecker().assertTaskTree 461 ("Sequence sequence1 {" + 462 " Iteration iteration1 {" + 463 " Sequence sequence2 {" + 464 " Interaction bla {}" + 465 " Interaction bli {}" + 466 " Interaction blup {}" + 467 " }" + 468 " }" + 469 " Interaction ble {}" + 470 " Interaction blo {}" + 471 " Interaction blu {}" + 472 " Iteration iteration2 {" + 473 " Sequence sequence3 {" + 474 " Interaction bla {}" + 475 " Interaction bli {}" + 476 " Interaction blup {}" + 477 " }" + 478 " }" + 479 " Interaction blu {}" + 480 " Interaction blo {}" + 481 " Interaction ble {}" + 482 " Iteration iteration3 {" + 483 " Sequence sequence4 {" + 484 " Iteration iteration4 {" + 485 " Sequence sequence4 {" + 486 " Interaction bla {}" + 487 " Interaction bli {}" + 488 " Interaction blup {}" + 489 " }" + 490 " }" + 491 " Iteration iteration5 {" + 492 " Sequence sequence5 {" + 493 " Interaction bli {}" + 494 " Interaction bla {}" + 495 " Interaction blup {}" + 496 " }" + 497 " }" + 498 " Iteration iteration6 {" + 499 " Sequence sequence6 {" + 500 " Interaction bla {}" + 501 " Interaction bli {}" + 502 " Interaction blup {}" + 503 " }" + 504 " }" + 505 " }" + 506 " }" + 507 "}", mManager.getTaskTree()); 508 } 509 510 //----------------------------------------------------------------------------------------------- 511 /** 512 * 513 */ 514 //----------------------------------------------------------------------------------------------- 515 @Test 516 public void testGUIElementHierarchyChanges() throws Exception 517 { 518 GUIElement element1 = new DummyGUIElement("elem1"); 519 GUIElement element2 = new DummyGUIElement("elem2"); 520 GUIElement element3 = new DummyGUIElement("elem3"); 521 GUIElement parent1 = new DummyGUIElement("parent1"); 522 GUIElement parent2 = new DummyGUIElement("parent2"); 523 GUIElement parent3 = new DummyGUIElement("parent3"); 524 525 element1.setParent(parent1); 526 element2.setParent(parent2); 527 element3.setParent(parent3); 528 529 parent1.setParent(parent2); 530 parent2.setParent(parent3); 531 532 Interaction interaction1 = new DummyInteraction("bla", 1); 533 simulateInteraction(element1, interaction1); 534 simulateInteraction(element2, interaction1); 535 simulateInteraction(element3, interaction1); 536 simulateInteraction(element2, interaction1); 537 simulateInteraction(element3, interaction1); 538 simulateInteraction(element2, interaction1); 539 simulateInteraction(element1, interaction1); 540 541 new TaskTreeChecker().assertTaskTree 542 ("Sequence sequence0 {" + 543 " Sequence sequence1 {" + 544 " Interaction bla {}" + 545 " }" + 546 " Sequence sequence2 {" + 547 " Interaction bla {}" + 548 " }" + 549 " Iteration iteration0 {" + 550 " Sequence sequence3 {" + 551 " Sequence sequence4 {" + 552 " Interaction bla {}" + 553 " }" + 554 " Sequence sequence5 {" + 555 " Interaction bla {}" + 556 " }" + 557 " }" + 558 " }" + 559 " Sequence sequence6 {" + 560 " Interaction bla {}" + 561 " }" + 562 "}", mManager.getTaskTree()); 563 564 } 565 566 //----------------------------------------------------------------------------------------------- 567 /** 568 * @param interactionsDoNotOverwriteElement 569 */ 570 //----------------------------------------------------------------------------------------------- 571 private void simulateInteraction(GUIElement GUIElement, Interaction interaction) 572 { 573 mManager.handleNewInteractionEvent(new InteractionEvent(GUIElement, interaction)); 574 } 31 /** */ 32 TaskTreeManager manager; 33 34 /** 35 * 36 */ 37 @Before 38 public void setUp() { 39 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 40 41 manager = new TaskTreeManager(); 42 } 43 44 /** 45 * 46 */ 47 @After 48 public void tearDown() { 49 manager = null; 50 ComponentManager.clearInstance(); 51 } 52 53 /** 54 * 55 */ 56 @Test 57 public void testOneEventOnOneElement() { 58 simulateEvent(new DummyInteraction("bla", 1), new DummyGUIElement("elem1")); 59 new TaskTreeChecker().assertTaskTree 60 ("Sequence sequence {" + 61 " Event bla {}" + 62 "}", manager.getTaskTree()); 63 } 64 65 /** 66 * 67 */ 68 @Test 69 public void testManyEventsOnOneElement() { 70 IEventTarget eventTarget = new DummyGUIElement("elem1"); 71 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 72 simulateEvent(new DummyInteraction("bli", 1), eventTarget); 73 simulateEvent(new DummyInteraction("blo", 1), eventTarget); 74 simulateEvent(new DummyInteraction("blu", 1), eventTarget); 75 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence {" + 79 " Event bla {}" + 80 " Event bli {}" + 81 " Event blo {}" + 82 " Event blu {}" + 83 " Event bla {}" + 84 "}", manager.getTaskTree()); 85 } 86 87 /** 88 * 89 */ 90 @Test 91 public void testOneEventOnManyElements() { 92 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 93 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 94 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 95 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 96 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 97 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 98 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 99 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 100 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 101 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 102 simulateEvent(new DummyInteraction("blo", 1), eventTarget5); 103 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 104 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence0 {" + 107 " Sequence sequence1 {" + 108 " Event bla {}" + 109 " }" + 110 " Sequence sequence2 {" + 111 " Event bli {}" + 112 " }" + 113 " Sequence sequence3 {" + 114 " Event bla {}" + 115 " }" + 116 " Sequence sequence4 {" + 117 " Event bli {}" + 118 " }" + 119 " Sequence sequence5 {" + 120 " Event blo {}" + 121 " }" + 122 " Sequence sequence6 {" + 123 " Event bla {}" + 124 " }" + 125 "}", manager.getTaskTree()); 126 } 127 128 /** 129 * 130 */ 131 @Test 132 public void testManyEventsOnManyElements() { 133 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 134 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 135 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 136 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 137 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 138 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 139 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 140 simulateEvent(new DummyInteraction("bli", 1), eventTarget1); 141 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 142 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 143 simulateEvent(new DummyInteraction("blo", 1), eventTarget2); 144 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 145 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 146 simulateEvent(new DummyInteraction("bla", 1), eventTarget4); 147 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 148 simulateEvent(new DummyInteraction("blo", 1), eventTarget4); 149 simulateEvent(new DummyInteraction("bla", 1), eventTarget5); 150 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 151 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 152 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 153 simulateEvent(new DummyInteraction("blo", 1), eventTarget6); 154 155 new TaskTreeChecker().assertTaskTree 156 ("Sequence sequence0 {" + 157 " Sequence sequence1 {" + 158 " Event bla {}" + 159 " Event bli {}" + 160 " Event bla {}" + 161 " }" + 162 " Sequence sequence2 {" + 163 " Event bli {}" + 164 " Event blo {}" + 165 " }" + 166 " Sequence sequence3 {" + 167 " Event bla {}" + 168 " }" + 169 " Sequence sequence4 {" + 170 " Event bli {}" + 171 " Event bla {}" + 172 " Event bli {}" + 173 " Event blo {}" + 174 " }" + 175 " Sequence sequence5 {" + 176 " Event bla {}" + 177 " }" + 178 " Sequence sequence6 {" + 179 " Event bli {}" + 180 " Event bla {}" + 181 " Event bli {}" + 182 " Event blo {}" + 183 " }" + 184 "}", manager.getTaskTree()); 185 } 186 187 /** 188 * 189 */ 190 @Test 191 public void testEventIterationDetection() throws Exception { 192 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 193 IEventType event1 = new DummyInteraction("bla", 1); 194 simulateEvent(event1, eventTarget1); 195 new TaskTreeChecker().assertTaskTree 196 ("Sequence sequence1 {" + 197 " Event bla {}" + 198 "}", manager.getTaskTree()); 199 200 simulateEvent(event1, eventTarget1); 201 new TaskTreeChecker().assertTaskTree 202 ("Sequence sequence1 {" + 203 " Iteration iteration1 {" + 204 " Event bla {}" + 205 " }" + 206 "}", manager.getTaskTree()); 207 208 simulateEvent(event1, eventTarget1); 209 new TaskTreeChecker().assertTaskTree 210 ("Sequence sequence1 {" + 211 " Iteration iteration1 {" + 212 " Event bla {}" + 213 " }" + 214 "}", manager.getTaskTree()); 215 216 for (int i = 0; i < 10; i++) { 217 simulateEvent(event1, eventTarget1); 218 } 219 220 new TaskTreeChecker().assertTaskTree 221 ("Sequence sequence1 {" + 222 " Iteration iteration1 {" + 223 " Event bla {}" + 224 " }" + 225 "}", manager.getTaskTree()); 226 227 // now test with preceding and trailing other interactions 228 IEventType event2 = new DummyInteraction("bli", 1); 229 IEventType event3 = new DummyInteraction("blup", 1); 230 231 simulateEvent(event2, eventTarget1); 232 simulateEvent(event3, eventTarget1); 233 for (int i = 0; i < 10; i++) { 234 simulateEvent(event1, eventTarget1); 235 } 236 simulateEvent(event3, eventTarget1); 237 simulateEvent(event2, eventTarget1); 238 239 new TaskTreeChecker().assertTaskTree 240 ("Sequence sequence1 {" + 241 " Iteration iteration1 {" + 242 " Event bla {}" + 243 " }" + 244 " Event bli {}" + 245 " Event blup {}" + 246 " Iteration iteration2 {" + 247 " Event bla {}" + 248 " }" + 249 " Event blup {}" + 250 " Event bli {}" + 251 "}", manager.getTaskTree()); 252 253 // now test with iterations of iterations 254 255 for (int i = 0; i < 10; i++) { 256 for (int j = 0; j < 5; j++) { 257 simulateEvent(event1, eventTarget1); 258 } 259 for (int j = 0; j < 5; j++) { 260 simulateEvent(event2, eventTarget1); 261 } 262 for (int j = 0; j < 5; j++) { 263 simulateEvent(event3, eventTarget1); 264 } 265 } 266 267 new TaskTreeChecker().assertTaskTree 268 ("Sequence sequence0 {" + 269 " Iteration iteration0 {" + 270 " Event bla {}" + 271 " }" + 272 " Event bli {}" + 273 " Event blup {}" + 274 " Iteration iteration1 {" + 275 " Event bla {}" + 276 " }" + 277 " Event blup {}" + 278 " Event bli {}" + 279 " Iteration iteration2 {" + 280 " Sequence sequence1 {" + 281 " Iteration iteration3 {" + 282 " Event bla {}" + 283 " }" + 284 " Iteration iteration4 {" + 285 " Event bli {}" + 286 " }" + 287 " Iteration iteration5 {" + 288 " Event blup {}" + 289 " }" + 290 " }" + 291 " }" + 292 "}", manager.getTaskTree()); 293 294 } 295 296 /** 297 * 298 */ 299 @Test 300 public void testSequenceIterationDetection() throws Exception { 301 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 302 IEventType event1 = new DummyInteraction("bla", 1); 303 IEventType event2 = new DummyInteraction("bli", 1); 304 IEventType event3 = new DummyInteraction("blup", 1); 305 simulateEvent(event1, eventTarget1); 306 simulateEvent(event2, eventTarget1); 307 simulateEvent(event3, eventTarget1); 308 new TaskTreeChecker().assertTaskTree 309 ("Sequence sequence1 {" + 310 " Event bla {}" + 311 " Event bli {}" + 312 " Event blup {}" + 313 "}", manager.getTaskTree()); 314 315 simulateEvent(event1, eventTarget1); 316 simulateEvent(event2, eventTarget1); 317 simulateEvent(event3, eventTarget1); 318 new TaskTreeChecker().assertTaskTree 319 ("Sequence sequence1 {" + 320 " Iteration iteration1 {" + 321 " Sequence sequence2 {" + 322 " Event bla {}" + 323 " Event bli {}" + 324 " Event blup {}" + 325 " }" + 326 " }" + 327 "}", manager.getTaskTree()); 328 329 simulateEvent(event1, eventTarget1); 330 simulateEvent(event2, eventTarget1); 331 simulateEvent(event3, eventTarget1); 332 new TaskTreeChecker().assertTaskTree 333 ("Sequence sequence1 {" + 334 " Iteration iteration1 {" + 335 " Sequence sequence2 {" + 336 " Event bla {}" + 337 " Event bli {}" + 338 " Event blup {}" + 339 " }" + 340 " }" + 341 "}", manager.getTaskTree()); 342 343 for (int i = 0; i < 10; i++) { 344 simulateEvent(event1, eventTarget1); 345 simulateEvent(event2, eventTarget1); 346 simulateEvent(event3, eventTarget1); 347 } 348 349 new TaskTreeChecker().assertTaskTree 350 ("Sequence sequence1 {" + 351 " Iteration iteration1 {" + 352 " Sequence sequence2 {" + 353 " Event bla {}" + 354 " Event bli {}" + 355 " Event blup {}" + 356 " }" + 357 " }" + 358 "}", manager.getTaskTree()); 359 360 // now test with preceding and trailing other interactions 361 IEventType event4 = new DummyInteraction("ble", 1); 362 IEventType event5 = new DummyInteraction("blo", 1); 363 IEventType event6 = new DummyInteraction("blu", 1); 364 simulateEvent(event4, eventTarget1); 365 simulateEvent(event5, eventTarget1); 366 simulateEvent(event6, eventTarget1); 367 for (int i = 0; i < 10; i++) { 368 simulateEvent(event1, eventTarget1); 369 simulateEvent(event2, eventTarget1); 370 simulateEvent(event3, eventTarget1); 371 } 372 simulateEvent(event6, eventTarget1); 373 simulateEvent(event5, eventTarget1); 374 simulateEvent(event4, eventTarget1); 375 376 new TaskTreeChecker().assertTaskTree 377 ("Sequence sequence1 {" + 378 " Iteration iteration1 {" + 379 " Sequence sequence2 {" + 380 " Event bla {}" + 381 " Event bli {}" + 382 " Event blup {}" + 383 " }" + 384 " }" + 385 " Event ble {}" + 386 " Event blo {}" + 387 " Event blu {}" + 388 " Iteration iteration2 {" + 389 " Sequence sequence3 {" + 390 " Event bla {}" + 391 " Event bli {}" + 392 " Event blup {}" + 393 " }" + 394 " }" + 395 " Event blu {}" + 396 " Event blo {}" + 397 " Event ble {}" + 398 "}", manager.getTaskTree()); 399 400 // now test with iterations of iterations 401 for (int i = 0; i < 10; i++) { 402 for (int j = 0; j < 5; j++) { 403 simulateEvent(event1, eventTarget1); 404 simulateEvent(event2, eventTarget1); 405 simulateEvent(event3, eventTarget1); 406 } 407 for (int j = 0; j < 5; j++) { 408 simulateEvent(event2, eventTarget1); 409 simulateEvent(event1, eventTarget1); 410 simulateEvent(event3, eventTarget1); 411 } 412 for (int j = 0; j < 5; j++) { 413 simulateEvent(event1, eventTarget1); 414 simulateEvent(event2, eventTarget1); 415 simulateEvent(event3, eventTarget1); 416 } 417 } 418 419 new TaskTreeChecker().assertTaskTree 420 ("Sequence sequence1 {" + 421 " Iteration iteration1 {" + 422 " Sequence sequence2 {" + 423 " Event bla {}" + 424 " Event bli {}" + 425 " Event blup {}" + 426 " }" + 427 " }" + 428 " Event ble {}" + 429 " Event blo {}" + 430 " Event blu {}" + 431 " Iteration iteration2 {" + 432 " Sequence sequence3 {" + 433 " Event bla {}" + 434 " Event bli {}" + 435 " Event blup {}" + 436 " }" + 437 " }" + 438 " Event blu {}" + 439 " Event blo {}" + 440 " Event ble {}" + 441 " Iteration iteration3 {" + 442 " Sequence sequence4 {" + 443 " Iteration iteration4 {" + 444 " Sequence sequence4 {" + 445 " Event bla {}" + 446 " Event bli {}" + 447 " Event blup {}" + 448 " }" + 449 " }" + 450 " Iteration iteration5 {" + 451 " Sequence sequence5 {" + 452 " Event bli {}" + 453 " Event bla {}" + 454 " Event blup {}" + 455 " }" + 456 " }" + 457 " Iteration iteration6 {" + 458 " Sequence sequence6 {" + 459 " Event bla {}" + 460 " Event bli {}" + 461 " Event blup {}" + 462 " }" + 463 " }" + 464 " }" + 465 " }" + 466 "}", manager.getTaskTree()); 467 } 468 469 /** 470 * 471 */ 472 private void simulateEvent(IEventType eventType, IEventTarget eventTarget) { 473 manager.handleNewEvent(new Event(eventType, eventTarget)); 474 } 575 475 576 476 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/AbstractTemporalRelationshipTC.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: AbstractTemporalRelationshipTC.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 14 13 import org.junit.Before; 15 14 16 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;17 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;15 import de.ugoe.cs.quest.eventcore.IEventTarget; 16 import de.ugoe.cs.quest.eventcore.IEventType; 18 17 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 19 18 import de.ugoe.cs.quest.tasktrees.testutils.SimpleLogFormatter; 20 19 import de.ugoe.cs.quest.tasktrees.testutils.Utilities; 21 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;22 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;23 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;24 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;25 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;26 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder Impl;27 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory Impl;20 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 21 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 22 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 25 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 26 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 28 27 29 //-------------------------------------------------------------------------------------------------30 28 /** 31 29 * TODO comment … … 34 32 * @author 2012, last modified by $Author: patrick$ 35 33 */ 36 //------------------------------------------------------------------------------------------------- 37 public class AbstractTemporalRelationshipTC 38 { 34 public class AbstractTemporalRelationshipTC { 39 35 40 /** */ 41 private List<InteractionTask> mInteractions; 42 43 /** */ 44 private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); 36 /** */ 37 private List<IEventTask> events; 45 38 46 /** */ 47 private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 48 49 /** */ 50 private NodeEqualityRuleManager mNodeEqualityRuleManager = 51 Utilities.getNodeEqualityRuleManagerForTests(); 39 /** */ 40 private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 52 41 53 //----------------------------------------------------------------------------------------------- 54 /** 42 /** */ 43 private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 44 45 /** */ 46 private NodeEqualityRuleManager nodeEqualityRuleManager = 47 Utilities.getNodeEqualityRuleManagerForTests(); 48 49 /** 55 50 * 56 51 */ 57 //----------------------------------------------------------------------------------------------- 58 @Before 59 public void setUp() 60 { 61 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 62 mInteractions = new ArrayList<InteractionTask>(); 63 } 52 @Before 53 public void setUp() { 54 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 55 events = new ArrayList<IEventTask>(); 56 } 64 57 65 //----------------------------------------------------------------------------------------------- 66 /** 67 * @param interactionsDoNotOverwriteElement 68 */ 69 //----------------------------------------------------------------------------------------------- 70 protected void simulateInteraction(GUIElement GUIElement, Interaction interaction) 71 { 72 mInteractions.add 73 (mTaskTreeNodeFactory.createNewInteractionTask(GUIElement, interaction)); 74 } 58 /** 59 * 60 */ 61 protected void simulateEvent(IEventType eventType, IEventTarget eventTarget) { 62 events.add(taskTreeNodeFactory.createNewEventTask(eventType, eventTarget)); 63 } 75 64 76 //----------------------------------------------------------------------------------------------- 77 /** 78 * @param interactionsDoNotOverwriteElement 79 * @return 80 */ 81 //----------------------------------------------------------------------------------------------- 82 protected TaskTree getTaskTree() 83 { 84 Sequence sequence = mTaskTreeNodeFactory.createNewSequence(); 85 86 for (InteractionTask task : mInteractions) 87 { 88 mTaskTreeBuilder.addChild(sequence, task); 65 /** 66 * 67 * @return 68 */ 69 protected ITaskTree getTaskTree() { 70 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 71 72 for (IEventTask task : events) { 73 taskTreeBuilder.addChild(sequence, task); 74 } 75 76 TemporalRelationshipRuleManager ruleManager = 77 new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 78 79 ruleManager.init(); 80 ruleManager.applyRules(sequence, taskTreeBuilder, taskTreeNodeFactory, true); 81 82 return taskTreeNodeFactory.createTaskTree(sequence); 89 83 } 90 91 TemporalRelationshipRuleManager ruleManager =92 new TemporalRelationshipRuleManager(mNodeEqualityRuleManager);93 94 ruleManager.init();95 ruleManager.applyRules(sequence, mTaskTreeBuilder, mTaskTreeNodeFactory, true);96 97 return mTaskTreeNodeFactory.createTaskTree(sequence);98 }99 84 100 85 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; … … 11 9 import org.junit.Test; 12 10 13 import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; 14 import de.ugoe.cs.quest.eventcore.userinteraction.Interaction; 11 import de.ugoe.cs.quest.eventcore.IEventTarget; 15 12 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 16 13 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 17 14 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 15 19 //-------------------------------------------------------------------------------------------------20 16 /** 21 17 * TODO comment 22 * 18 * 23 19 * @version $Revision: $ $Date: $ 24 * @author 20 * @author 2011, last modified by $Author: $ 25 21 */ 26 //------------------------------------------------------------------------------------------------- 27 public class DefaultGUIElementSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC 28 { 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 @Test 35 public void testOneInteractionOnOneElement() 36 { 37 simulateInteraction(new DummyGUIElement("elem1"), new DummyInteraction("bla", 1)); 22 public class DefaultGuiEventSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC { 38 23 39 new TaskTreeChecker().assertTaskTree 40 ("Sequence sequence {" + 41 " Interaction bla {}" + 42 "}", getTaskTree()); 43 } 44 45 //----------------------------------------------------------------------------------------------- 46 /** 47 * 48 */ 49 //----------------------------------------------------------------------------------------------- 50 @Test 51 public void testManyInteractionsOnOneElement() 52 { 53 GUIElement element = new DummyGUIElement("elem1"); 54 simulateInteraction(element, new DummyInteraction("bla", 1)); 55 simulateInteraction(element, new DummyInteraction("bli", 1)); 56 simulateInteraction(element, new DummyInteraction("blo", 1)); 57 simulateInteraction(element, new DummyInteraction("blu", 1)); 58 simulateInteraction(element, new DummyInteraction("bla", 1)); 59 60 new TaskTreeChecker().assertTaskTree 61 ("Sequence sequence {" + 62 " Interaction bla {}" + 63 " Interaction bli {}" + 64 " Interaction blo {}" + 65 " Interaction blu {}" + 66 " Interaction bla {}" + 67 "}", getTaskTree()); 68 } 69 70 //----------------------------------------------------------------------------------------------- 71 /** 72 * 73 */ 74 //----------------------------------------------------------------------------------------------- 75 @Test 76 public void testOneInteractionOnManyElements() 77 { 78 GUIElement element1 = new DummyGUIElement("elem1"); 79 GUIElement element2 = new DummyGUIElement("elem2"); 80 GUIElement element3 = new DummyGUIElement("elem3"); 81 GUIElement element4 = new DummyGUIElement("elem4"); 82 GUIElement element5 = new DummyGUIElement("elem5"); 83 GUIElement element6 = new DummyGUIElement("elem6"); 84 simulateInteraction(element1, new DummyInteraction("bla", 1)); 85 simulateInteraction(element2, new DummyInteraction("bli", 1)); 86 simulateInteraction(element3, new DummyInteraction("bla", 1)); 87 simulateInteraction(element4, new DummyInteraction("bli", 1)); 88 simulateInteraction(element5, new DummyInteraction("blo", 1)); 89 simulateInteraction(element6, new DummyInteraction("bla", 1)); 24 /** 25 * 26 */ 27 @Test 28 public void testOneInteractionOnOneElement() { 29 simulateEvent(new DummyInteraction("bla", 1), new DummyGUIElement("elem1")); 90 30 91 new TaskTreeChecker().assertTaskTree 92 ("Sequence sequence0 {" + 93 " Sequence sequence1 {" + 94 " Interaction bla {}" + 95 " }" + 96 " Sequence sequence2 {" + 97 " Interaction bli {}" + 98 " }" + 99 " Sequence sequence3 {" + 100 " Interaction bla {}" + 101 " }" + 102 " Sequence sequence4 {" + 103 " Interaction bli {}" + 104 " }" + 105 " Sequence sequence5 {" + 106 " Interaction blo {}" + 107 " }" + 108 " Sequence sequence6 {" + 109 " Interaction bla {}" + 110 " }" + 111 "}", getTaskTree()); 112 } 31 new TaskTreeChecker().assertTaskTree 32 ("Sequence sequence {" + 33 " Event bla {}" + 34 "}", getTaskTree()); 35 } 113 36 114 //----------------------------------------------------------------------------------------------- 115 /** 116 * 117 */ 118 //----------------------------------------------------------------------------------------------- 119 @Test 120 public void testManyInteractionsOnManyElements() 121 { 122 GUIElement element1 = new DummyGUIElement("elem1"); 123 GUIElement element2 = new DummyGUIElement("elem2"); 124 GUIElement element3 = new DummyGUIElement("elem3"); 125 GUIElement element4 = new DummyGUIElement("elem4"); 126 GUIElement element5 = new DummyGUIElement("elem5"); 127 GUIElement element6 = new DummyGUIElement("elem6"); 128 simulateInteraction(element1, new DummyInteraction("bla", 1)); 129 simulateInteraction(element1, new DummyInteraction("bli", 1)); 130 simulateInteraction(element1, new DummyInteraction("bla", 1)); 131 simulateInteraction(element2, new DummyInteraction("bli", 1)); 132 simulateInteraction(element2, new DummyInteraction("blo", 1)); 133 simulateInteraction(element3, new DummyInteraction("bla", 1)); 134 simulateInteraction(element4, new DummyInteraction("bli", 1)); 135 simulateInteraction(element4, new DummyInteraction("bla", 1)); 136 simulateInteraction(element4, new DummyInteraction("bli", 1)); 137 simulateInteraction(element4, new DummyInteraction("blo", 1)); 138 simulateInteraction(element5, new DummyInteraction("bla", 1)); 139 simulateInteraction(element6, new DummyInteraction("bli", 1)); 140 simulateInteraction(element6, new DummyInteraction("bla", 1)); 141 simulateInteraction(element6, new DummyInteraction("bli", 1)); 142 simulateInteraction(element6, new DummyInteraction("blo", 1)); 143 144 new TaskTreeChecker().assertTaskTree 145 ("Sequence sequence0 {" + 146 " Sequence sequence1 {" + 147 " Interaction bla {}" + 148 " Interaction bli {}" + 149 " Interaction bla {}" + 150 " }" + 151 " Sequence sequence2 {" + 152 " Interaction bli {}" + 153 " Interaction blo {}" + 154 " }" + 155 " Sequence sequence3 {" + 156 " Interaction bla {}" + 157 " }" + 158 " Sequence sequence4 {" + 159 " Interaction bli {}" + 160 " Interaction bla {}" + 161 " Interaction bli {}" + 162 " Interaction blo {}" + 163 " }" + 164 " Sequence sequence5 {" + 165 " Interaction bla {}" + 166 " }" + 167 " Sequence sequence6 {" + 168 " Interaction bli {}" + 169 " Interaction bla {}" + 170 " Interaction bli {}" + 171 " Interaction blo {}" + 172 " }" + 173 "}", getTaskTree()); 174 } 37 /** 38 * 39 */ 40 @Test 41 public void testManyInteractionsOnOneElement() { 42 IEventTarget eventTarget = new DummyGUIElement("elem1"); 43 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 44 simulateEvent(new DummyInteraction("bli", 1), eventTarget); 45 simulateEvent(new DummyInteraction("blo", 1), eventTarget); 46 simulateEvent(new DummyInteraction("blu", 1), eventTarget); 47 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 175 48 176 //----------------------------------------------------------------------------------------------- 177 /** 178 * 179 */ 180 //----------------------------------------------------------------------------------------------- 181 @Test 182 public void testGUIElementHierarchyChanges() throws Exception 183 { 184 GUIElement element1 = new DummyGUIElement("elem1"); 185 GUIElement element2 = new DummyGUIElement("elem2"); 186 GUIElement element3 = new DummyGUIElement("elem3"); 187 GUIElement parent1 = new DummyGUIElement("parent1"); 188 GUIElement parent2 = new DummyGUIElement("parent2"); 189 GUIElement parent3 = new DummyGUIElement("parent3"); 190 191 element1.setParent(parent1); 192 element2.setParent(parent2); 193 element3.setParent(parent3); 194 195 parent1.setParent(parent2); 196 parent2.setParent(parent3); 197 198 Interaction interaction1 = new DummyInteraction("bla", 1); 199 simulateInteraction(element1, interaction1); 200 simulateInteraction(element2, interaction1); 201 simulateInteraction(element3, interaction1); 202 simulateInteraction(element2, interaction1); 203 simulateInteraction(element3, interaction1); 204 simulateInteraction(element2, interaction1); 205 simulateInteraction(element1, interaction1); 206 207 new TaskTreeChecker().assertTaskTree 208 ("Sequence sequence0 {" + 209 " Sequence sequence1 {" + 210 " Interaction bla {}" + 211 " }" + 212 " Sequence sequence2 {" + 213 " Interaction bla {}" + 214 " }" + 215 " Iteration iteration0 {" + 216 " Sequence sequence3 {" + 217 " Sequence sequence4 {" + 218 " Interaction bla {}" + 219 " }" + 220 " Sequence sequence5 {" + 221 " Interaction bla {}" + 222 " }" + 223 " }" + 224 " }" + 225 " Sequence sequence6 {" + 226 " Interaction bla {}" + 227 " }" + 228 "}", getTaskTree()); 49 new TaskTreeChecker().assertTaskTree 50 ("Sequence sequence {" + 51 " Event bla {}" + 52 " Event bli {}" + 53 " Event blo {}" + 54 " Event blu {}" + 55 " Event bla {}" + 56 "}", getTaskTree()); 57 } 229 58 230 } 231 59 /** 60 * 61 */ 62 @Test 63 public void testOneInteractionOnManyElements() { 64 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 65 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 66 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 67 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 68 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 69 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 70 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 71 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 72 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 73 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 74 simulateEvent(new DummyInteraction("blo", 1), eventTarget5); 75 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence0 {" + 79 " Sequence sequence1 {" + 80 " Event bla {}" + 81 " }" + 82 " Sequence sequence2 {" + 83 " Event bli {}" + 84 " }" + 85 " Sequence sequence3 {" + 86 " Event bla {}" + 87 " }" + 88 " Sequence sequence4 {" + 89 " Event bli {}" + 90 " }" + 91 " Sequence sequence5 {" + 92 " Event blo {}" + 93 " }" + 94 " Sequence sequence6 {" + 95 " Event bla {}" + 96 " }" + 97 "}", getTaskTree()); 98 } 99 100 /** 101 * 102 */ 103 @Test 104 public void testManyInteractionsOnManyElements() { 105 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 106 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 107 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 108 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 109 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 110 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 111 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 112 simulateEvent(new DummyInteraction("bli", 1), eventTarget1); 113 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 114 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 115 simulateEvent(new DummyInteraction("blo", 1), eventTarget2); 116 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 117 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 118 simulateEvent(new DummyInteraction("bla", 1), eventTarget4); 119 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 120 simulateEvent(new DummyInteraction("blo", 1), eventTarget4); 121 simulateEvent(new DummyInteraction("bla", 1), eventTarget5); 122 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 123 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 124 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 125 simulateEvent(new DummyInteraction("blo", 1), eventTarget6); 126 127 new TaskTreeChecker().assertTaskTree 128 ("Sequence sequence0 {" + 129 " Sequence sequence1 {" + 130 " Event bla {}" + 131 " Event bli {}" + 132 " Event bla {}" + 133 " }" + 134 " Sequence sequence2 {" + 135 " Event bli {}" + 136 " Event blo {}" + 137 " }" + 138 " Sequence sequence3 {" + 139 " Event bla {}" + 140 " }" + 141 " Sequence sequence4 {" + 142 " Event bli {}" + 143 " Event bla {}" + 144 " Event bli {}" + 145 " Event blo {}" + 146 " }" + 147 " Sequence sequence5 {" + 148 " Event bla {}" + 149 " }" + 150 " Sequence sequence6 {" + 151 " Event bli {}" + 152 " Event bla {}" + 153 " Event bli {}" + 154 " Event blo {}" + 155 " }" + 156 "}", getTaskTree()); 157 } 158 232 159 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;13 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;11 import de.ugoe.cs.quest.eventcore.IEventTarget; 12 import de.ugoe.cs.quest.eventcore.IEventType; 14 13 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 15 14 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 17 16 18 //-------------------------------------------------------------------------------------------------19 17 /** 20 18 * TODO comment … … 23 21 * @author 2012, last modified by $Author: patrick$ 24 22 */ 25 //------------------------------------------------------------------------------------------------- 26 public class DefaultIterationDetectionRuleTest extends AbstractTemporalRelationshipTC 27 { 28 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 @Test 35 public void testInteractionIterationDetection() throws Exception 36 { 37 GUIElement element1 = new DummyGUIElement("elem1"); 38 Interaction interaction1 = new DummyInteraction("bla", 1); 39 simulateInteraction(element1, interaction1); 40 new TaskTreeChecker().assertTaskTree 41 ("Sequence sequence1 {" + 42 " Interaction bla {}" + 43 "}", getTaskTree()); 44 45 simulateInteraction(element1, interaction1); 46 new TaskTreeChecker().assertTaskTree 47 ("Sequence sequence1 {" + 48 " Iteration iteration1 {" + 49 " Interaction bla {}" + 50 " }" + 51 "}", getTaskTree()); 52 53 simulateInteraction(element1, interaction1); 54 new TaskTreeChecker().assertTaskTree 55 ("Sequence sequence1 {" + 56 " Iteration iteration1 {" + 57 " Interaction bla {}" + 58 " }" + 59 "}", getTaskTree()); 60 61 for (int i = 0; i < 10; i++) 62 { 63 simulateInteraction(element1, interaction1); 23 public class DefaultIterationDetectionRuleTest extends AbstractTemporalRelationshipTC { 24 25 /** 26 * 27 */ 28 @Test 29 public void testInteractionIterationDetection() throws Exception { 30 IEventTarget element1 = new DummyGUIElement("elem1"); 31 IEventType event1 = new DummyInteraction("bla", 1); 32 simulateEvent(event1, element1); 33 new TaskTreeChecker().assertTaskTree 34 ("Sequence sequence1 {" + 35 " Event bla {}" + 36 "}", getTaskTree()); 37 38 simulateEvent(event1, element1); 39 new TaskTreeChecker().assertTaskTree 40 ("Sequence sequence1 {" + 41 " Iteration iteration1 {" + 42 " Event bla {}" + 43 " }" + 44 "}", getTaskTree()); 45 46 simulateEvent(event1, element1); 47 new TaskTreeChecker().assertTaskTree 48 ("Sequence sequence1 {" + 49 " Iteration iteration1 {" + 50 " Event bla {}" + 51 " }" + 52 "}", getTaskTree()); 53 54 for (int i = 0; i < 10; i++) { 55 simulateEvent(event1, element1); 56 } 57 58 new TaskTreeChecker().assertTaskTree 59 ("Sequence sequence1 {" + 60 " Iteration iteration1 {" + 61 " Event bla {}" + 62 " }" + 63 "}", getTaskTree()); 64 65 // now test with preceding and trailing other events 66 IEventType event2 = new DummyInteraction("bli", 1); 67 IEventType event3 = new DummyInteraction("blup", 1); 68 69 simulateEvent(event2, element1); 70 simulateEvent(event3, element1); 71 for (int i = 0; i < 10; i++) { 72 simulateEvent(event1, element1); 73 } 74 simulateEvent(event3, element1); 75 simulateEvent(event2, element1); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence1 {" + 79 " Iteration iteration1 {" + 80 " Event bla {}" + 81 " }" + 82 " Event bli {}" + 83 " Event blup {}" + 84 " Iteration iteration2 {" + 85 " Event bla {}" + 86 " }" + 87 " Event blup {}" + 88 " Event bli {}" + 89 "}", getTaskTree()); 90 91 // now test with iterations of iterations 92 93 for (int i = 0; i < 10; i++) { 94 for (int j = 0; j < 5; j++) { 95 simulateEvent(event1, element1); 96 } 97 for (int j = 0; j < 5; j++) { 98 simulateEvent(event2, element1); 99 } 100 for (int j = 0; j < 5; j++) { 101 simulateEvent(event3, element1); 102 } 103 } 104 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence1 {" + 107 " Iteration iteration1 {" + 108 " Event bla {}" + 109 " }" + 110 " Event bli {}" + 111 " Event blup {}" + 112 " Iteration iteration2 {" + 113 " Event bla {}" + 114 " }" + 115 " Event blup {}" + 116 " Event bli {}" + 117 " Iteration iteration3 {" + 118 " Sequence sequence2 {" + 119 " Iteration iteration4 {" + 120 " Event bla {}" + 121 " }" + 122 " Iteration iteration5 {" + 123 " Event bli {}" + 124 " }" + 125 " Iteration iteration6 {" + 126 " Event blup {}" + 127 " }" + 128 " }" + 129 " }" + 130 "}", getTaskTree()); 131 64 132 } 65 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence1 {" + 68 " Iteration iteration1 {" + 69 " Interaction bla {}" + 70 " }" + 71 "}", getTaskTree()); 72 73 // now test with preceding and trailing other interactions 74 Interaction interaction2 = new DummyInteraction("bli", 1); 75 Interaction interaction3 = new DummyInteraction("blup", 1); 76 77 simulateInteraction(element1, interaction2); 78 simulateInteraction(element1, interaction3); 79 for (int i = 0; i < 10; i++) 80 { 81 simulateInteraction(element1, interaction1); 133 134 /** 135 * 136 */ 137 @Test 138 public void testSequenceIterationDetection() throws Exception { 139 IEventTarget element1 = new DummyGUIElement("elem1"); 140 IEventType event1 = new DummyInteraction("bla", 1); 141 IEventType event2 = new DummyInteraction("bli", 1); 142 IEventType event3 = new DummyInteraction("blup", 1); 143 simulateEvent(event1, element1); 144 simulateEvent(event2, element1); 145 simulateEvent(event3, element1); 146 new TaskTreeChecker().assertTaskTree 147 ("Sequence sequence1 {" + 148 " Event bla {}" + 149 " Event bli {}" + 150 " Event blup {}" + 151 "}", getTaskTree()); 152 153 simulateEvent(event1, element1); 154 simulateEvent(event2, element1); 155 simulateEvent(event3, element1); 156 new TaskTreeChecker().assertTaskTree 157 ("Sequence sequence1 {" + 158 " Iteration iteration1 {" + 159 " Sequence sequence2 {" + 160 " Event bla {}" + 161 " Event bli {}" + 162 " Event blup {}" + 163 " }" + 164 " }" + 165 "}", getTaskTree()); 166 167 simulateEvent(event1, element1); 168 simulateEvent(event2, element1); 169 simulateEvent(event3, element1); 170 new TaskTreeChecker().assertTaskTree 171 ("Sequence sequence1 {" + 172 " Iteration iteration1 {" + 173 " Sequence sequence2 {" + 174 " Event bla {}" + 175 " Event bli {}" + 176 " Event blup {}" + 177 " }" + 178 " }" + 179 "}", getTaskTree()); 180 181 for (int i = 0; i < 10; i++) { 182 simulateEvent(event1, element1); 183 simulateEvent(event2, element1); 184 simulateEvent(event3, element1); 185 } 186 187 new TaskTreeChecker().assertTaskTree 188 ("Sequence sequence1 {" + 189 " Iteration iteration1 {" + 190 " Sequence sequence2 {" + 191 " Event bla {}" + 192 " Event bli {}" + 193 " Event blup {}" + 194 " }" + 195 " }" + 196 "}", getTaskTree()); 197 198 // now test with preceding and trailing other events 199 IEventType event4 = new DummyInteraction("ble", 1); 200 IEventType event5 = new DummyInteraction("blo", 1); 201 IEventType event6 = new DummyInteraction("blu", 1); 202 simulateEvent(event4, element1); 203 simulateEvent(event5, element1); 204 simulateEvent(event6, element1); 205 for (int i = 0; i < 10; i++) { 206 simulateEvent(event1, element1); 207 simulateEvent(event2, element1); 208 simulateEvent(event3, element1); 209 } 210 simulateEvent(event6, element1); 211 simulateEvent(event5, element1); 212 simulateEvent(event4, element1); 213 214 new TaskTreeChecker().assertTaskTree 215 ("Sequence sequence1 {" + 216 " Iteration iteration1 {" + 217 " Sequence sequence2 {" + 218 " Event bla {}" + 219 " Event bli {}" + 220 " Event blup {}" + 221 " }" + 222 " }" + 223 " Event ble {}" + 224 " Event blo {}" + 225 " Event blu {}" + 226 " Iteration iteration2 {" + 227 " Sequence sequence3 {" + 228 " Event bla {}" + 229 " Event bli {}" + 230 " Event blup {}" + 231 " }" + 232 " }" + 233 " Event blu {}" + 234 " Event blo {}" + 235 " Event ble {}" + 236 "}", getTaskTree()); 237 238 // now test with iterations of iterations 239 for (int i = 0; i < 10; i++) { 240 for (int j = 0; j < 5; j++) { 241 simulateEvent(event1, element1); 242 simulateEvent(event2, element1); 243 simulateEvent(event3, element1); 244 } 245 for (int j = 0; j < 5; j++) { 246 simulateEvent(event2, element1); 247 simulateEvent(event1, element1); 248 simulateEvent(event3, element1); 249 } 250 for (int j = 0; j < 5; j++) { 251 simulateEvent(event1, element1); 252 simulateEvent(event2, element1); 253 simulateEvent(event3, element1); 254 } 255 } 256 257 new TaskTreeChecker().assertTaskTree 258 ("Sequence sequence1 {" + 259 " Iteration iteration1 {" + 260 " Sequence sequence2 {" + 261 " Event bla {}" + 262 " Event bli {}" + 263 " Event blup {}" + 264 " }" + 265 " }" + 266 " Event ble {}" + 267 " Event blo {}" + 268 " Event blu {}" + 269 " Iteration iteration2 {" + 270 " Sequence sequence3 {" + 271 " Event bla {}" + 272 " Event bli {}" + 273 " Event blup {}" + 274 " }" + 275 " }" + 276 " Event blu {}" + 277 " Event blo {}" + 278 " Event ble {}" + 279 " Iteration iteration3 {" + 280 " Sequence sequence4 {" + 281 " Iteration iteration4 {" + 282 " Sequence sequence4 {" + 283 " Event bla {}" + 284 " Event bli {}" + 285 " Event blup {}" + 286 " }" + 287 " }" + 288 " Iteration iteration5 {" + 289 " Sequence sequence5 {" + 290 " Event bli {}" + 291 " Event bla {}" + 292 " Event blup {}" + 293 " }" + 294 " }" + 295 " Iteration iteration6 {" + 296 " Sequence sequence6 {" + 297 " Event bla {}" + 298 " Event bli {}" + 299 " Event blup {}" + 300 " }" + 301 " }" + 302 " }" + 303 " }" + 304 "}", getTaskTree()); 82 305 } 83 simulateInteraction(element1, interaction3); 84 simulateInteraction(element1, interaction2); 85 86 new TaskTreeChecker().assertTaskTree 87 ("Sequence sequence1 {" + 88 " Iteration iteration1 {" + 89 " Interaction bla {}" + 90 " }" + 91 " Interaction bli {}" + 92 " Interaction blup {}" + 93 " Iteration iteration2 {" + 94 " Interaction bla {}" + 95 " }" + 96 " Interaction blup {}" + 97 " Interaction bli {}" + 98 "}", getTaskTree()); 99 100 // now test with iterations of iterations 101 102 for (int i = 0; i < 10; i++) 103 { 104 for (int j = 0; j < 5; j++) 105 { 106 simulateInteraction(element1, interaction1); 107 } 108 for (int j = 0; j < 5; j++) 109 { 110 simulateInteraction(element1, interaction2); 111 } 112 for (int j = 0; j < 5; j++) 113 { 114 simulateInteraction(element1, interaction3); 115 } 116 } 117 118 new TaskTreeChecker().assertTaskTree 119 ("Sequence sequence1 {" + 120 " Iteration iteration1 {" + 121 " Interaction bla {}" + 122 " }" + 123 " Interaction bli {}" + 124 " Interaction blup {}" + 125 " Iteration iteration2 {" + 126 " Interaction bla {}" + 127 " }" + 128 " Interaction blup {}" + 129 " Interaction bli {}" + 130 " Iteration iteration3 {" + 131 " Sequence sequence2 {" + 132 " Iteration iteration4 {" + 133 " Interaction bla {}" + 134 " }" + 135 " Iteration iteration5 {" + 136 " Interaction bli {}" + 137 " }" + 138 " Iteration iteration6 {" + 139 " Interaction blup {}" + 140 " }" + 141 " }" + 142 " }" + 143 "}", getTaskTree()); 144 145 } 146 147 //----------------------------------------------------------------------------------------------- 148 /** 149 * 150 */ 151 //----------------------------------------------------------------------------------------------- 152 @Test 153 public void testSequenceIterationDetection() throws Exception 154 { 155 GUIElement element1 = new DummyGUIElement("elem1"); 156 Interaction interaction1 = new DummyInteraction("bla", 1); 157 Interaction interaction2 = new DummyInteraction("bli", 1); 158 Interaction interaction3 = new DummyInteraction("blup", 1); 159 simulateInteraction(element1, interaction1); 160 simulateInteraction(element1, interaction2); 161 simulateInteraction(element1, interaction3); 162 new TaskTreeChecker().assertTaskTree 163 ("Sequence sequence1 {" + 164 " Interaction bla {}" + 165 " Interaction bli {}" + 166 " Interaction blup {}" + 167 "}", getTaskTree()); 168 169 simulateInteraction(element1, interaction1); 170 simulateInteraction(element1, interaction2); 171 simulateInteraction(element1, interaction3); 172 new TaskTreeChecker().assertTaskTree 173 ("Sequence sequence1 {" + 174 " Iteration iteration1 {" + 175 " Sequence sequence2 {" + 176 " Interaction bla {}" + 177 " Interaction bli {}" + 178 " Interaction blup {}" + 179 " }" + 180 " }" + 181 "}", getTaskTree()); 182 183 simulateInteraction(element1, interaction1); 184 simulateInteraction(element1, interaction2); 185 simulateInteraction(element1, interaction3); 186 new TaskTreeChecker().assertTaskTree 187 ("Sequence sequence1 {" + 188 " Iteration iteration1 {" + 189 " Sequence sequence2 {" + 190 " Interaction bla {}" + 191 " Interaction bli {}" + 192 " Interaction blup {}" + 193 " }" + 194 " }" + 195 "}", getTaskTree()); 196 197 for (int i = 0; i < 10; i++) 198 { 199 simulateInteraction(element1, interaction1); 200 simulateInteraction(element1, interaction2); 201 simulateInteraction(element1, interaction3); 202 } 203 204 new TaskTreeChecker().assertTaskTree 205 ("Sequence sequence1 {" + 206 " Iteration iteration1 {" + 207 " Sequence sequence2 {" + 208 " Interaction bla {}" + 209 " Interaction bli {}" + 210 " Interaction blup {}" + 211 " }" + 212 " }" + 213 "}", getTaskTree()); 214 215 // now test with preceding and trailing other interactions 216 Interaction interaction4 = new DummyInteraction("ble", 1); 217 Interaction interaction5 = new DummyInteraction("blo", 1); 218 Interaction interaction6 = new DummyInteraction("blu", 1); 219 simulateInteraction(element1, interaction4); 220 simulateInteraction(element1, interaction5); 221 simulateInteraction(element1, interaction6); 222 for (int i = 0; i < 10; i++) 223 { 224 simulateInteraction(element1, interaction1); 225 simulateInteraction(element1, interaction2); 226 simulateInteraction(element1, interaction3); 227 } 228 simulateInteraction(element1, interaction6); 229 simulateInteraction(element1, interaction5); 230 simulateInteraction(element1, interaction4); 231 232 new TaskTreeChecker().assertTaskTree 233 ("Sequence sequence1 {" + 234 " Iteration iteration1 {" + 235 " Sequence sequence2 {" + 236 " Interaction bla {}" + 237 " Interaction bli {}" + 238 " Interaction blup {}" + 239 " }" + 240 " }" + 241 " Interaction ble {}" + 242 " Interaction blo {}" + 243 " Interaction blu {}" + 244 " Iteration iteration2 {" + 245 " Sequence sequence3 {" + 246 " Interaction bla {}" + 247 " Interaction bli {}" + 248 " Interaction blup {}" + 249 " }" + 250 " }" + 251 " Interaction blu {}" + 252 " Interaction blo {}" + 253 " Interaction ble {}" + 254 "}", getTaskTree()); 255 256 // now test with iterations of iterations 257 for (int i = 0; i < 10; i++) 258 { 259 for (int j = 0; j < 5; j++) 260 { 261 simulateInteraction(element1, interaction1); 262 simulateInteraction(element1, interaction2); 263 simulateInteraction(element1, interaction3); 264 } 265 for (int j = 0; j < 5; j++) 266 { 267 simulateInteraction(element1, interaction2); 268 simulateInteraction(element1, interaction1); 269 simulateInteraction(element1, interaction3); 270 } 271 for (int j = 0; j < 5; j++) 272 { 273 simulateInteraction(element1, interaction1); 274 simulateInteraction(element1, interaction2); 275 simulateInteraction(element1, interaction3); 276 } 277 } 278 279 new TaskTreeChecker().assertTaskTree 280 ("Sequence sequence1 {" + 281 " Iteration iteration1 {" + 282 " Sequence sequence2 {" + 283 " Interaction bla {}" + 284 " Interaction bli {}" + 285 " Interaction blup {}" + 286 " }" + 287 " }" + 288 " Interaction ble {}" + 289 " Interaction blo {}" + 290 " Interaction blu {}" + 291 " Iteration iteration2 {" + 292 " Sequence sequence3 {" + 293 " Interaction bla {}" + 294 " Interaction bli {}" + 295 " Interaction blup {}" + 296 " }" + 297 " }" + 298 " Interaction blu {}" + 299 " Interaction blo {}" + 300 " Interaction ble {}" + 301 " Iteration iteration3 {" + 302 " Sequence sequence4 {" + 303 " Iteration iteration4 {" + 304 " Sequence sequence4 {" + 305 " Interaction bla {}" + 306 " Interaction bli {}" + 307 " Interaction blup {}" + 308 " }" + 309 " }" + 310 " Iteration iteration5 {" + 311 " Sequence sequence5 {" + 312 " Interaction bli {}" + 313 " Interaction bla {}" + 314 " Interaction blup {}" + 315 " }" + 316 " }" + 317 " Iteration iteration6 {" + 318 " Sequence sequence6 {" + 319 " Interaction bla {}" + 320 " Interaction bli {}" + 321 " Interaction blup {}" + 322 " }" + 323 " }" + 324 " }" + 325 " }" + 326 "}", getTaskTree()); 327 } 328 306 329 307 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultMouseClickReductionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; … … 11 9 import org.junit.Test; 12 10 13 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;14 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonDown;15 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonInteraction;16 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonUp;17 import de.ugoe.cs.quest.eventcore. userinteraction.MouseClick;11 import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 12 import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 13 import de.ugoe.cs.quest.eventcore.gui.MouseButtonUp; 14 import de.ugoe.cs.quest.eventcore.gui.MouseClick; 15 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 18 16 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 19 17 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 20 18 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 21 19 22 //-------------------------------------------------------------------------------------------------23 20 /** 24 21 * TODO comment 25 * 22 * 26 23 * @version $Revision: $ $Date: $ 27 * @author 24 * @author 2011, last modified by $Author: $ 28 25 */ 29 //------------------------------------------------------------------------------------------------- 30 public class DefaultMouseClickReductionRuleTest extends AbstractTemporalRelationshipTC 31 { 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Test 38 public void testMouseClickInOneSequenceElement() 39 { 40 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 41 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 42 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 43 44 GUIElement element1 = new DummyGUIElement("elem1"); 45 GUIElement element2 = new DummyGUIElement("elem1"); 46 47 simulateInteraction(element1, new MouseButtonDown(leftBtn)); 48 simulateInteraction(element1, new MouseButtonUp(leftBtn)); 49 simulateInteraction(element1, new MouseClick(leftBtn)); 26 public class DefaultMouseClickReductionRuleTest extends AbstractTemporalRelationshipTC { 50 27 51 new TaskTreeChecker().assertTaskTree 52 ("Sequence sequence {" + 53 " Interaction LeftMouseClick {}" + 54 "}", getTaskTree()); 55 56 simulateInteraction(element1, new DummyInteraction("bla", 1)); 57 simulateInteraction(element1, new DummyInteraction("bli", 1)); 58 simulateInteraction(element1, new MouseButtonDown(middleBtn)); 59 simulateInteraction(element1, new MouseButtonUp(middleBtn)); 60 simulateInteraction(element1, new MouseClick(middleBtn)); 61 simulateInteraction(element1, new DummyInteraction("blo", 1)); 62 simulateInteraction(element1, new DummyInteraction("blu", 1)); 28 /** 29 * 30 */ 31 @Test 32 public void testMouseClickInOneSequenceElement() { 33 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 34 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 35 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 63 36 64 new TaskTreeChecker().assertTaskTree 65 ("Sequence sequence {" + 66 " Interaction LeftMouseClick {}" + 67 " Interaction bla {}" + 68 " Interaction bli {}" + 69 " Interaction MiddleMouseClick {}" + 70 " Interaction blo {}" + 71 " Interaction blu {}" + 72 "}", getTaskTree()); 37 IGUIElement element1 = new DummyGUIElement("elem1"); 38 IGUIElement element2 = new DummyGUIElement("elem1"); 73 39 74 simulateInteraction(element2, new DummyInteraction("bla", 1)); 75 simulateInteraction(element2, new DummyInteraction("bli", 1)); 76 simulateInteraction(element2, new MouseButtonDown(rightBtn)); 77 simulateInteraction(element2, new MouseButtonUp(rightBtn)); 78 simulateInteraction(element2, new MouseClick(rightBtn)); 79 simulateInteraction(element2, new DummyInteraction("blo", 1)); 80 simulateInteraction(element2, new DummyInteraction("blu", 1)); 40 simulateEvent(new MouseButtonDown(leftBtn), element1); 41 simulateEvent(new MouseButtonUp(leftBtn), element1); 42 simulateEvent(new MouseClick(leftBtn), element1); 81 43 82 new TaskTreeChecker().assertTaskTree 83 ("Sequence sequence0 {" + 84 " Sequence sequence1 {" + 85 " Interaction LeftMouseClick {}" + 86 " Interaction bla {}" + 87 " Interaction bli {}" + 88 " Interaction MiddleMouseClick {}" + 89 " Interaction blo {}" + 90 " Interaction blu {}" + 91 " }" + 92 " Sequence sequence2 {" + 93 " Interaction bla {}" + 94 " Interaction bli {}" + 95 " Interaction RightMouseClick {}" + 96 " Interaction blo {}" + 97 " Interaction blu {}" + 98 " }" + 99 "}", getTaskTree()); 44 new TaskTreeChecker().assertTaskTree 45 ("Sequence sequence {" + 46 " Event LeftMouseClick {}" + 47 "}", getTaskTree()); 100 48 101 simulateInteraction(element1, new MouseButtonDown(leftBtn)); 102 simulateInteraction(element1, new MouseButtonUp(leftBtn)); 103 simulateInteraction(element2, new MouseClick(leftBtn)); 49 simulateEvent(new DummyInteraction("bla", 1), element1); 50 simulateEvent(new DummyInteraction("bli", 1), element1); 51 simulateEvent(new MouseButtonDown(middleBtn), element1); 52 simulateEvent(new MouseButtonUp(middleBtn), element1); 53 simulateEvent(new MouseClick(middleBtn), element1); 54 simulateEvent(new DummyInteraction("blo", 1), element1); 55 simulateEvent(new DummyInteraction("blu", 1), element1); 104 56 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence0 {" + 107 " Sequence sequence1 {" + 108 " Interaction LeftMouseClick {}" + 109 " Interaction bla {}" + 110 " Interaction bli {}" + 111 " Interaction MiddleMouseClick {}" + 112 " Interaction blo {}" + 113 " Interaction blu {}" + 114 " }" + 115 " Sequence sequence2 {" + 116 " Interaction bla {}" + 117 " Interaction bli {}" + 118 " Interaction RightMouseClick {}" + 119 " Interaction blo {}" + 120 " Interaction blu {}" + 121 " }" + 122 " Sequence sequence3 {" + 123 " Interaction LeftMouseButtonDown {}" + 124 " Interaction LeftMouseButtonUp {}" + 125 " }" + 126 " Sequence sequence4 {" + 127 " Interaction LeftMouseClick {}" + 128 " }" + 129 "}", getTaskTree()); 57 new TaskTreeChecker().assertTaskTree 58 ("Sequence sequence {" + 59 " Event LeftMouseClick {}" + 60 " Event bla {}" + 61 " Event bli {}" + 62 " Event MiddleMouseClick {}" + 63 " Event blo {}" + 64 " Event blu {}" + 65 "}", getTaskTree()); 130 66 131 simulateInteraction(element1, new MouseButtonDown(middleBtn)); 132 simulateInteraction(element1, new MouseButtonUp(middleBtn)); 133 simulateInteraction(element1, new MouseClick(rightBtn)); 134 simulateInteraction(element2, new DummyInteraction("bla", 1)); 67 simulateEvent(new DummyInteraction("bla", 1), element2); 68 simulateEvent(new DummyInteraction("bli", 1), element2); 69 simulateEvent(new MouseButtonDown(rightBtn), element2); 70 simulateEvent(new MouseButtonUp(rightBtn), element2); 71 simulateEvent(new MouseClick(rightBtn), element2); 72 simulateEvent(new DummyInteraction("blo", 1), element2); 73 simulateEvent(new DummyInteraction("blu", 1), element2); 135 74 136 new TaskTreeChecker().assertTaskTree 137 ("Sequence sequence0 {" + 138 " Sequence sequence1 {" + 139 " Interaction LeftMouseClick {}" + 140 " Interaction bla {}" + 141 " Interaction bli {}" + 142 " Interaction MiddleMouseClick {}" + 143 " Interaction blo {}" + 144 " Interaction blu {}" + 145 " }" + 146 " Sequence sequence2 {" + 147 " Interaction bla {}" + 148 " Interaction bli {}" + 149 " Interaction RightMouseClick {}" + 150 " Interaction blo {}" + 151 " Interaction blu {}" + 152 " }" + 153 " Sequence sequence3 {" + 154 " Interaction LeftMouseButtonDown {}" + 155 " Interaction LeftMouseButtonUp {}" + 156 " }" + 157 " Sequence sequence4 {" + 158 " Interaction LeftMouseClick {}" + 159 " }" + 160 " Sequence sequence5 {" + 161 " Sequence sequence6 {" + 162 " Interaction MiddleMouseButtonDown {}" + 163 " Interaction MiddleMouseButtonUp {}" + 164 " }" + 165 " Interaction RightMouseClick {}" + 166 " }" + 167 " Sequence sequence7 {" + 168 " Interaction bla {}" + 169 " }" + 170 "}", getTaskTree()); 75 new TaskTreeChecker().assertTaskTree 76 ("Sequence sequence0 {" + 77 " Sequence sequence1 {" + 78 " Event LeftMouseClick {}" + 79 " Event bla {}" + 80 " Event bli {}" + 81 " Event MiddleMouseClick {}" + 82 " Event blo {}" + 83 " Event blu {}" + 84 " }" + 85 " Sequence sequence2 {" + 86 " Event bla {}" + 87 " Event bli {}" + 88 " Event RightMouseClick {}" + 89 " Event blo {}" + 90 " Event blu {}" + 91 " }" + 92 "}", getTaskTree()); 171 93 172 } 173 94 simulateEvent(new MouseButtonDown(leftBtn), element1); 95 simulateEvent(new MouseButtonUp(leftBtn), element1); 96 simulateEvent(new MouseClick(leftBtn), element2); 97 98 new TaskTreeChecker().assertTaskTree 99 ("Sequence sequence0 {" + 100 " Sequence sequence1 {" + 101 " Event LeftMouseClick {}" + 102 " Event bla {}" + 103 " Event bli {}" + 104 " Event MiddleMouseClick {}" + 105 " Event blo {}" + 106 " Event blu {}" + 107 " }" + 108 " Sequence sequence2 {" + 109 " Event bla {}" + 110 " Event bli {}" + 111 " Event RightMouseClick {}" + 112 " Event blo {}" + 113 " Event blu {}" + 114 " }" + 115 " Sequence sequence3 {" + 116 " Event LeftMouseButtonDown {}" + 117 " Event LeftMouseButtonUp {}" + 118 " }" + 119 " Sequence sequence4 {" + 120 " Event LeftMouseClick {}" + 121 " }" + 122 "}", getTaskTree()); 123 124 simulateEvent(new MouseButtonDown(middleBtn), element1); 125 simulateEvent(new MouseButtonUp(middleBtn), element1); 126 simulateEvent(new MouseClick(rightBtn), element1); 127 simulateEvent(new DummyInteraction("bla", 1), element2); 128 129 new TaskTreeChecker().assertTaskTree 130 ("Sequence sequence0 {" + 131 " Sequence sequence1 {" + 132 " Event LeftMouseClick {}" + 133 " Event bla {}" + 134 " Event bli {}" + 135 " Event MiddleMouseClick {}" + 136 " Event blo {}" + 137 " Event blu {}" + 138 " }" + 139 " Sequence sequence2 {" + 140 " Event bla {}" + 141 " Event bli {}" + 142 " Event RightMouseClick {}" + 143 " Event blo {}" + 144 " Event blu {}" + 145 " }" + 146 " Sequence sequence3 {" + 147 " Event LeftMouseButtonDown {}" + 148 " Event LeftMouseButtonUp {}" + 149 " }" + 150 " Sequence sequence4 {" + 151 " Event LeftMouseClick {}" + 152 " }" + 153 " Sequence sequence5 {" + 154 " Sequence sequence6 {" + 155 " Event MiddleMouseButtonDown {}" + 156 " Event MiddleMouseButtonUp {}" + 157 " }" + 158 " Event RightMouseClick {}" + 159 " }" + 160 " Sequence sequence7 {" + 161 " Event bla {}" + 162 " }" + 163 "}", getTaskTree()); 164 165 } 166 174 167 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;13 import de.ugoe.cs.quest.eventcore.gui model.TextField;14 import de.ugoe.cs.quest.eventcore. userinteraction.KeyPressed;15 import de.ugoe.cs.quest.eventcore. userinteraction.KeyReleased;11 import de.ugoe.cs.quest.eventcore.gui.KeyPressed; 12 import de.ugoe.cs.quest.eventcore.gui.KeyReleased; 13 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 14 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 17 16 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 17 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 19 18 20 //-------------------------------------------------------------------------------------------------21 19 /** 22 20 * TODO comment … … 25 23 * @author 2012, last modified by $Author: patrick$ 26 24 */ 27 //------------------------------------------------------------------------------------------------- 28 public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC 29 { 30 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * 34 */ 35 //----------------------------------------------------------------------------------------------- 36 @Test 37 public void testSimpleTextEntry() 38 { 39 GUIElement element1 = new DummyTextField("elem1"); 40 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 41 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 42 new TaskTreeChecker(true).assertTaskTree 43 ("Sequence sequence0 {" + 44 " TextInputInteraction TextInput a {" + 45 " Interaction KeyPressed LETTER_A {}" + 46 " Interaction KeyReleased LETTER_A {}" + 47 " }" + 48 "}", getTaskTree()); 49 50 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B)); 51 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B)); 52 new TaskTreeChecker().assertTaskTree 53 ("Sequence sequence0 {" + 54 " TextInputInteraction TextInput ab {" + 55 " Interaction KeyPressed LETTER_A {}" + 56 " Interaction KeyReleased LETTER_A {}" + 57 " Interaction KeyPressed LETTER_B {}" + 58 " Interaction KeyReleased LETTER_B {}" + 59 " }" + 60 "}", getTaskTree()); 61 62 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 63 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 64 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 65 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence0 {" + 68 " TextInputInteraction TextInput abC {" + 69 " Interaction KeyPressed LETTER_A {}" + 70 " Interaction KeyReleased LETTER_A {}" + 71 " Interaction KeyPressed LETTER_B {}" + 72 " Interaction KeyReleased LETTER_B {}" + 73 " Interaction KeyPressed SHIFT {}" + 74 " Interaction KeyPressed LETTER_C {}" + 75 " Interaction KeyReleased LETTER_C {}" + 76 " Interaction KeyReleased SHIFT {}" + 77 " }" + 78 "}", getTaskTree()); 79 80 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 81 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D)); 82 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D)); 83 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E)); 84 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E)); 85 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F)); 86 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F)); 87 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 88 new TaskTreeChecker().assertTaskTree 89 ("Sequence sequence0 {" + 90 " TextInputInteraction TextInput abCDEF {" + 91 " Interaction KeyPressed LETTER_A {}" + 92 " Interaction KeyReleased LETTER_A {}" + 93 " Interaction KeyPressed LETTER_B {}" + 94 " Interaction KeyReleased LETTER_B {}" + 95 " Interaction KeyPressed SHIFT {}" + 96 " Interaction KeyPressed LETTER_C {}" + 97 " Interaction KeyReleased LETTER_C {}" + 98 " Interaction KeyReleased SHIFT {}" + 99 " Interaction KeyPressed SHIFT {}" + 100 " Interaction KeyPressed LETTER_D {}" + 101 " Interaction KeyReleased LETTER_D {}" + 102 " Interaction KeyPressed LETTER_E {}" + 103 " Interaction KeyReleased LETTER_E {}" + 104 " Interaction KeyPressed LETTER_F {}" + 105 " Interaction KeyReleased LETTER_F {}" + 106 " Interaction KeyReleased SHIFT {}" + 107 " }" + 108 "}", getTaskTree()); 109 110 111 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 112 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 113 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G)); 114 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G)); 115 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 116 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 117 new TaskTreeChecker().assertTaskTree 118 ("Sequence sequence0 {" + 119 " TextInputInteraction TextInput abCDEFg {" + 120 " Interaction KeyPressed LETTER_A {}" + 121 " Interaction KeyReleased LETTER_A {}" + 122 " Interaction KeyPressed LETTER_B {}" + 123 " Interaction KeyReleased LETTER_B {}" + 124 " Interaction KeyPressed SHIFT {}" + 125 " Interaction KeyPressed LETTER_C {}" + 126 " Interaction KeyReleased LETTER_C {}" + 127 " Interaction KeyReleased SHIFT {}" + 128 " Interaction KeyPressed SHIFT {}" + 129 " Interaction KeyPressed LETTER_D {}" + 130 " Interaction KeyReleased LETTER_D {}" + 131 " Interaction KeyPressed LETTER_E {}" + 132 " Interaction KeyReleased LETTER_E {}" + 133 " Interaction KeyPressed LETTER_F {}" + 134 " Interaction KeyReleased LETTER_F {}" + 135 " Interaction KeyReleased SHIFT {}" + 136 " Interaction KeyPressed SHIFT {}" + 137 " Interaction KeyPressed SHIFT {}" + 138 " Interaction KeyPressed LETTER_G {}" + 139 " Interaction KeyReleased LETTER_G {}" + 140 " Interaction KeyReleased SHIFT {}" + 141 " Interaction KeyReleased SHIFT {}" + 142 " }" + 143 "}", getTaskTree()); 144 145 } 146 147 //----------------------------------------------------------------------------------------------- 148 /** 149 * 150 */ 151 //----------------------------------------------------------------------------------------------- 152 @Test 153 public void testTextEntryOnDifferentGuiElements() 154 { 155 GUIElement element1 = new DummyTextField("elem1"); 156 GUIElement element2 = new DummyTextField("elem2"); 157 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 158 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 159 new TaskTreeChecker().assertTaskTree 160 ("Sequence sequence0 {" + 161 " TextInputInteraction TextInput a {" + 162 " Interaction KeyPressed LETTER_A {}" + 163 " Interaction KeyReleased LETTER_A {}" + 164 " }" + 165 "}", getTaskTree()); 166 167 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_B)); 168 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_B)); 169 new TaskTreeChecker().assertTaskTree 170 ("Sequence sequence0 {" + 171 " Sequence sequence1 {" + 172 " TextInputInteraction TextInput a {" + 173 " Interaction KeyPressed LETTER_A {}" + 174 " Interaction KeyReleased LETTER_A {}" + 175 " }" + 176 " }" + 177 " Sequence sequence2 {" + 178 " TextInputInteraction TextInput b {" + 179 " Interaction KeyPressed LETTER_B {}" + 180 " Interaction KeyReleased LETTER_B {}" + 181 " }" + 182 " }" + 183 "}", getTaskTree()); 184 185 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 186 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 187 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 188 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 189 new TaskTreeChecker().assertTaskTree 190 ("Sequence sequence0 {" + 191 " Sequence sequence1 {" + 192 " TextInputInteraction TextInput a {" + 193 " Interaction KeyPressed LETTER_A {}" + 194 " Interaction KeyReleased LETTER_A {}" + 195 " }" + 196 " }" + 197 " Sequence sequence2 {" + 198 " TextInputInteraction TextInput b {" + 199 " Interaction KeyPressed LETTER_B {}" + 200 " Interaction KeyReleased LETTER_B {}" + 201 " }" + 202 " }" + 203 " Sequence sequence3 {" + 204 " TextInputInteraction TextInput C {" + 205 " Interaction KeyPressed SHIFT {}" + 206 " Interaction KeyPressed LETTER_C {}" + 207 " Interaction KeyReleased LETTER_C {}" + 208 " Interaction KeyReleased SHIFT {}" + 209 " }" + 210 " }" + 211 "}", getTaskTree()); 212 213 simulateInteraction(element2, new KeyPressed(VirtualKey.SHIFT)); 214 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_D)); 215 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_D)); 216 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_E)); 217 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_E)); 218 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_F)); 219 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_F)); 220 simulateInteraction(element2, new KeyReleased(VirtualKey.SHIFT)); 221 new TaskTreeChecker().assertTaskTree 222 ("Sequence sequence0 {" + 223 " Sequence sequence1 {" + 224 " TextInputInteraction TextInput a {" + 225 " Interaction KeyPressed LETTER_A {}" + 226 " Interaction KeyReleased LETTER_A {}" + 227 " }" + 228 " }" + 229 " Sequence sequence2 {" + 230 " TextInputInteraction TextInput b {" + 231 " Interaction KeyPressed LETTER_B {}" + 232 " Interaction KeyReleased LETTER_B {}" + 233 " }" + 234 " }" + 235 " Sequence sequence3 {" + 236 " TextInputInteraction TextInput C {" + 237 " Interaction KeyPressed SHIFT {}" + 238 " Interaction KeyPressed LETTER_C {}" + 239 " Interaction KeyReleased LETTER_C {}" + 240 " Interaction KeyReleased SHIFT {}" + 241 " }" + 242 " }" + 243 " Sequence sequence4 {" + 244 " TextInputInteraction TextInput DEF {" + 245 " Interaction KeyPressed SHIFT {}" + 246 " Interaction KeyPressed LETTER_D {}" + 247 " Interaction KeyReleased LETTER_D {}" + 248 " Interaction KeyPressed LETTER_E {}" + 249 " Interaction KeyReleased LETTER_E {}" + 250 " Interaction KeyPressed LETTER_F {}" + 251 " Interaction KeyReleased LETTER_F {}" + 252 " Interaction KeyReleased SHIFT {}" + 253 " }" + 254 " }" + 255 "}", getTaskTree()); 256 257 258 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 259 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 260 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G)); 261 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G)); 262 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 263 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 264 new TaskTreeChecker().assertTaskTree 265 ("Sequence sequence0 {" + 266 " Sequence sequence1 {" + 267 " TextInputInteraction TextInput a {" + 268 " Interaction KeyPressed LETTER_A {}" + 269 " Interaction KeyReleased LETTER_A {}" + 270 " }" + 271 " }" + 272 " Sequence sequence2 {" + 273 " TextInputInteraction TextInput b {" + 274 " Interaction KeyPressed LETTER_B {}" + 275 " Interaction KeyReleased LETTER_B {}" + 276 " }" + 277 " }" + 278 " Sequence sequence3 {" + 279 " TextInputInteraction TextInput C {" + 280 " Interaction KeyPressed SHIFT {}" + 281 " Interaction KeyPressed LETTER_C {}" + 282 " Interaction KeyReleased LETTER_C {}" + 283 " Interaction KeyReleased SHIFT {}" + 284 " }" + 285 " }" + 286 " Sequence sequence4 {" + 287 " TextInputInteraction TextInput DEF {" + 288 " Interaction KeyPressed SHIFT {}" + 289 " Interaction KeyPressed LETTER_D {}" + 290 " Interaction KeyReleased LETTER_D {}" + 291 " Interaction KeyPressed LETTER_E {}" + 292 " Interaction KeyReleased LETTER_E {}" + 293 " Interaction KeyPressed LETTER_F {}" + 294 " Interaction KeyReleased LETTER_F {}" + 295 " Interaction KeyReleased SHIFT {}" + 296 " }" + 297 " }" + 298 " Sequence sequence5 {" + 299 " TextInputInteraction TextInput g {" + 300 " Interaction KeyPressed SHIFT {}" + 301 " Interaction KeyPressed SHIFT {}" + 302 " Interaction KeyPressed LETTER_G {}" + 303 " Interaction KeyReleased LETTER_G {}" + 304 " Interaction KeyReleased SHIFT {}" + 305 " Interaction KeyReleased SHIFT {}" + 306 " }" + 307 " }" + 308 "}", getTaskTree()); 309 310 } 311 312 //----------------------------------------------------------------------------------------------- 313 /** 314 * 315 */ 316 //----------------------------------------------------------------------------------------------- 317 @Test 318 public void testUsageOfBackspace() 319 { 320 GUIElement element1 = new DummyTextField("elem1"); 321 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 322 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 323 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B)); 324 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B)); 325 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 326 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 327 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D)); 328 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D)); 329 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 330 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 331 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E)); 332 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E)); 333 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F)); 334 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F)); 335 new TaskTreeChecker().assertTaskTree 336 ("Sequence sequence0 {" + 337 " TextInputInteraction TextInput abcef {" + 338 " Interaction KeyPressed LETTER_A {}" + 339 " Interaction KeyReleased LETTER_A {}" + 340 " Interaction KeyPressed LETTER_B {}" + 341 " Interaction KeyReleased LETTER_B {}" + 342 " Interaction KeyPressed LETTER_C {}" + 343 " Interaction KeyReleased LETTER_C {}" + 344 " Interaction KeyPressed LETTER_D {}" + 345 " Interaction KeyReleased LETTER_D {}" + 346 " Interaction KeyPressed BACK_SPACE {}" + 347 " Interaction KeyReleased BACK_SPACE {}" + 348 " Interaction KeyPressed LETTER_E {}" + 349 " Interaction KeyReleased LETTER_E {}" + 350 " Interaction KeyPressed LETTER_F {}" + 351 " Interaction KeyReleased LETTER_F {}" + 352 " }" + 353 "}", getTaskTree()); 354 355 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 356 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 357 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 358 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 359 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 360 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 361 new TaskTreeChecker().assertTaskTree 362 ("Sequence sequence0 {" + 363 " TextInputInteraction TextInput ab {" + 364 " Interaction KeyPressed LETTER_A {}" + 365 " Interaction KeyReleased LETTER_A {}" + 366 " Interaction KeyPressed LETTER_B {}" + 367 " Interaction KeyReleased LETTER_B {}" + 368 " Interaction KeyPressed LETTER_C {}" + 369 " Interaction KeyReleased LETTER_C {}" + 370 " Interaction KeyPressed LETTER_D {}" + 371 " Interaction KeyReleased LETTER_D {}" + 372 " Interaction KeyPressed BACK_SPACE {}" + 373 " Interaction KeyReleased BACK_SPACE {}" + 374 " Interaction KeyPressed LETTER_E {}" + 375 " Interaction KeyReleased LETTER_E {}" + 376 " Interaction KeyPressed LETTER_F {}" + 377 " Interaction KeyReleased LETTER_F {}" + 378 " Interaction KeyPressed BACK_SPACE {}" + 379 " Interaction KeyReleased BACK_SPACE {}" + 380 " Interaction KeyPressed BACK_SPACE {}" + 381 " Interaction KeyReleased BACK_SPACE {}" + 382 " Interaction KeyPressed BACK_SPACE {}" + 383 " Interaction KeyReleased BACK_SPACE {}" + 384 " }" + 385 "}", getTaskTree()); 386 387 } 388 389 //----------------------------------------------------------------------------------------------- 390 /** 391 * 392 */ 393 //----------------------------------------------------------------------------------------------- 394 private static class DummyTextField extends DummyGUIElement implements TextField 395 { 396 397 //--------------------------------------------------------------------------------------------- 25 public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC { 26 398 27 /** 399 * TODO: comment400 28 * 401 * @param name402 29 */ 403 //--------------------------------------------------------------------------------------------- 404 public DummyTextField(String name) 405 { 406 super(name); 30 @Test 31 public void testSimpleTextEntry() { 32 IGUIElement element1 = new DummyTextField("elem1"); 33 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 34 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 35 new TaskTreeChecker(true).assertTaskTree 36 ("Sequence sequence0 {" + 37 " TextInputEvent TextInput a {" + 38 " Event KeyPressed LETTER_A {}" + 39 " Event KeyReleased LETTER_A {}" + 40 " }" + 41 "}", getTaskTree()); 42 43 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 44 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 45 new TaskTreeChecker().assertTaskTree 46 ("Sequence sequence0 {" + 47 " TextInputEvent TextInput ab {" + 48 " Event KeyPressed LETTER_A {}" + 49 " Event KeyReleased LETTER_A {}" + 50 " Event KeyPressed LETTER_B {}" + 51 " Event KeyReleased LETTER_B {}" + 52 " }" + 53 "}", getTaskTree()); 54 55 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 56 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 57 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 58 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 59 new TaskTreeChecker().assertTaskTree 60 ("Sequence sequence0 {" + 61 " TextInputEvent TextInput abC {" + 62 " Event KeyPressed LETTER_A {}" + 63 " Event KeyReleased LETTER_A {}" + 64 " Event KeyPressed LETTER_B {}" + 65 " Event KeyReleased LETTER_B {}" + 66 " Event KeyPressed SHIFT {}" + 67 " Event KeyPressed LETTER_C {}" + 68 " Event KeyReleased LETTER_C {}" + 69 " Event KeyReleased SHIFT {}" + 70 " }" + 71 "}", getTaskTree()); 72 73 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 74 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element1); 75 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element1); 76 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element1); 77 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element1); 78 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element1); 79 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 80 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 81 new TaskTreeChecker().assertTaskTree 82 ("Sequence sequence0 {" + 83 " TextInputEvent TextInput abCDEF {" + 84 " Event KeyPressed LETTER_A {}" + 85 " Event KeyReleased LETTER_A {}" + 86 " Event KeyPressed LETTER_B {}" + 87 " Event KeyReleased LETTER_B {}" + 88 " Event KeyPressed SHIFT {}" + 89 " Event KeyPressed LETTER_C {}" + 90 " Event KeyReleased LETTER_C {}" + 91 " Event KeyReleased SHIFT {}" + 92 " Event KeyPressed SHIFT {}" + 93 " Event KeyPressed LETTER_D {}" + 94 " Event KeyReleased LETTER_D {}" + 95 " Event KeyPressed LETTER_E {}" + 96 " Event KeyReleased LETTER_E {}" + 97 " Event KeyPressed LETTER_F {}" + 98 " Event KeyReleased LETTER_F {}" + 99 " Event KeyReleased SHIFT {}" + 100 " }" + 101 "}", getTaskTree()); 102 103 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 104 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 105 simulateEvent(new KeyPressed(VirtualKey.LETTER_G), element1); 106 simulateEvent(new KeyReleased(VirtualKey.LETTER_G), element1); 107 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 108 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 109 new TaskTreeChecker().assertTaskTree 110 ("Sequence sequence0 {" + 111 " TextInputEvent TextInput abCDEFg {" + 112 " Event KeyPressed LETTER_A {}" + 113 " Event KeyReleased LETTER_A {}" + 114 " Event KeyPressed LETTER_B {}" + 115 " Event KeyReleased LETTER_B {}" + 116 " Event KeyPressed SHIFT {}" + 117 " Event KeyPressed LETTER_C {}" + 118 " Event KeyReleased LETTER_C {}" + 119 " Event KeyReleased SHIFT {}" + 120 " Event KeyPressed SHIFT {}" + 121 " Event KeyPressed LETTER_D {}" + 122 " Event KeyReleased LETTER_D {}" + 123 " Event KeyPressed LETTER_E {}" + 124 " Event KeyReleased LETTER_E {}" + 125 " Event KeyPressed LETTER_F {}" + 126 " Event KeyReleased LETTER_F {}" + 127 " Event KeyReleased SHIFT {}" + 128 " Event KeyPressed SHIFT {}" + 129 " Event KeyPressed SHIFT {}" + 130 " Event KeyPressed LETTER_G {}" + 131 " Event KeyReleased LETTER_G {}" + 132 " Event KeyReleased SHIFT {}" + 133 " Event KeyReleased SHIFT {}" + 134 " }" + 135 "}", getTaskTree()); 136 407 137 } 408 138 409 } 139 /** 140 * 141 */ 142 @Test 143 public void testTextEntryOnDifferentGuiElements() { 144 IGUIElement element1 = new DummyTextField("elem1"); 145 IGUIElement element2 = new DummyTextField("elem2"); 146 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 147 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 148 new TaskTreeChecker().assertTaskTree 149 ("Sequence sequence0 {" + 150 " TextInputEvent TextInput a {" + 151 " Event KeyPressed LETTER_A {}" + 152 " Event KeyReleased LETTER_A {}" + 153 " }" + 154 "}", getTaskTree()); 155 156 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element2); 157 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element2); 158 new TaskTreeChecker().assertTaskTree 159 ("Sequence sequence0 {" + 160 " Sequence sequence1 {" + 161 " TextInputEvent TextInput a {" + 162 " Event KeyPressed LETTER_A {}" + 163 " Event KeyReleased LETTER_A {}" + 164 " }" + 165 " }" + 166 " Sequence sequence2 {" + 167 " TextInputEvent TextInput b {" + 168 " Event KeyPressed LETTER_B {}" + 169 " Event KeyReleased LETTER_B {}" + 170 " }" + 171 " }" + 172 "}", getTaskTree()); 173 174 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 175 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 176 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 177 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 178 new TaskTreeChecker().assertTaskTree 179 ("Sequence sequence0 {" + 180 " Sequence sequence1 {" + 181 " TextInputEvent TextInput a {" + 182 " Event KeyPressed LETTER_A {}" + 183 " Event KeyReleased LETTER_A {}" + 184 " }" + 185 " }" + 186 " Sequence sequence2 {" + 187 " TextInputEvent TextInput b {" + 188 " Event KeyPressed LETTER_B {}" + 189 " Event KeyReleased LETTER_B {}" + 190 " }" + 191 " }" + 192 " Sequence sequence3 {" + 193 " TextInputEvent TextInput C {" + 194 " Event KeyPressed SHIFT {}" + 195 " Event KeyPressed LETTER_C {}" + 196 " Event KeyReleased LETTER_C {}" + 197 " Event KeyReleased SHIFT {}" + 198 " }" + 199 " }" + 200 "}", getTaskTree()); 201 202 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element2); 203 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element2); 204 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element2); 205 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element2); 206 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element2); 207 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element2); 208 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element2); 209 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element2); 210 new TaskTreeChecker().assertTaskTree 211 ("Sequence sequence0 {" + 212 " Sequence sequence1 {" + 213 " TextInputEvent TextInput a {" + 214 " Event KeyPressed LETTER_A {}" + 215 " Event KeyReleased LETTER_A {}" + 216 " }" + 217 " }" + 218 " Sequence sequence2 {" + 219 " TextInputEvent TextInput b {" + 220 " Event KeyPressed LETTER_B {}" + 221 " Event KeyReleased LETTER_B {}" + 222 " }" + 223 " }" + 224 " Sequence sequence3 {" + 225 " TextInputEvent TextInput C {" + 226 " Event KeyPressed SHIFT {}" + 227 " Event KeyPressed LETTER_C {}" + 228 " Event KeyReleased LETTER_C {}" + 229 " Event KeyReleased SHIFT {}" + 230 " }" + 231 " }" + 232 " Sequence sequence4 {" + 233 " TextInputEvent TextInput DEF {" + 234 " Event KeyPressed SHIFT {}" + 235 " Event KeyPressed LETTER_D {}" + 236 " Event KeyReleased LETTER_D {}" + 237 " Event KeyPressed LETTER_E {}" + 238 " Event KeyReleased LETTER_E {}" + 239 " Event KeyPressed LETTER_F {}" + 240 " Event KeyReleased LETTER_F {}" + 241 " Event KeyReleased SHIFT {}" + 242 " }" + 243 " }" + 244 "}", getTaskTree()); 245 246 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 247 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 248 simulateEvent(new KeyPressed(VirtualKey.LETTER_G), element1); 249 simulateEvent(new KeyReleased(VirtualKey.LETTER_G), element1); 250 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 251 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 252 new TaskTreeChecker().assertTaskTree 253 ("Sequence sequence0 {" + 254 " Sequence sequence1 {" + 255 " TextInputEvent TextInput a {" + 256 " Event KeyPressed LETTER_A {}" + 257 " Event KeyReleased LETTER_A {}" + 258 " }" + 259 " }" + 260 " Sequence sequence2 {" + 261 " TextInputEvent TextInput b {" + 262 " Event KeyPressed LETTER_B {}" + 263 " Event KeyReleased LETTER_B {}" + 264 " }" + 265 " }" + 266 " Sequence sequence3 {" + 267 " TextInputEvent TextInput C {" + 268 " Event KeyPressed SHIFT {}" + 269 " Event KeyPressed LETTER_C {}" + 270 " Event KeyReleased LETTER_C {}" + 271 " Event KeyReleased SHIFT {}" + 272 " }" + 273 " }" + 274 " Sequence sequence4 {" + 275 " TextInputEvent TextInput DEF {" + 276 " Event KeyPressed SHIFT {}" + 277 " Event KeyPressed LETTER_D {}" + 278 " Event KeyReleased LETTER_D {}" + 279 " Event KeyPressed LETTER_E {}" + 280 " Event KeyReleased LETTER_E {}" + 281 " Event KeyPressed LETTER_F {}" + 282 " Event KeyReleased LETTER_F {}" + 283 " Event KeyReleased SHIFT {}" + 284 " }" + 285 " }" + 286 " Sequence sequence5 {" + 287 " TextInputEvent TextInput g {" + 288 " Event KeyPressed SHIFT {}" + 289 " Event KeyPressed SHIFT {}" + 290 " Event KeyPressed LETTER_G {}" + 291 " Event KeyReleased LETTER_G {}" + 292 " Event KeyReleased SHIFT {}" + 293 " Event KeyReleased SHIFT {}" + 294 " }" + 295 " }" + 296 "}", getTaskTree()); 297 298 } 299 300 /** 301 * 302 */ 303 @Test 304 public void testUsageOfBackspace() { 305 IGUIElement element1 = new DummyTextField("elem1"); 306 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 307 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 308 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 309 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 310 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 311 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 312 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element1); 313 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element1); 314 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 315 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 316 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element1); 317 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element1); 318 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element1); 319 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 320 new TaskTreeChecker().assertTaskTree 321 ("Sequence sequence0 {" + 322 " TextInputEvent TextInput abcef {" + 323 " Event KeyPressed LETTER_A {}" + 324 " Event KeyReleased LETTER_A {}" + 325 " Event KeyPressed LETTER_B {}" + 326 " Event KeyReleased LETTER_B {}" + 327 " Event KeyPressed LETTER_C {}" + 328 " Event KeyReleased LETTER_C {}" + 329 " Event KeyPressed LETTER_D {}" + 330 " Event KeyReleased LETTER_D {}" + 331 " Event KeyPressed BACK_SPACE {}" + 332 " Event KeyReleased BACK_SPACE {}" + 333 " Event KeyPressed LETTER_E {}" + 334 " Event KeyReleased LETTER_E {}" + 335 " Event KeyPressed LETTER_F {}" + 336 " Event KeyReleased LETTER_F {}" + 337 " }" + 338 "}", getTaskTree()); 339 340 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 341 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 342 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 343 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 344 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 345 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 346 new TaskTreeChecker().assertTaskTree 347 ("Sequence sequence0 {" + 348 " TextInputEvent TextInput ab {" + 349 " Event KeyPressed LETTER_A {}" + 350 " Event KeyReleased LETTER_A {}" + 351 " Event KeyPressed LETTER_B {}" + 352 " Event KeyReleased LETTER_B {}" + 353 " Event KeyPressed LETTER_C {}" + 354 " Event KeyReleased LETTER_C {}" + 355 " Event KeyPressed LETTER_D {}" + 356 " Event KeyReleased LETTER_D {}" + 357 " Event KeyPressed BACK_SPACE {}" + 358 " Event KeyReleased BACK_SPACE {}" + 359 " Event KeyPressed LETTER_E {}" + 360 " Event KeyReleased LETTER_E {}" + 361 " Event KeyPressed LETTER_F {}" + 362 " Event KeyReleased LETTER_F {}" + 363 " Event KeyPressed BACK_SPACE {}" + 364 " Event KeyReleased BACK_SPACE {}" + 365 " Event KeyPressed BACK_SPACE {}" + 366 " Event KeyReleased BACK_SPACE {}" + 367 " Event KeyPressed BACK_SPACE {}" + 368 " Event KeyReleased BACK_SPACE {}" + 369 " }" + 370 "}", getTaskTree()); 371 372 } 373 374 /** 375 * 376 */ 377 private static class DummyTextField extends DummyGUIElement implements ITextField { 378 379 /** */ 380 private static final long serialVersionUID = 1L; 381 382 /** 383 * TODO: comment 384 * 385 * @param name 386 */ 387 public DummyTextField(String name) { 388 super(name); 389 } 390 391 } 410 392 411 393 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TrackBarSelectionDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;13 import de.ugoe.cs.quest.eventcore.guimodel. TrackBar;14 import de.ugoe.cs.quest.eventcore. userinteraction.ValueSelection;11 import de.ugoe.cs.quest.eventcore.gui.ValueSelection; 12 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 13 import de.ugoe.cs.quest.eventcore.guimodel.ITrackBar; 15 14 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 17 16 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 17 19 //-------------------------------------------------------------------------------------------------20 18 /** 21 19 * TODO comment … … 24 22 * @author 2012, last modified by $Author: patrick$ 25 23 */ 26 //------------------------------------------------------------------------------------------------- 27 public class TrackBarSelectionDetectionRuleTest extends AbstractTemporalRelationshipTC 28 { 24 public class TrackBarSelectionDetectionRuleTest extends AbstractTemporalRelationshipTC { 29 25 30 //-----------------------------------------------------------------------------------------------31 /**32 *33 */34 //-----------------------------------------------------------------------------------------------35 @Test36 public void testSimpleDetection() throws Exception37 {38 GUIElement element1 = new DummyTrackBar();39 simulateInteraction(element1, new ValueSelection<Integer>(1));40 new TaskTreeChecker().assertTaskTree41 ("Sequence sequence1 {" +42 " Iteration interation1 {" +43 " Selection selection1 {" +44 " Interaction ValueSelection {}" +45 " }" +46 " }" +47 "}", getTaskTree());48 49 simulateInteraction(element1, new ValueSelection<Integer>(2));50 new TaskTreeChecker().assertTaskTree51 ("Sequence sequence1 {" +52 " Iteration interation1 {" +53 " Selection selection1 {" +54 " Interaction ValueSelection {}" +55 " Interaction ValueSelection {}" +56 " }" +57 " }" +58 "}", getTaskTree());59 60 simulateInteraction(element1, new ValueSelection<Integer>(3));61 new TaskTreeChecker().assertTaskTree62 ("Sequence sequence1 {" +63 " Iteration interation1 {" +64 " Selection selection1 {" +65 " Interaction ValueSelection {}" +66 " Interaction ValueSelection {}" +67 " Interaction ValueSelection {}" +68 " }" +69 " }" +70 "}", getTaskTree());71 72 simulateInteraction(element1, new ValueSelection<Integer>(2));73 new TaskTreeChecker().assertTaskTree74 ("Sequence sequence1 {" +75 " Iteration interation1 {" +76 " Selection selection1 {" +77 " Interaction ValueSelection {}" +78 " Interaction ValueSelection {}" +79 " Interaction ValueSelection {}" +80 " }" +81 " }" +82 "}", getTaskTree());83 84 simulateInteraction(element1, new ValueSelection<Integer>(3));85 new TaskTreeChecker().assertTaskTree86 ("Sequence sequence1 {" +87 " Iteration interation1 {" +88 " Selection selection1 {" +89 " Interaction ValueSelection {}" +90 " Interaction ValueSelection {}" +91 " Interaction ValueSelection {}" +92 " }" +93 " }" +94 "}", getTaskTree());95 96 }97 98 //-----------------------------------------------------------------------------------------------99 /**100 *101 */102 //-----------------------------------------------------------------------------------------------103 @Test104 public void testComplexDetection() throws Exception105 {106 GUIElement element1 = new DummyTrackBar();107 simulateInteraction(element1, new ValueSelection<Integer>(1));108 simulateInteraction(element1, new ValueSelection<Integer>(2));109 simulateInteraction(element1, new ValueSelection<Integer>(3));110 simulateInteraction(element1, new ValueSelection<Integer>(1));111 simulateInteraction(element1, new DummyInteraction("bla", 1));112 simulateInteraction(element1, new DummyInteraction("bla", 2));113 simulateInteraction(element1, new ValueSelection<Integer>(2));114 simulateInteraction(element1, new ValueSelection<Integer>(1));115 simulateInteraction(element1, new DummyInteraction("bla", 3));116 simulateInteraction(element1, new ValueSelection<Integer>(3));117 simulateInteraction(element1, new ValueSelection<Integer>(2));118 simulateInteraction(element1, new ValueSelection<Integer>(3));119 simulateInteraction(element1, new DummyInteraction("bla", 1));120 simulateInteraction(element1, new DummyInteraction("bla", 2));121 simulateInteraction(element1, new ValueSelection<Integer>(1));122 simulateInteraction(element1, new ValueSelection<Integer>(1));123 124 new TaskTreeChecker().assertTaskTree125 ("Sequence sequence1 {" +126 " Iteration interation1 {" +127 " Selection selection1 {" +128 " Interaction ValueSelection {}" +129 " Interaction ValueSelection {}" +130 " Interaction ValueSelection {}" +131 " }" +132 " }" +133 " Interaction bla {}" +134 " Interaction bla {}" +135 " Iteration interation2 {" +136 " Selection selection2 {" +137 " Interaction ValueSelection {}" +138 " Interaction ValueSelection {}" +139 " }" +140 " }" +141 " Interaction bla {}" +142 " Iteration interation3 {" +143 " Selection selection3 {" +144 " Interaction ValueSelection {}" +145 " Interaction ValueSelection {}" +146 " }" +147 " }" +148 " Interaction bla {}" +149 " Interaction bla {}" +150 " Iteration interation4 {" +151 " Selection selection4 {" +152 " Interaction ValueSelection {}" +153 " }" +154 " }" +155 "}", getTaskTree());156 }157 158 //-----------------------------------------------------------------------------------------------159 /**160 * TODO comment161 *162 * @version $Revision: $ $Date: 28.04.2012$163 * @author 2012, last modified by $Author: patrick$164 */165 //-----------------------------------------------------------------------------------------------166 public class DummyTrackBar extends DummyGUIElement implements TrackBar167 {168 169 //---------------------------------------------------------------------------------------------170 26 /** 171 27 * 172 28 */ 173 //--------------------------------------------------------------------------------------------- 174 public DummyTrackBar() 175 { 176 super("DummyTrackBar"); 29 @Test 30 public void testSimpleDetection() throws Exception { 31 IGUIElement element1 = new DummyTrackBar(); 32 simulateEvent(new ValueSelection<Integer>(1), element1); 33 new TaskTreeChecker().assertTaskTree 34 ("Sequence sequence1 {" + 35 " Iteration interation1 {" + 36 " Selection selection1 {" + 37 " Event ValueSelection {}" + 38 " }" + 39 " }" + 40 "}", getTaskTree()); 41 42 simulateEvent(new ValueSelection<Integer>(2), element1); 43 new TaskTreeChecker().assertTaskTree 44 ("Sequence sequence1 {" + 45 " Iteration interation1 {" + 46 " Selection selection1 {" + 47 " Event ValueSelection {}" + 48 " Event ValueSelection {}" + 49 " }" + 50 " }" + 51 "}", getTaskTree()); 52 53 simulateEvent(new ValueSelection<Integer>(3), element1); 54 new TaskTreeChecker().assertTaskTree 55 ("Sequence sequence1 {" + 56 " Iteration interation1 {" + 57 " Selection selection1 {" + 58 " Event ValueSelection {}" + 59 " Event ValueSelection {}" + 60 " Event ValueSelection {}" + 61 " }" + 62 " }" + 63 "}", getTaskTree()); 64 65 simulateEvent(new ValueSelection<Integer>(2), element1); 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence1 {" + 68 " Iteration interation1 {" + 69 " Selection selection1 {" + 70 " Event ValueSelection {}" + 71 " Event ValueSelection {}" + 72 " Event ValueSelection {}" + 73 " }" + 74 " }" + 75 "}", getTaskTree()); 76 77 simulateEvent(new ValueSelection<Integer>(3), element1); 78 new TaskTreeChecker().assertTaskTree 79 ("Sequence sequence1 {" + 80 " Iteration interation1 {" + 81 " Selection selection1 {" + 82 " Event ValueSelection {}" + 83 " Event ValueSelection {}" + 84 " Event ValueSelection {}" + 85 " }" + 86 " }" + 87 "}", getTaskTree()); 88 177 89 } 178 } 90 91 /** 92 * 93 */ 94 @Test 95 public void testComplexDetection() throws Exception { 96 IGUIElement element1 = new DummyTrackBar(); 97 simulateEvent(new ValueSelection<Integer>(1), element1); 98 simulateEvent(new ValueSelection<Integer>(2), element1); 99 simulateEvent(new ValueSelection<Integer>(3), element1); 100 simulateEvent(new ValueSelection<Integer>(1), element1); 101 simulateEvent(new DummyInteraction("bla", 1), element1); 102 simulateEvent(new DummyInteraction("bla", 2), element1); 103 simulateEvent(new ValueSelection<Integer>(2), element1); 104 simulateEvent(new ValueSelection<Integer>(1), element1); 105 simulateEvent(new DummyInteraction("bla", 3), element1); 106 simulateEvent(new ValueSelection<Integer>(3), element1); 107 simulateEvent(new ValueSelection<Integer>(2), element1); 108 simulateEvent(new ValueSelection<Integer>(3), element1); 109 simulateEvent(new DummyInteraction("bla", 1), element1); 110 simulateEvent(new DummyInteraction("bla", 2), element1); 111 simulateEvent(new ValueSelection<Integer>(1), element1); 112 simulateEvent(new ValueSelection<Integer>(1), element1); 113 114 new TaskTreeChecker().assertTaskTree 115 ("Sequence sequence1 {" + 116 " Iteration interation1 {" + 117 " Selection selection1 {" + 118 " Event ValueSelection {}" + 119 " Event ValueSelection {}" + 120 " Event ValueSelection {}" + 121 " }" + 122 " }" + 123 " Event bla {}" + 124 " Event bla {}" + 125 " Iteration interation2 {" + 126 " Selection selection2 {" + 127 " Event ValueSelection {}" + 128 " Event ValueSelection {}" + 129 " }" + 130 " }" + 131 " Event bla {}" + 132 " Iteration interation3 {" + 133 " Selection selection3 {" + 134 " Event ValueSelection {}" + 135 " Event ValueSelection {}" + 136 " }" + 137 " }" + 138 " Event bla {}" + 139 " Event bla {}" + 140 " Iteration interation4 {" + 141 " Selection selection4 {" + 142 " Event ValueSelection {}" + 143 " }" + 144 " }" + 145 "}", getTaskTree()); 146 } 147 148 /** 149 * TODO comment 150 * 151 * @version $Revision: $ $Date: 28.04.2012$ 152 * @author 2012, last modified by $Author: patrick$ 153 */ 154 public class DummyTrackBar extends DummyGUIElement implements ITrackBar { 155 156 /** */ 157 private static final long serialVersionUID = 1L; 158 159 /** 160 * 161 */ 162 public DummyTrackBar() { 163 super("DummyTrackBar"); 164 } 165 } 179 166 180 167 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyGUIElement.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyGUIElement.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.testutils; 9 8 10 9 import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElement; 11 import de.ugoe.cs.quest.eventcore.guimodel. GUIElement;10 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 13 * TODO comment … … 18 16 * @author 2012, last modified by $Author: patrick$ 19 17 */ 20 //------------------------------------------------------------------------------------------------- 21 public class DummyGUIElement extends AbstractDefaultGUIElement 22 implements GUIElement 23 { 24 /** */ 25 private String mName; 18 public class DummyGUIElement extends AbstractDefaultGUIElement implements IGUIElement { 19 20 /** */ 21 private static final long serialVersionUID = 1L; 26 22 27 //--------------------------------------------------------------------------------------------- 28 /** 29 * 30 */ 31 //--------------------------------------------------------------------------------------------- 32 public DummyGUIElement(String name) 33 { 34 super(); 35 mName = name; 36 } 23 /** */ 24 private String name; 37 25 38 //----------------------------------------------------------------------------------------------- 39 /* (non-Javadoc) 40 * @see java.lang.Object#toString() 41 */ 42 //----------------------------------------------------------------------------------------------- 43 @Override 44 public String toString() 45 { 46 return mName; 47 } 26 /** 27 * 28 */ 29 public DummyGUIElement(String name) { 30 super(); 31 this.name = name; 32 } 48 33 49 //----------------------------------------------------------------------------------------------- 50 /* (non-Javadoc) 51 * @see de.harms.attef.userinteraction.GUIElement#equals(GUIElement) 52 */ 53 //----------------------------------------------------------------------------------------------- 54 public boolean equals(GUIElement other) 55 { 56 return this == other; 57 } 34 /* (non-Javadoc) 35 * @see de.ugoe.cs.quest.eventcore.IEventTarget#getPlatform() 36 */ 37 @Override 38 public String getPlatform() { 39 return "Dummy"; 40 } 41 42 /* 43 * (non-Javadoc) 44 * 45 * @see java.lang.Object#toString() 46 */ 47 @Override 48 public String toString() { 49 return name; 50 } 51 52 /* 53 * (non-Javadoc) 54 * 55 * @see de.harms.attef.userinteraction.GUIElement#equals(GUIElement) 56 */ 57 public boolean equals(IGUIElement other) { 58 return this == other; 59 } 58 60 59 61 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyInteraction.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyInteraction.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.testutils; 9 8 10 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.gui.IInteraction; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class DummyInteraction implements Interaction 21 { 22 /** */ 23 private int mInteractionNumber; 24 25 /** */ 26 private String mInteractionType; 27 28 //----------------------------------------------------------------------------------------------- 29 /** 30 * @param interactionNumber 31 * @param interactionType 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public DummyInteraction(String interactionType, int interactionNumber) 35 { 36 super(); 37 mInteractionNumber = interactionNumber; 38 mInteractionType = interactionType; 39 } 17 public class DummyInteraction implements IInteraction { 18 19 /** */ 20 private static final long serialVersionUID = 1L; 40 21 41 //----------------------------------------------------------------------------------------------- 42 /* (non-Javadoc) 43 * @see de.harms.attef.userinteraction.Interaction#getName() 44 */ 45 //----------------------------------------------------------------------------------------------- 46 public String getName() 47 { 48 return mInteractionType; 49 } 22 /** */ 23 private int interactionNumber; 50 24 51 //----------------------------------------------------------------------------------------------- 52 /* (non-Javadoc) 53 * @see java.lang.Object#toString() 54 */ 55 //----------------------------------------------------------------------------------------------- 56 @Override 57 public String toString() 58 { 59 return mInteractionType; 60 } 25 /** */ 26 private String interactionType; 61 27 62 //-----------------------------------------------------------------------------------------------63 /* (non-Javadoc)64 * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()65 */66 //-----------------------------------------------------------------------------------------------67 public boolean startsLogicalSequence()68 {69 return false;70 }28 /** 29 * @param interactionNumber 30 * @param interactionType 31 */ 32 public DummyInteraction(String interactionType, int interactionNumber) { 33 super(); 34 this.interactionNumber = interactionNumber; 35 this.interactionType = interactionType; 36 } 71 37 72 //----------------------------------------------------------------------------------------------- 73 /* (non-Javadoc) 74 * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence() 75 */ 76 //----------------------------------------------------------------------------------------------- 77 public boolean finishesLogicalSequence() 78 { 79 return false; 80 } 38 /* 39 * (non-Javadoc) 40 * 41 * @see de.harms.attef.userinteraction.Interaction#getName() 42 */ 43 public String getName() { 44 return interactionType; 45 } 81 46 82 //-----------------------------------------------------------------------------------------------83 /**84 * @return the interactionType85 */86 //-----------------------------------------------------------------------------------------------87 public String getInteractionType()88 {89 return mInteractionType;90 }47 /* 48 * (non-Javadoc) 49 * 50 * @see java.lang.Object#toString() 51 */ 52 @Override 53 public String toString() { 54 return interactionType; 55 } 91 56 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * @return the interactionNumber 95 */ 96 //----------------------------------------------------------------------------------------------- 97 public int getInteractionNumber() 98 { 99 return mInteractionNumber; 100 } 57 /* 58 * (non-Javadoc) 59 * 60 * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence() 61 */ 62 public boolean startsLogicalSequence() { 63 return false; 64 } 65 66 /* 67 * (non-Javadoc) 68 * 69 * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence() 70 */ 71 public boolean finishesLogicalSequence() { 72 return false; 73 } 74 75 /** 76 * @return the interactionType 77 */ 78 public String getInteractionType() { 79 return interactionType; 80 } 81 82 /** 83 * @return the interactionNumber 84 */ 85 public int getInteractionNumber() { 86 return interactionNumber; 87 } 101 88 102 89 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyTextField.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyGUIElement.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.testutils; 9 9 10 import de.ugoe.cs.quest.eventcore.guimodel. TextField;10 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 11 11 12 //-------------------------------------------------------------------------------------------------13 12 /** 14 13 * TODO comment … … 17 16 * @author 2012, last modified by $Author: patrick$ 18 17 */ 19 //------------------------------------------------------------------------------------------------- 20 public class DummyTextField extends DummyGUIElement 21 implements TextField 22 { 18 public class DummyTextField extends DummyGUIElement implements ITextField { 23 19 24 //---------------------------------------------------------------------------------------------25 /**26 * 27 */28 //---------------------------------------------------------------------------------------------29 public DummyTextField(String name)30 {31 super("text field \"" + name + "\"");32 }20 /** */ 21 private static final long serialVersionUID = 1L; 22 23 /** 24 * 25 */ 26 public DummyTextField(String name) { 27 super("text field \"" + name + "\""); 28 } 33 29 34 30 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/SimpleLogFormatter.java
r445 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TestLogger.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 26.11.2011 15:26:38 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.testutils; … … 16 14 import java.util.logging.LogRecord; 17 15 18 19 //-------------------------------------------------------------------------------------------------20 16 /** 21 17 * TODO comment 22 * 18 * 23 19 * @version $Revision: $ $Date: $ 24 * @author 20 * @author 2011, last modified by $Author: $ 25 21 */ 26 //------------------------------------------------------------------------------------------------- 22 public class SimpleLogFormatter extends Formatter { 27 23 28 public class SimpleLogFormatter extends Formatter 29 { 30 //----------------------------------------------------------------------------------------------- 31 /** 32 * 33 */ 34 //----------------------------------------------------------------------------------------------- 35 @Override 36 public String format(LogRecord record) 37 { 38 StringBuffer result = new StringBuffer(); 39 result.append(record.getLevel().getName().charAt(0)); 40 result.append(" | "); 41 result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis())); 42 result.append(" | "); 43 tailValue("" + record.getThreadID(), 6, result); 44 result.append(" | "); 45 tailValue(record.getLoggerName(), 30, result); 46 result.append(" | "); 47 result.append(record.getMessage()); 48 49 if (record.getThrown() != null) 50 { 51 ByteArrayOutputStream out = new ByteArrayOutputStream(); 52 record.getThrown().printStackTrace(new PrintStream(out)); 53 result.append("\n"); 54 result.append(out.toString()); 55 try 56 { 57 out.close(); 58 } 59 catch (IOException e) 60 { 61 // ignore 62 } 24 /** 25 * 26 */ 27 @Override 28 public String format(LogRecord record) { 29 StringBuffer result = new StringBuffer(); 30 result.append(record.getLevel().getName().charAt(0)); 31 result.append(" | "); 32 result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis())); 33 result.append(" | "); 34 tailValue("" + record.getThreadID(), 6, result); 35 result.append(" | "); 36 tailValue(record.getLoggerName(), 30, result); 37 result.append(" | "); 38 result.append(record.getMessage()); 39 40 if (record.getThrown() != null) { 41 ByteArrayOutputStream out = new ByteArrayOutputStream(); 42 record.getThrown().printStackTrace(new PrintStream(out)); 43 result.append("\n"); 44 result.append(out.toString()); 45 try { 46 out.close(); 47 } 48 catch (IOException e) { 49 // ignore 50 } 51 } 52 53 result.append("\n"); 54 55 return result.toString(); 63 56 } 64 65 result.append("\n"); 66 67 return result.toString(); 68 } 69 70 //----------------------------------------------------------------------------------------------- 71 /** 72 * 73 */ 74 //----------------------------------------------------------------------------------------------- 75 private void tailValue(String value, int length, StringBuffer output) 76 { 77 for (int i = value.length() - length - 1; i < value.length(); i++) 78 { 79 if (i < 0) 80 { 81 output.append(" "); 82 } 83 else 84 { 85 output.append(value.charAt(i)); 86 } 57 58 /** 59 * 60 */ 61 private void tailValue(String value, int length, StringBuffer output) { 62 for (int i = value.length() - length - 1; i < value.length(); i++) { 63 if (i < 0) { 64 output.append(" "); 65 } 66 else { 67 output.append(value.charAt(i)); 68 } 69 } 87 70 } 88 }89 71 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/TaskTreeChecker.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeChecker.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 01.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.testutils; 9 8 … … 21 20 import java.util.regex.Pattern; 22 21 23 import de.ugoe.cs.quest. tasktrees.treeifc.InteractionTask;24 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;25 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;26 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;27 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;28 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;29 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;30 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;31 32 //------------------------------------------------------------------------------------------------- 22 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 23 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 24 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 25 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 26 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 27 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 28 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 29 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 30 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 31 33 32 /** 34 33 * TODO comment … … 37 36 * @author 2012, last modified by $Author: patrick$ 38 37 */ 39 //------------------------------------------------------------------------------------------------- 40 public class TaskTreeChecker 41 { 42 /** */ 43 private boolean mDoTrace; 44 45 //----------------------------------------------------------------------------------------------- 46 /** 47 * TODO: comment 38 public class TaskTreeChecker { 39 40 /** */ 41 private boolean doTrace; 42 43 /** 44 * TODO: comment 45 * 46 */ 47 public TaskTreeChecker() { 48 this(false); 49 } 50 51 /** 52 * TODO: comment 53 * 54 */ 55 public TaskTreeChecker(boolean doTrace) { 56 this.doTrace = doTrace; 57 } 58 59 /** 60 * 61 */ 62 public void assertTaskTree(String taskTreeSpec, ITaskTree taskTree) { 63 Map<ITaskTreeNode, Integer> taskMapCopy = new HashMap<ITaskTreeNode, Integer>(); 64 65 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : taskTree.getTaskMap().entrySet()) { 66 if (entry.getValue().getNoOfOccurencesInTree() > 0) { 67 taskMapCopy.put(entry.getKey(), entry.getValue().getNoOfOccurencesInTree()); 68 } 69 else { 70 taskMapCopy.put(entry.getKey(), 1); 71 } 72 } 73 74 if (doTrace) { 75 dumpTaskMap(taskMapCopy); 76 } 77 78 TaskSpec task = null; 79 80 Matcher matcher = Pattern.compile 81 ("(\\s*(\\w+)\\s+(\\w+)\\s+((\\w*\\s)*)(\\{))|((\\}))").matcher(taskTreeSpec); 82 83 do { 84 if (!matcher.find()) { 85 if (!matcher.hitEnd()) { 86 throw new IllegalArgumentException("could not parse task specification"); 87 } 88 else { 89 break; 90 } 91 } 92 93 task = parseTask(matcher); 94 if (task != null) { 95 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 96 } 97 } 98 while (task != null); 99 100 assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 101 } 102 103 /** 104 * TODO: comment 105 * 106 * @param taskTree 107 */ 108 public void dumpAsCheckString(ITaskTree taskTree) { 109 dumpNodeAsCheckString(taskTree.getRoot(), new int[4], ""); 110 } 111 112 /** 113 * TODO: comment 114 * 115 * @param root 116 * @param string 117 */ 118 private void dumpNodeAsCheckString(ITaskTreeNode node, int[] typeCounters, String indent) { 119 System.err.print(" \""); 120 System.err.print(indent); 121 122 if (node instanceof ISequence) { 123 System.err.print("Sequence sequence"); 124 System.err.print(typeCounters[0]++); 125 System.err.println(" {\" +"); 126 } 127 else if (node instanceof IIteration) { 128 System.err.print("Iteration iteration"); 129 System.err.print(typeCounters[1]++); 130 System.err.println(" {\" +"); 131 } 132 else if (node instanceof ISelection) { 133 System.err.print("Selection selection"); 134 System.err.print(typeCounters[2]++); 135 System.err.println(" {\" +"); 136 } 137 else if (node instanceof ITextInputEventTask) { 138 System.err.print("TextInputEvent textInput"); 139 System.err.print(typeCounters[3]++); 140 System.err.print(" "); 141 System.err.print(((ITextInputEventTask) node).getEnteredText()); 142 System.err.println(" {\" +"); 143 } 144 else if (node instanceof IEventTask) { 145 System.err.print("Event "); 146 System.err.print(((IEventTask) node).getEventType().getName()); 147 System.err.print(" {}\" +"); 148 } 149 else { 150 fail("unknown type of node in task tree " + node); 151 } 152 153 for (ITaskTreeNode child : node.getChildren()) { 154 dumpNodeAsCheckString(child, typeCounters, indent + " "); 155 } 156 157 if (!(node instanceof IEventTask) || (node instanceof ITextInputEventTask)) { 158 System.err.print(" \""); 159 System.err.print(indent); 160 System.err.print("}\" +"); 161 } 162 163 System.err.println(); 164 } 165 166 /** 167 * TODO: comment 168 * 169 * @param taskTree 170 */ 171 public void dumpFullTaskTree(ITaskTree taskTree) throws FileNotFoundException { 172 PrintWriter out = null; 173 try { 174 out = new PrintWriter(new FileOutputStream("taskTree.txt")); 175 dumpFullNode(taskTree.getRoot(), out, ""); 176 } 177 finally { 178 if (out != null) { 179 out.close(); 180 } 181 } 182 183 } 184 185 /** 186 * 187 */ 188 private void dumpFullNode(ITaskTreeNode node, PrintWriter out, String indent) { 189 out.print(indent); 190 if (node instanceof ISequence) { 191 out.println("Sequence"); 192 out.print(indent); 193 out.println("{"); 194 } 195 else if (node instanceof IIteration) { 196 out.println("Iteration"); 197 out.print(indent); 198 out.println("{"); 199 } 200 else if (node instanceof ISelection) { 201 out.println("Selection"); 202 out.print(indent); 203 out.println("{"); 204 } 205 else if (node instanceof ITextInputEventTask) { 206 out.print("TextInputEvent"); 207 out.print(" "); 208 out.println(((ITextInputEventTask) node).getEnteredText()); 209 out.print(indent); 210 out.println("{"); 211 } 212 else if (node instanceof IEventTask) { 213 out.print(((IEventTask) node).getEventType().getName()); 214 out.print(" "); 215 out.print(((IEventTask) node).getEventTarget()); 216 if (((IEventTask) node).getEventTarget() instanceof IGUIElement) 217 { 218 out.print(" "); 219 out.print(((IGUIElement) ((IEventTask) node).getEventTarget()).getOriginalTypeInfo()); 220 } 221 } 222 else { 223 fail("unknown type of node in task tree " + node); 224 } 225 226 for (ITaskTreeNode child : node.getChildren()) { 227 dumpFullNode(child, out, indent + " "); 228 } 229 230 if (!(node instanceof IEventTask) || (node instanceof ITextInputEventTask)) { 231 out.print(indent); 232 out.print("}"); 233 } 234 235 out.println(); 236 } 237 238 /** 239 * 240 */ 241 private TaskSpec parseTask(Matcher tokenMatcher) { 242 String firstToken = tokenMatcher.group(); 243 244 if ("}".equals(firstToken)) { 245 throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 246 } 247 248 TaskSpec task = new TaskSpec(); 249 task.type = tokenMatcher.group(2); 250 task.name = tokenMatcher.group(3); 251 task.additionalInfo = tokenMatcher.group(4).trim(); 252 253 if ("".equals(task.name)) { 254 task.name = null; 255 } 256 257 if (!tokenMatcher.find()) { 258 throw new IllegalArgumentException("could not parse task specification"); 259 } 260 261 firstToken = tokenMatcher.group(); 262 263 if (!"}".equals(firstToken)) { 264 ArrayList<TaskSpec> children = new ArrayList<TaskSpec>(); 265 266 TaskSpec child = null; 267 268 do { 269 child = parseTask(tokenMatcher); 270 271 if (child != null) { 272 children.add(child); 273 274 if (!tokenMatcher.find()) { 275 throw new IllegalArgumentException("could not parse task specification"); 276 } 277 278 firstToken = tokenMatcher.group(); 279 280 if ("}".equals(firstToken)) { 281 break; 282 } 283 } 284 285 } 286 while (child != null); 287 288 task.children = children.toArray(new TaskSpec[children.size()]); 289 } 290 291 return task; 292 } 293 294 /** 295 * @param task 296 * @param taskMapCopy 297 */ 298 private void assertTaskAndChildrenInMapAndRemove(TaskSpec task, 299 Map<ITaskTreeNode, Integer> taskMap) 300 { 301 for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 302 if (taskSpecEqualsTask(task, entry.getKey())) { 303 if (task.children != null) { 304 for (TaskSpec child : task.children) { 305 assertTaskAndChildrenInMapAndRemove(child, taskMap); 306 } 307 } 308 309 int count = taskMap.get(entry.getKey()); 310 if (count == 1) { 311 taskMap.remove(entry.getKey()); 312 } 313 else { 314 taskMap.put(entry.getKey(), count - 1); 315 } 316 return; 317 } 318 } 319 320 fail("expected task " + task.type + " " + task.name + 321 " not included in task map"); 322 } 323 324 /** 325 * 326 */ 327 private boolean taskSpecEqualsTask(TaskSpec taskSpec, ITaskTreeNode task) { 328 if (doTrace) { 329 System.err.println("comparing " + taskSpec.name + " with"); 330 dumpTask(task, 0, ""); 331 } 332 333 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 334 ("TextInputEvent".equals(taskSpec.type) && (!(task instanceof ITextInputEventTask))) || 335 ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 336 ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || 337 ("Iteration".equals(taskSpec.type) && (!(task instanceof IIteration)))) 338 { 339 if (doTrace) { 340 System.err.println("task types do not match: " + taskSpec.type + " != " + 341 task.getClass().getSimpleName() + "\n"); 342 } 343 return false; 344 } 345 else if (!"Event".equals(taskSpec.type) && 346 !"TextInputEvent".equals(taskSpec.type) && 347 !"Sequence".equals(taskSpec.type) && 348 !"Selection".equals(taskSpec.type) && 349 !"Iteration".equals(taskSpec.type)) 350 { 351 fail("unknown task type " + taskSpec.type + " --> please extend test case"); 352 } 353 354 if ("TextInputEvent".equals(taskSpec.type)) { 355 if (!"".equals(taskSpec.additionalInfo) && 356 !(taskSpec.additionalInfo.equals(((ITextInputEventTask) task).getEnteredText()))) 357 { 358 if (doTrace) { 359 System.err.println("expected text \"" + taskSpec.additionalInfo + 360 "\" is not equal to the text " + "provided by the task \"" + 361 ((ITextInputEventTask) task).getEnteredText() + "\"\n"); 362 } 363 return false; 364 } 365 } 366 else if ((task instanceof IEventTask) && (((IEventTask) task).getEventType() != null) && 367 (!taskSpec.name.equals(((IEventTask) task).getEventType().getName()))) 368 { 369 // simple event names do not match. But what about the event name in 370 // combination with the additional info 371 String complexName = 372 taskSpec.name + 373 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 374 375 if (!complexName.equals(((IEventTask) task).getEventType().getName())) { 376 if (doTrace) { 377 System.err.println("event names do not match: " + taskSpec.name + " != " + 378 ((IEventTask) task).getEventType().getName() + "\n"); 379 } 380 return false; 381 } 382 } 383 384 if (((taskSpec.children == null) && (task.getChildren().size() > 0)) || 385 ((taskSpec.children != null) && (taskSpec.children.length != task.getChildren().size()))) 386 { 387 if (doTrace) { 388 System.err.println 389 ("numbers of children do not match: " + 390 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 391 (task.getChildren() == null ? "0" : task.getChildren().size()) + "\n"); 392 } 393 return false; 394 } 395 396 Iterator<ITaskTreeNode> children = task.getChildren().iterator(); 397 if (taskSpec.children != null) { 398 for (TaskSpec child : taskSpec.children) { 399 if (!taskSpecEqualsTask(child, children.next())) { 400 if (doTrace) { 401 System.err.println("one of the children does not match\n"); 402 } 403 return false; 404 } 405 } 406 } 407 408 if (!children.hasNext()) { 409 if (doTrace) { 410 System.err.println("nodes match\n"); 411 } 412 return true; 413 } 414 else { 415 if (doTrace) { 416 System.err.println("number of children does not match\n"); 417 } 418 return false; 419 } 420 } 421 422 /** 48 423 * 49 424 */ 50 //-----------------------------------------------------------------------------------------------51 public TaskTreeChecker()52 {53 this(false);54 }55 56 //-----------------------------------------------------------------------------------------------57 /** 58 * TODO: comment425 private void dumpTaskMap(Map<ITaskTreeNode, Integer> taskMap) { 426 System.err.println(); 427 for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 428 dumpTask(entry.getKey(), entry.getValue(), ""); 429 System.err.println(); 430 } 431 } 432 433 /** 59 434 * 60 435 */ 61 //----------------------------------------------------------------------------------------------- 62 public TaskTreeChecker(boolean doTrace) 63 { 64 mDoTrace = doTrace; 65 } 66 67 //----------------------------------------------------------------------------------------------- 68 /** 69 * 70 */ 71 //----------------------------------------------------------------------------------------------- 72 public void assertTaskTree(String taskTreeSpec, TaskTree taskTree) 73 { 74 Map<TaskTreeNode, Integer> taskMapCopy = new HashMap<TaskTreeNode, Integer>(); 75 76 for (Map.Entry<TaskTreeNode, NodeInfo> entry : taskTree.getTaskMap().entrySet()) 77 { 78 if (entry.getValue().getNoOfOccurencesInTree() > 0) 79 { 80 taskMapCopy.put(entry.getKey(), entry.getValue().getNoOfOccurencesInTree()); 81 } 82 else 83 { 84 taskMapCopy.put(entry.getKey(), 1); 85 } 86 } 87 88 if (mDoTrace) 89 { 90 dumpTaskMap(taskMapCopy); 91 } 92 93 TaskSpec task = null; 94 95 Matcher matcher = 96 Pattern.compile("(\\s*(\\w+)\\s+(\\w+)\\s+((\\w*\\s)*)(\\{))|((\\}))").matcher(taskTreeSpec); 97 98 do 99 { 100 if (!matcher.find()) 101 { 102 if (!matcher.hitEnd()) 103 { 104 throw new IllegalArgumentException("could not parse task specification"); 105 } 106 else 107 { 108 break; 109 } 110 } 111 112 task = parseTask(matcher); 113 if (task != null) 114 { 115 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 116 } 117 } 118 while (task != null); 119 120 assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 121 } 122 123 //----------------------------------------------------------------------------------------------- 124 /** 125 * TODO: comment 126 * 127 * @param taskTree 128 */ 129 //----------------------------------------------------------------------------------------------- 130 public void dumpAsCheckString(TaskTree taskTree) 131 { 132 dumpNodeAsCheckString(taskTree.getRoot(), new int[4], ""); 133 } 134 135 //----------------------------------------------------------------------------------------------- 136 /** 137 * TODO: comment 138 * 139 * @param root 140 * @param string 141 */ 142 //----------------------------------------------------------------------------------------------- 143 private void dumpNodeAsCheckString(TaskTreeNode node, 144 int[] typeCounters, 145 String indent) 146 { 147 System.err.print(" \""); 148 System.err.print(indent); 149 150 if (node instanceof Sequence) 151 { 152 System.err.print("Sequence sequence"); 153 System.err.print(typeCounters[0]++); 154 System.err.println(" {\" +"); 155 } 156 else if (node instanceof Iteration) 157 { 158 System.err.print("Iteration iteration"); 159 System.err.print(typeCounters[1]++); 160 System.err.println(" {\" +"); 161 } 162 else if (node instanceof Selection) 163 { 164 System.err.print("Selection selection"); 165 System.err.print(typeCounters[2]++); 166 System.err.println(" {\" +"); 167 } 168 else if (node instanceof TextInputInteractionTask) 169 { 170 System.err.print("TextInputInteraction textInput"); 171 System.err.print(typeCounters[3]++); 172 System.err.print(" "); 173 System.err.print(((TextInputInteractionTask) node).getEnteredText()); 174 System.err.println(" {\" +"); 175 } 176 else if (node instanceof InteractionTask) 177 { 178 System.err.print("Interaction "); 179 System.err.print(((InteractionTask) node).getInteraction().getName()); 180 System.err.print(" {}\" +"); 181 } 182 else 183 { 184 fail("unknown type of node in task tree " + node); 185 } 186 187 for (TaskTreeNode child : node.getChildren()) 188 { 189 dumpNodeAsCheckString(child, typeCounters, indent + " "); 190 } 191 192 if (!(node instanceof InteractionTask) || 193 (node instanceof TextInputInteractionTask)) 194 { 195 System.err.print(" \""); 196 System.err.print(indent); 197 System.err.print("}\" +"); 198 } 199 200 System.err.println(); 201 } 202 203 //----------------------------------------------------------------------------------------------- 204 /** 205 * TODO: comment 206 * 207 * @param taskTree 208 */ 209 //----------------------------------------------------------------------------------------------- 210 public void dumpFullTaskTree(TaskTree taskTree) throws FileNotFoundException 211 { 212 PrintWriter out = null; 213 try 214 { 215 out = new PrintWriter(new FileOutputStream("taskTree.txt")); 216 dumpFullNode(taskTree.getRoot(), out, ""); 217 } 218 finally 219 { 220 if (out != null) 221 { 222 out.close(); 223 } 224 } 225 226 } 227 228 //----------------------------------------------------------------------------------------------- 229 /** 230 * 231 */ 232 //----------------------------------------------------------------------------------------------- 233 private void dumpFullNode(TaskTreeNode node, PrintWriter out, String indent) 234 { 235 out.print(indent); 236 if (node instanceof Sequence) 237 { 238 out.println("Sequence"); 239 out.print(indent); 240 out.println("{"); 241 } 242 else if (node instanceof Iteration) 243 { 244 out.println("Iteration"); 245 out.print(indent); 246 out.println("{"); 247 } 248 else if (node instanceof Selection) 249 { 250 out.println("Selection"); 251 out.print(indent); 252 out.println("{"); 253 } 254 else if (node instanceof TextInputInteractionTask) 255 { 256 out.print("TextInputInteraction"); 257 out.print(" "); 258 out.println(((TextInputInteractionTask) node).getEnteredText()); 259 out.print(indent); 260 out.println("{"); 261 } 262 else if (node instanceof InteractionTask) 263 { 264 out.print(((InteractionTask) node).getInteraction().getName()); 265 out.print(" "); 266 out.print(((InteractionTask) node).getGUIElement()); 267 out.print(" "); 268 out.print(((InteractionTask) node).getGUIElement().getOriginalTypeInfo()); 269 } 270 else 271 { 272 fail("unknown type of node in task tree " + node); 273 } 274 275 for (TaskTreeNode child : node.getChildren()) 276 { 277 dumpFullNode(child, out, indent + " "); 278 } 279 280 if (!(node instanceof InteractionTask) || 281 (node instanceof TextInputInteractionTask)) 282 { 283 out.print(indent); 284 out.print("}"); 285 } 286 287 out.println(); 288 } 289 290 //----------------------------------------------------------------------------------------------- 291 /** 292 * 293 */ 294 //----------------------------------------------------------------------------------------------- 295 private TaskSpec parseTask(Matcher tokenMatcher) 296 { 297 String firstToken = tokenMatcher.group(); 298 299 if ("}".equals(firstToken)) 300 { 301 throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 302 } 303 304 TaskSpec task = new TaskSpec(); 305 task.type = tokenMatcher.group(2); 306 task.interactionName = tokenMatcher.group(3); 307 task.additionalInfo = tokenMatcher.group(4).trim(); 308 309 if ("".equals(task.interactionName)) 310 { 311 task.interactionName = null; 312 } 313 314 if (!tokenMatcher.find()) 315 { 316 throw new IllegalArgumentException("could not parse task specification"); 317 } 318 319 firstToken = tokenMatcher.group(); 320 321 if (!"}".equals(firstToken)) 322 { 323 ArrayList<TaskSpec> children = new ArrayList<TaskSpec>(); 324 325 TaskSpec child = null; 326 327 do 328 { 329 child = parseTask(tokenMatcher); 330 331 if (child != null) 332 { 333 children.add(child); 334 335 if (!tokenMatcher.find()) 336 { 337 throw new IllegalArgumentException("could not parse task specification"); 338 } 339 340 firstToken = tokenMatcher.group(); 341 342 if ("}".equals(firstToken)) 343 { 344 break; 345 } 346 } 347 348 } 349 while (child != null); 350 351 task.children = children.toArray(new TaskSpec[children.size()]); 352 } 353 354 return task; 355 } 356 357 //----------------------------------------------------------------------------------------------- 358 /** 359 * @param task 360 * @param taskMapCopy 361 */ 362 //----------------------------------------------------------------------------------------------- 363 private void assertTaskAndChildrenInMapAndRemove(TaskSpec task, 364 Map<TaskTreeNode, Integer> taskMap) 365 { 366 for (Map.Entry<TaskTreeNode, Integer> entry : taskMap.entrySet()) 367 { 368 if (taskSpecEqualsTask(task, entry.getKey())) 369 { 370 if (task.children != null) 371 { 372 for (TaskSpec child : task.children) 373 { 374 assertTaskAndChildrenInMapAndRemove(child, taskMap); 375 } 376 } 377 378 int count = taskMap.get(entry.getKey()); 379 if (count == 1) 380 { 381 taskMap.remove(entry.getKey()); 382 } 383 else 384 { 385 taskMap.put(entry.getKey(), count - 1); 386 } 387 return; 388 } 389 } 390 391 fail("expected task " + task.type + " " + task.interactionName + " not included in task map"); 392 } 393 394 //----------------------------------------------------------------------------------------------- 395 /** 396 * 397 */ 398 //----------------------------------------------------------------------------------------------- 399 private boolean taskSpecEqualsTask(TaskSpec taskSpec, TaskTreeNode task) 400 { 401 if (mDoTrace) 402 { 403 System.err.println("comparing " + taskSpec.interactionName + " with"); 404 dumpTask(task, 0, ""); 405 } 406 407 if (("Interaction".equals(taskSpec.type) && (!(task instanceof InteractionTask))) || 408 ("TextInputInteraction".equals(taskSpec.type) && 409 (!(task instanceof TextInputInteractionTask))) || 410 ("Sequence".equals(taskSpec.type) && (!(task instanceof Sequence))) || 411 ("Selection".equals(taskSpec.type) && (!(task instanceof Selection))) || 412 ("Iteration".equals(taskSpec.type) && (!(task instanceof Iteration)))) 413 { 414 if (mDoTrace) 415 { 416 System.err.println("task types do not match: " + taskSpec.type + " != " + 417 task.getClass().getSimpleName() + "\n"); 418 } 419 return false; 420 } 421 else if (!"Interaction".equals(taskSpec.type) && 422 !"TextInputInteraction".equals(taskSpec.type) && 423 !"Sequence".equals(taskSpec.type) && 424 !"Selection".equals(taskSpec.type) && 425 !"Iteration".equals(taskSpec.type)) 426 { 427 fail("unknown task type " + taskSpec.type + " --> please extend test case"); 428 } 429 430 if ("TextInputInteraction".equals(taskSpec.type)) 431 { 432 if (!"".equals(taskSpec.additionalInfo) && 433 !(taskSpec.additionalInfo.equals(((TextInputInteractionTask) task).getEnteredText()))) 434 { 435 if (mDoTrace) 436 { 437 System.err.println 438 ("expected text \"" + taskSpec.additionalInfo + "\" is not equal to the text " + 439 "provided by the task \"" + ((TextInputInteractionTask) task).getEnteredText() + 440 "\"\n"); 441 } 442 return false; 443 } 444 } 445 else if ((task instanceof InteractionTask) && 446 (((InteractionTask) task).getInteraction() != null) && 447 (!taskSpec.interactionName.equals(((InteractionTask) task).getInteraction().getName()))) 448 { 449 // simple interaction names do not match. But what about the interaction name in combination 450 // with the additional info 451 String complexInteractionName = taskSpec.interactionName + 452 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 453 454 if (!complexInteractionName.equals(((InteractionTask) task).getInteraction().getName())) 455 { 456 if (mDoTrace) 457 { 458 System.err.println("interaction names do not match: " + taskSpec.interactionName + 459 " != " + ((InteractionTask) task).getInteraction().getName() + "\n"); 460 } 461 return false; 462 } 463 } 464 465 if (((taskSpec.children == null) && (task.getChildren().size() > 0)) || 466 ((taskSpec.children != null) && (taskSpec.children.length != task.getChildren().size()))) 467 { 468 if (mDoTrace) 469 { 470 System.err.println("numbers of children do not match: " + 471 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 472 (task.getChildren() == null ? "0" : task.getChildren().size()) + "\n"); 473 } 474 return false; 475 } 476 477 Iterator<TaskTreeNode> children = task.getChildren().iterator(); 478 if (taskSpec.children != null) 479 { 480 for (TaskSpec child : taskSpec.children) 481 { 482 if (!taskSpecEqualsTask(child, children.next())) 483 { 484 if (mDoTrace) 485 { 486 System.err.println("one of the children does not match\n"); 487 } 488 return false; 489 } 490 } 491 } 492 493 if (!children.hasNext()) 494 { 495 if (mDoTrace) 496 { 497 System.err.println("nodes match\n"); 498 } 499 return true; 500 } 501 else 502 { 503 if (mDoTrace) 504 { 505 System.err.println("number of children does not match\n"); 506 } 507 return false; 508 } 509 } 510 511 //----------------------------------------------------------------------------------------------- 512 /** 513 * 514 */ 515 //----------------------------------------------------------------------------------------------- 516 private void dumpTaskMap(Map<TaskTreeNode, Integer> taskMap) 517 { 518 System.err.println(); 519 for (Map.Entry<TaskTreeNode, Integer> entry : taskMap.entrySet()) 520 { 521 dumpTask(entry.getKey(), entry.getValue(), ""); 522 System.err.println(); 523 } 524 } 525 526 //----------------------------------------------------------------------------------------------- 527 /** 528 * 529 */ 530 //----------------------------------------------------------------------------------------------- 531 private void dumpTask(TaskTreeNode task, int count, String indent) 532 { 533 System.err.print(indent); 534 System.err.print(task); 535 System.err.print(" "); 536 System.err.print(task.getDescription()); 537 System.err.print(" "); 538 539 if (count > 0) 540 { 541 System.err.print("("); 542 System.err.print(count); 543 System.err.print(" occurrences)"); 544 } 545 546 System.err.println(); 547 548 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) 549 { 550 for (TaskTreeNode child : task.getChildren()) 551 { 552 dumpTask(child, 0, indent + " "); 553 } 554 } 555 } 556 557 //----------------------------------------------------------------------------------------------- 558 /** 559 * TODO comment 560 * 561 * @version $Revision: $ $Date: $ 562 * @author 2011, last modified by $Author: $ 563 */ 564 //----------------------------------------------------------------------------------------------- 565 private class TaskSpec 566 { 567 public String type; 568 public String interactionName; 569 public String additionalInfo; 570 public TaskSpec[] children; 571 } 436 private void dumpTask(ITaskTreeNode task, int count, String indent) { 437 System.err.print(indent); 438 System.err.print(task); 439 System.err.print(" "); 440 System.err.print(task.getDescription()); 441 System.err.print(" "); 442 443 if (count > 0) { 444 System.err.print("("); 445 System.err.print(count); 446 System.err.print(" occurrences)"); 447 } 448 449 System.err.println(); 450 451 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 452 for (ITaskTreeNode child : task.getChildren()) { 453 dumpTask(child, 0, indent + " "); 454 } 455 } 456 } 457 458 /** 459 * TODO comment 460 * 461 * @version $Revision: $ $Date: $ 462 * @author 2011, last modified by $Author: $ 463 */ 464 private class TaskSpec { 465 public String type; 466 public String name; 467 public String additionalInfo; 468 public TaskSpec[] children; 469 } 572 470 573 471 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/Utilities.java
r445 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TestUtils.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.testutils; 9 9 10 10 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 11 11 12 //-------------------------------------------------------------------------------------------------13 12 /** 14 13 * TODO comment … … 17 16 * @author 2012, last modified by $Author: patrick$ 18 17 */ 19 //------------------------------------------------------------------------------------------------- 20 public class Utilities 21 { 22 /** */ 23 private static final NodeEqualityRuleManager NODE_EQUALITY_RULE_MANAGER = 24 new NodeEqualityRuleManager(); 25 26 static 27 { 28 NODE_EQUALITY_RULE_MANAGER.init(); 29 } 18 public class Utilities { 19 20 /** */ 21 private static final NodeEqualityRuleManager NODE_EQUALITY_RULE_MANAGER = 22 new NodeEqualityRuleManager(); 30 23 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * TODO: comment 34 * 35 * @return 36 */ 37 //----------------------------------------------------------------------------------------------- 38 public static NodeEqualityRuleManager getNodeEqualityRuleManagerForTests() 39 { 40 return NODE_EQUALITY_RULE_MANAGER; 41 } 24 static { 25 NODE_EQUALITY_RULE_MANAGER.init(); 26 } 27 28 /** 29 * TODO: comment 30 * 31 * @return 32 */ 33 public static NodeEqualityRuleManager getNodeEqualityRuleManagerForTests() { 34 return NODE_EQUALITY_RULE_MANAGER; 35 } 42 36 43 37 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeImplTest.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeImplTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 … … 19 19 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 20 20 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 21 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 22 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 23 import de.ugoe.cs.quest.tasktrees.treeifc.NodeInfo; 24 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 25 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 26 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 27 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 28 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 29 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 30 31 //------------------------------------------------------------------------------------------------- 21 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 22 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 25 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 26 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 27 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 28 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 29 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 30 32 31 /** 33 32 * TODO comment … … 36 35 * @author 2012, last modified by $Author: patrick$ 37 36 */ 38 //------------------------------------------------------------------------------------------------- 39 public class TaskTreeImplTest 40 { 41 /** */ 42 private static final int MAX_TREE_DEPTH = 15; 43 44 /** */ 45 private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); 46 47 /** */ 48 private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 49 50 //----------------------------------------------------------------------------------------------- 51 /** 52 * @throws Exception 53 * 54 */ 55 //----------------------------------------------------------------------------------------------- 56 @Test 57 public void testRandomTrees() throws Exception 58 { 59 int noOfTrees = 10; 60 int noOfMaxChildren = 8; 61 int maxDepth = MAX_TREE_DEPTH; 37 public class TaskTreeImplTest { 62 38 63 for (int i = 0; i < noOfTrees; i++) 64 { 65 System.err.println("iteration " + (i + 1) + ":"); 66 System.err.println(" creating tree"); 67 Map<TaskTreeNode, NodeInfo> treeInfos = new HashMap<TaskTreeNode, NodeInfo>(); 68 TaskTreeNode rootNode = createTree(noOfMaxChildren, maxDepth, treeInfos); 69 System.err.println(" creating task tree"); 70 TaskTree taskTree = mTaskTreeNodeFactory.createTaskTree(rootNode); 71 72 System.err.println(" validating task tree"); 73 assertEquals(rootNode, taskTree.getRoot()); 74 assertMapsEqual(treeInfos, taskTree.getTaskMap()); 75 } 76 } 77 78 //----------------------------------------------------------------------------------------------- 79 /** 80 * TODO: comment 81 * 82 * @param treeInfos 83 * @param taskMap 84 */ 85 //----------------------------------------------------------------------------------------------- 86 private void assertMapsEqual(Map<TaskTreeNode, NodeInfo> map1, 87 Map<TaskTreeNode, NodeInfo> map2) 88 { 89 try 90 { 91 if (map1 == null) 92 { 93 assertNull(map2); 94 return; 95 } 96 97 assertEquals(map1.size(), map2.size()); 98 99 for (Map.Entry<TaskTreeNode, NodeInfo> entry : map1.entrySet()) 100 { 101 NodeInfo value2 = map2.get(entry.getKey()); 102 assertNotNull(value2); 103 assertEquals(entry.getValue().getTask(), value2.getTask()); 104 assertEquals(entry.getValue().getNoOfOccurencesInTree(), value2.getNoOfOccurencesInTree()); 105 } 106 } 107 catch (AssertionError e) 108 { 109 dumpMap(map1); 110 dumpMap(map2); 111 throw e; 112 } 113 } 114 115 //----------------------------------------------------------------------------------------------- 116 /** 117 * TODO: comment 118 * 119 * @param map2 120 */ 121 //----------------------------------------------------------------------------------------------- 122 private void dumpMap(Map<TaskTreeNode, NodeInfo> map) 123 { 124 System.err.println(); 125 126 if (map == null) 127 { 128 System.err.println("map is null"); 129 } 130 else 131 { 132 System.err.println("map:"); 133 for (Map.Entry<TaskTreeNode, NodeInfo> entry : map.entrySet()) 134 { 135 System.err.print(" "); 136 System.err.print(entry.getKey()); 137 for (int i = entry.getKey().toString().length(); i < 49; i++) 39 /** */ 40 private static final int MAX_TREE_DEPTH = 15; 41 42 /** */ 43 private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 44 45 /** */ 46 private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 47 48 /** 49 * @throws Exception 50 * 51 */ 52 @Test 53 public void testRandomTrees() throws Exception { 54 int noOfTrees = 10; 55 int noOfMaxChildren = 8; 56 int maxDepth = MAX_TREE_DEPTH; 57 58 for (int i = 0; i < noOfTrees; i++) { 59 System.err.println("iteration " + (i + 1) + ":"); 60 System.err.println(" creating tree"); 61 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos = 62 new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 63 ITaskTreeNode rootNode = createTree(noOfMaxChildren, maxDepth, treeInfos); 64 System.err.println(" creating task tree"); 65 ITaskTree taskTree = taskTreeNodeFactory.createTaskTree(rootNode); 66 67 System.err.println(" validating task tree"); 68 assertEquals(rootNode, taskTree.getRoot()); 69 assertMapsEqual(treeInfos, taskTree.getTaskMap()); 70 } 71 } 72 73 /** 74 * TODO: comment 75 * 76 * @param treeInfos 77 * @param taskMap 78 */ 79 private void assertMapsEqual(Map<ITaskTreeNode, ITaskTreeNodeInfo> map1, 80 Map<ITaskTreeNode, ITaskTreeNodeInfo> map2) 81 { 82 try { 83 if (map1 == null) { 84 assertNull(map2); 85 return; 86 } 87 88 assertEquals(map1.size(), map2.size()); 89 90 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : map1.entrySet()) { 91 ITaskTreeNodeInfo value2 = map2.get(entry.getKey()); 92 assertNotNull(value2); 93 assertEquals(entry.getValue().getTask(), value2.getTask()); 94 assertEquals(entry.getValue().getNoOfOccurencesInTree(), 95 value2.getNoOfOccurencesInTree()); 96 } 97 } 98 catch (AssertionError e) { 99 dumpMap(map1); 100 dumpMap(map2); 101 throw e; 102 } 103 } 104 105 /** 106 * TODO: comment 107 * 108 * @param map2 109 */ 110 private void dumpMap(Map<ITaskTreeNode, ITaskTreeNodeInfo> map) { 111 System.err.println(); 112 113 if (map == null) { 114 System.err.println("map is null"); 115 } 116 else { 117 System.err.println("map:"); 118 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : map.entrySet()) { 119 System.err.print(" "); 120 System.err.print(entry.getKey()); 121 for (int i = entry.getKey().toString().length(); i < 49; i++) { 122 System.err.print(" "); 123 } 124 System.err.print(" : "); 125 System.err.println(entry.getValue()); 126 } 127 } 128 129 System.err.println(); 130 } 131 132 /** 133 * TODO: comment 134 * 135 * @param noOfMaxChildren 136 * @param maxDepth 137 * @param treeInfos 138 * @return 139 */ 140 private ITaskTreeNode createTree(int maxNoOfChildren, 141 int maxDepth, 142 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 143 throws Exception 144 { 145 /* 146 * for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) { System.err.print(" "); } 147 */ 148 149 ITaskTreeNode tree; 150 151 // integrating the maximum depth here assures, that either something between 0 and 8 will 152 // be the type, or if the max depth decreases near 0 only event tasks will be created 153 // to finish the tree creation 154 int type = (int) (Math.random() * (Math.min(8, maxDepth))); 155 156 switch (type) 138 157 { 139 System.err.print(" "); 140 } 141 System.err.print(" : "); 142 System.err.println(entry.getValue()); 143 } 144 } 145 146 System.err.println(); 147 } 148 149 //----------------------------------------------------------------------------------------------- 150 /** 151 * TODO: comment 152 * 153 * @param noOfMaxChildren 154 * @param maxDepth 155 * @param treeInfos 156 * @return 157 */ 158 //----------------------------------------------------------------------------------------------- 159 private TaskTreeNode createTree(int maxNoOfChildren, 160 int maxDepth, 161 Map<TaskTreeNode, NodeInfo> treeInfos) 162 throws Exception 163 { 164 /*for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) 165 { 166 System.err.print(" "); 167 }*/ 168 169 TaskTreeNode tree; 170 171 // integrating the maximum depth here assures, that either something between 0 and 8 will 172 // be the type, or if the max depth decreases near 0 only interaction tasks will be created 173 // to finish the tree creation 174 int type = (int) (Math.random() * (Math.min(8, maxDepth))); 175 176 switch (type) 177 { 178 case 0: 179 { 180 //System.err.print("creating new interaction task "); 181 tree = createNewInteractionTask(treeInfos); 182 break; 183 } 184 case 1: 185 { 186 //System.err.print("reusing interaction task "); 187 tree = reuseInteractionTask(treeInfos); 188 break; 189 } 190 case 2: 191 { 192 //System.err.println("creating new sequence {"); 193 tree = createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 194 break; 195 } 196 case 3: 197 { 198 //System.err.println("reusing sequence {"); 199 tree = reuseSequence(maxNoOfChildren, maxDepth, treeInfos); 200 break; 201 } 202 case 4: 203 { 204 //System.err.println("creating new selection {"); 205 tree = createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 206 break; 207 } 208 case 5: 209 { 210 //System.err.println("reusing selection {"); 211 tree = reuseSelection(maxNoOfChildren, maxDepth, treeInfos); 212 break; 213 } 214 case 6: 215 { 216 //System.err.println("creating new iteration {"); 217 tree = createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 218 break; 219 } 220 case 7: 221 { 222 //System.err.println("reusing iteration {"); 223 tree = reuseIteration(maxNoOfChildren, maxDepth, treeInfos); 224 break; 225 } 226 default: 227 { 228 //System.err.print("creating new interaction task per default "); 229 tree = createNewInteractionTask(treeInfos); 230 } 231 } 232 233 /* 234 if (!(tree instanceof InteractionTask)) 235 { 236 for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) 237 { 238 System.err.print(" "); 239 } 240 241 System.err.print("} "); 242 } 243 244 System.err.println(tree);*/ 245 246 return tree; 247 } 248 249 //----------------------------------------------------------------------------------------------- 250 /** 251 * TODO: comment 252 * 253 * @param treeInfos 254 * @return 255 */ 256 //----------------------------------------------------------------------------------------------- 257 private InteractionTask createNewInteractionTask(Map<TaskTreeNode, NodeInfo> treeInfos) 258 throws Exception 259 { 260 Thread.sleep(2); 261 long id = System.currentTimeMillis(); 262 InteractionTask task = mTaskTreeNodeFactory.createNewInteractionTask 263 (new DummyGUIElement("elem" + id), new DummyInteraction("interaction" + id, 1)); 264 265 treeInfos.put(task, new NodeInfoImpl(task)); 266 267 return task; 268 } 269 270 //----------------------------------------------------------------------------------------------- 271 /** 272 * TODO: comment 273 * 274 * @param treeInfos 275 * @return 276 */ 277 //----------------------------------------------------------------------------------------------- 278 private InteractionTask reuseInteractionTask(Map<TaskTreeNode, NodeInfo> treeInfos) 279 throws Exception 280 { 281 int noOfInteractionTasks = 0; 282 283 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 284 { 285 if (entry.getKey() instanceof InteractionTask) 286 { 287 noOfInteractionTasks++; 288 } 289 } 290 291 if (noOfInteractionTasks > 0) 292 { 293 noOfInteractionTasks = (int) (Math.random() * noOfInteractionTasks); 294 295 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 296 { 297 if (entry.getKey() instanceof InteractionTask) 298 { 299 if (--noOfInteractionTasks <= 0) 300 { 301 return (InteractionTask) entry.getKey(); 302 } 303 } 304 } 305 } 306 else 307 { 308 return createNewInteractionTask(treeInfos); 309 } 310 311 throw new RuntimeException("this is an implementation error"); 312 } 313 314 //----------------------------------------------------------------------------------------------- 315 /** 316 * TODO: comment 317 * 318 * @param treeInfos 319 * @return 320 */ 321 //----------------------------------------------------------------------------------------------- 322 private Sequence createNewSequence(int maxNoOfChildren, 323 int maxDepth, 324 Map<TaskTreeNode, NodeInfo> treeInfos) 325 throws Exception 326 { 327 Sequence sequence = mTaskTreeNodeFactory.createNewSequence(); 328 329 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 330 331 for (int i = 0; i < noOfChildren; i++) 332 { 333 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 334 335 // through first removing an existing parent it is assured, that a parent is recorded 336 // only once. This is needed, because parent may be reused in a tree as well, but we always 337 // iterate the whole tree 338 ((NodeInfoImpl) treeInfos.get(child)).removeParent(sequence); 339 ((NodeInfoImpl) treeInfos.get(child)).addParent(sequence); 340 mTaskTreeBuilder.addChild(sequence, child); 341 } 342 343 treeInfos.put(sequence, new NodeInfoImpl(sequence)); 344 return sequence; 345 } 346 347 //----------------------------------------------------------------------------------------------- 348 /** 349 * TODO: comment 350 * 351 * @param treeInfos 352 * @return 353 */ 354 //----------------------------------------------------------------------------------------------- 355 private Sequence reuseSequence(int maxNoOfChildren, 356 int maxDepth, 357 Map<TaskTreeNode, NodeInfo> treeInfos) 358 throws Exception 359 { 360 int noOfSequences = 0; 361 362 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 363 { 364 if (entry.getKey() instanceof Sequence) 365 { 366 noOfSequences++; 367 } 368 } 369 370 if (noOfSequences > 0) 371 { 372 noOfSequences = (int) (Math.random() * noOfSequences); 373 374 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 375 { 376 if (entry.getKey() instanceof Sequence) 377 { 378 if (--noOfSequences <= 0) 379 { 380 return (Sequence) entry.getKey(); 381 } 382 } 383 } 384 } 385 else 386 { 387 return createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 388 } 389 390 throw new RuntimeException("this is an implementation error"); 391 } 392 393 //----------------------------------------------------------------------------------------------- 394 /** 395 * TODO: comment 396 * 397 * @param treeInfos 398 * @return 399 */ 400 //----------------------------------------------------------------------------------------------- 401 private Selection createNewSelection(int maxNoOfChildren, 402 int maxDepth, 403 Map<TaskTreeNode, NodeInfo> treeInfos) 404 throws Exception 405 { 406 Selection selection = mTaskTreeNodeFactory.createNewSelection(); 407 408 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 409 410 for (int i = 0; i < noOfChildren; i++) 411 { 412 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 413 414 // through first removing an existing parent it is assured, that a parent is recorded 415 // only once. This is needed, because parent may be reused in a tree as well, but we always 416 // iterate the whole tree 417 ((NodeInfoImpl) treeInfos.get(child)).removeParent(selection); 418 ((NodeInfoImpl) treeInfos.get(child)).addParent(selection); 419 mTaskTreeBuilder.addChild(selection, child); 420 } 421 422 treeInfos.put(selection, new NodeInfoImpl(selection)); 423 return selection; 424 } 425 426 //----------------------------------------------------------------------------------------------- 427 /** 428 * TODO: comment 429 * 430 * @param treeInfos 431 * @return 432 */ 433 //----------------------------------------------------------------------------------------------- 434 private Selection reuseSelection(int maxNoOfChildren, 435 int maxDepth, 436 Map<TaskTreeNode, NodeInfo> treeInfos) 437 throws Exception 438 { 439 int noOfSelections = 0; 440 441 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 442 { 443 if (entry.getKey() instanceof Selection) 444 { 445 noOfSelections++; 446 } 447 } 448 449 if (noOfSelections > 0) 450 { 451 noOfSelections = (int) (Math.random() * noOfSelections); 452 453 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 454 { 455 if (entry.getKey() instanceof Selection) 456 { 457 if (--noOfSelections <= 0) 458 { 459 return (Selection) entry.getKey(); 460 } 461 } 462 } 463 } 464 else 465 { 466 return createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 467 } 468 469 throw new RuntimeException("this is an implementation error"); 470 } 471 472 //----------------------------------------------------------------------------------------------- 473 /** 474 * TODO: comment 475 * 476 * @param treeInfos 477 * @return 478 */ 479 //----------------------------------------------------------------------------------------------- 480 private Iteration createNewIteration(int maxNoOfChildren, 481 int maxDepth, 482 Map<TaskTreeNode, NodeInfo> treeInfos) 483 throws Exception 484 { 485 Iteration iteration = mTaskTreeNodeFactory.createNewIteration(); 486 487 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 488 489 // through first removing an existing parent it is assured, that a parent is recorded 490 // only once. This is needed, because parent may be reused in a tree as well, but we always 491 // iterate the whole tree 492 ((NodeInfoImpl) treeInfos.get(child)).removeParent(iteration); 493 ((NodeInfoImpl) treeInfos.get(child)).addParent(iteration); 494 mTaskTreeBuilder.setChild(iteration, child); 495 496 treeInfos.put(iteration, new NodeInfoImpl(iteration)); 497 return iteration; 498 } 499 500 //----------------------------------------------------------------------------------------------- 501 /** 502 * TODO: comment 503 * 504 * @param treeInfos 505 * @return 506 */ 507 //----------------------------------------------------------------------------------------------- 508 private Iteration reuseIteration(int maxNoOfChildren, 509 int maxDepth, 510 Map<TaskTreeNode, NodeInfo> treeInfos) 511 throws Exception 512 { 513 int noOfIterations = 0; 514 515 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 516 { 517 if (entry.getKey() instanceof Iteration) 518 { 519 noOfIterations++; 520 } 521 } 522 523 if (noOfIterations > 0) 524 { 525 noOfIterations = (int) (Math.random() * noOfIterations); 526 527 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 528 { 529 if (entry.getKey() instanceof Iteration) 530 { 531 if (--noOfIterations <= 0) 532 { 533 return (Iteration) entry.getKey(); 534 } 535 } 536 } 537 } 538 else 539 { 540 return createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 541 } 542 543 throw new RuntimeException("this is an implementation error"); 544 } 158 case 0: { 159 // System.err.print("creating new event task "); 160 tree = createNewEventTask(treeInfos); 161 break; 162 } 163 case 1: { 164 // System.err.print("reusing event task "); 165 tree = reuseEventTask(treeInfos); 166 break; 167 } 168 case 2: { 169 // System.err.println("creating new sequence {"); 170 tree = createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 171 break; 172 } 173 case 3: { 174 // System.err.println("reusing sequence {"); 175 tree = reuseSequence(maxNoOfChildren, maxDepth, treeInfos); 176 break; 177 } 178 case 4: { 179 // System.err.println("creating new selection {"); 180 tree = createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 181 break; 182 } 183 case 5: { 184 // System.err.println("reusing selection {"); 185 tree = reuseSelection(maxNoOfChildren, maxDepth, treeInfos); 186 break; 187 } 188 case 6: { 189 // System.err.println("creating new iteration {"); 190 tree = createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 191 break; 192 } 193 case 7: { 194 // System.err.println("reusing iteration {"); 195 tree = reuseIteration(maxNoOfChildren, maxDepth, treeInfos); 196 break; 197 } 198 default: { 199 // System.err.print("creating new event task per default "); 200 tree = createNewEventTask(treeInfos); 201 } 202 } 203 204 /* 205 * if (!(tree instanceof InteractionTask)) { for (int i = 0; i < (MAX_TREE_DEPTH + 1 - 206 * maxDepth); i++) { System.err.print(" "); } 207 * 208 * System.err.print("} "); } 209 * 210 * System.err.println(tree); 211 */ 212 213 return tree; 214 } 215 216 /** 217 * TODO: comment 218 * 219 * @param treeInfos 220 * @return 221 */ 222 private IEventTask createNewEventTask(Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 223 throws Exception 224 { 225 Thread.sleep(2); 226 long id = System.currentTimeMillis(); 227 IEventTask task = 228 taskTreeNodeFactory.createNewEventTask(new DummyInteraction("interaction" + id, 1), 229 new DummyGUIElement("elem" + id)); 230 231 treeInfos.put(task, new NodeInfo(task)); 232 233 return task; 234 } 235 236 /** 237 * TODO: comment 238 * 239 * @param treeInfos 240 * @return 241 */ 242 private IEventTask reuseEventTask(Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 243 throws Exception 244 { 245 int noOfEventTasks = 0; 246 247 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 248 if (entry.getKey() instanceof IEventTask) { 249 noOfEventTasks++; 250 } 251 } 252 253 if (noOfEventTasks > 0) { 254 noOfEventTasks = (int) (Math.random() * noOfEventTasks); 255 256 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 257 if (entry.getKey() instanceof IEventTask) { 258 if (--noOfEventTasks <= 0) { 259 return (IEventTask) entry.getKey(); 260 } 261 } 262 } 263 } 264 else { 265 return createNewEventTask(treeInfos); 266 } 267 268 throw new RuntimeException("this is an implementation error"); 269 } 270 271 /** 272 * TODO: comment 273 * 274 * @param treeInfos 275 * @return 276 */ 277 private ISequence createNewSequence(int maxNoOfChildren, 278 int maxDepth, 279 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 280 throws Exception 281 { 282 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 283 284 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 285 286 for (int i = 0; i < noOfChildren; i++) { 287 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 288 289 // through first removing an existing parent it is assured, that a parent is recorded 290 // only once. This is needed, because parent may be reused in a tree as well, but we 291 // always 292 // iterate the whole tree 293 ((NodeInfo) treeInfos.get(child)).removeParent(sequence); 294 ((NodeInfo) treeInfos.get(child)).addParent(sequence); 295 taskTreeBuilder.addChild(sequence, child); 296 } 297 298 treeInfos.put(sequence, new NodeInfo(sequence)); 299 return sequence; 300 } 301 302 /** 303 * TODO: comment 304 * 305 * @param treeInfos 306 * @return 307 */ 308 private ISequence reuseSequence(int maxNoOfChildren, 309 int maxDepth, 310 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 311 throws Exception 312 { 313 int noOfSequences = 0; 314 315 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 316 if (entry.getKey() instanceof ISequence) { 317 noOfSequences++; 318 } 319 } 320 321 if (noOfSequences > 0) { 322 noOfSequences = (int) (Math.random() * noOfSequences); 323 324 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 325 if (entry.getKey() instanceof ISequence) { 326 if (--noOfSequences <= 0) { 327 return (ISequence) entry.getKey(); 328 } 329 } 330 } 331 } 332 else { 333 return createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 334 } 335 336 throw new RuntimeException("this is an implementation error"); 337 } 338 339 /** 340 * TODO: comment 341 * 342 * @param treeInfos 343 * @return 344 */ 345 private ISelection createNewSelection(int maxNoOfChildren, 346 int maxDepth, 347 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 348 throws Exception 349 { 350 ISelection selection = taskTreeNodeFactory.createNewSelection(); 351 352 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 353 354 for (int i = 0; i < noOfChildren; i++) { 355 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 356 357 // through first removing an existing parent it is assured, that a parent is recorded 358 // only once. This is needed, because parent may be reused in a tree as well, but we 359 // always 360 // iterate the whole tree 361 ((NodeInfo) treeInfos.get(child)).removeParent(selection); 362 ((NodeInfo) treeInfos.get(child)).addParent(selection); 363 taskTreeBuilder.addChild(selection, child); 364 } 365 366 treeInfos.put(selection, new NodeInfo(selection)); 367 return selection; 368 } 369 370 /** 371 * TODO: comment 372 * 373 * @param treeInfos 374 * @return 375 */ 376 private ISelection reuseSelection(int maxNoOfChildren, 377 int maxDepth, 378 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 379 throws Exception 380 { 381 int noOfSelections = 0; 382 383 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 384 if (entry.getKey() instanceof ISelection) { 385 noOfSelections++; 386 } 387 } 388 389 if (noOfSelections > 0) { 390 noOfSelections = (int) (Math.random() * noOfSelections); 391 392 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 393 if (entry.getKey() instanceof ISelection) { 394 if (--noOfSelections <= 0) { 395 return (ISelection) entry.getKey(); 396 } 397 } 398 } 399 } 400 else { 401 return createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 402 } 403 404 throw new RuntimeException("this is an implementation error"); 405 } 406 407 /** 408 * TODO: comment 409 * 410 * @param treeInfos 411 * @return 412 */ 413 private IIteration createNewIteration(int maxNoOfChildren, 414 int maxDepth, 415 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 416 throws Exception 417 { 418 IIteration iteration = taskTreeNodeFactory.createNewIteration(); 419 420 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 421 422 // through first removing an existing parent it is assured, that a parent is recorded 423 // only once. This is needed, because parent may be reused in a tree as well, but we always 424 // iterate the whole tree 425 ((NodeInfo) treeInfos.get(child)).removeParent(iteration); 426 ((NodeInfo) treeInfos.get(child)).addParent(iteration); 427 taskTreeBuilder.setChild(iteration, child); 428 429 treeInfos.put(iteration, new NodeInfo(iteration)); 430 return iteration; 431 } 432 433 /** 434 * TODO: comment 435 * 436 * @param treeInfos 437 * @return 438 */ 439 private IIteration reuseIteration(int maxNoOfChildren, 440 int maxDepth, 441 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 442 throws Exception 443 { 444 int noOfIterations = 0; 445 446 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 447 if (entry.getKey() instanceof IIteration) { 448 noOfIterations++; 449 } 450 } 451 452 if (noOfIterations > 0) { 453 noOfIterations = (int) (Math.random() * noOfIterations); 454 455 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 456 if (entry.getKey() instanceof IIteration) { 457 if (--noOfIterations <= 0) { 458 return (IIteration) entry.getKey(); 459 } 460 } 461 } 462 } 463 else { 464 return createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 465 } 466 467 throw new RuntimeException("this is an implementation error"); 468 } 545 469 546 470 } -
trunk/quest-core-tasktrees/pom.xml
r502 r557 11 11 <dependency> 12 12 <groupId>de.ugoe.cs.quest</groupId> 13 <artifactId>quest-core-events -patrick</artifactId>13 <artifactId>quest-core-events</artifactId> 14 14 <version>0.0.1-SNAPSHOT</version> 15 15 </dependency> -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/ComponentManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: ComponentManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.manager; 9 8 10 9 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 11 10 import de.ugoe.cs.quest.tasktrees.temporalrelation.TemporalRelationshipRuleManager; 12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder Impl;15 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory Impl;11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 // ------------------------------------------------------------------------------------------------- 25 public class ComponentManager 26 { 27 /** */ 28 private static ComponentManager sInstance; 22 public class ComponentManager { 23 24 /** */ 25 private static ComponentManager instance; 29 26 30 /** */ 31 private TemporalRelationshipRuleManager mTemporalRelationshipRuleManager; 32 33 /** */ 34 private NodeEqualityRuleManager mNodeEqualityRuleManager; 27 /** */ 28 private TemporalRelationshipRuleManager temporalRelationshipRuleManager; 35 29 36 /** */37 private TaskTreeBuilder mTaskTreeBuilder;30 /** */ 31 private NodeEqualityRuleManager nodeEqualityRuleManager; 38 32 39 /** */40 private TaskTreeNodeFactory mTaskTreeNodeFactory;33 /** */ 34 private ITaskTreeBuilder taskTreeBuilder; 41 35 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * TODO: comment 45 * 46 * @return 47 */ 48 //----------------------------------------------------------------------------------------------- 49 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() 50 { 51 return getInstance().mTemporalRelationshipRuleManager; 52 } 36 /** */ 37 private ITaskTreeNodeFactory taskTreeNodeFactory; 53 38 54 //----------------------------------------------------------------------------------------------- 55 /** 56 * TODO: comment 57 * 58 * @return 59 */ 60 //----------------------------------------------------------------------------------------------- 61 public static NodeEqualityRuleManager getNodeEqualityRuleManager() 62 { 63 return getInstance().mNodeEqualityRuleManager; 64 } 39 /** 40 * TODO: comment 41 * 42 * @return 43 */ 44 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() { 45 return getInstance().temporalRelationshipRuleManager; 46 } 65 47 66 //----------------------------------------------------------------------------------------------- 67 /** 68 * TODO: comment 69 * 70 * @return 71 */ 72 //----------------------------------------------------------------------------------------------- 73 public static TaskTreeBuilder getDefaultTaskTreeBuilder() 74 { 75 return getInstance().mTaskTreeBuilder; 76 } 48 /** 49 * TODO: comment 50 * 51 * @return 52 */ 53 public static NodeEqualityRuleManager getNodeEqualityRuleManager() { 54 return getInstance().nodeEqualityRuleManager; 55 } 77 56 78 //----------------------------------------------------------------------------------------------- 79 /** 80 * TODO: comment 81 * 82 * @return 83 */ 84 //----------------------------------------------------------------------------------------------- 85 public static TaskTreeNodeFactory getDefaultTaskTreeNodeFactory() 86 { 87 return getInstance().mTaskTreeNodeFactory; 88 } 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 public static ITaskTreeBuilder getDefaultTaskTreeBuilder() { 63 return getInstance().taskTreeBuilder; 64 } 89 65 90 //----------------------------------------------------------------------------------------------- 91 /** 92 * TODO: comment 93 * 94 * @return 95 */ 96 //----------------------------------------------------------------------------------------------- 97 public static synchronized void clearInstance() 98 { 99 sInstance = null; 100 } 66 /** 67 * TODO: comment 68 * 69 * @return 70 */ 71 public static ITaskTreeNodeFactory getDefaultTaskTreeNodeFactory() { 72 return getInstance().taskTreeNodeFactory; 73 } 101 74 102 //----------------------------------------------------------------------------------------------- 103 /** 104 * TODO: comment 105 * 106 * @return 107 */ 108 //----------------------------------------------------------------------------------------------- 109 private static synchronized ComponentManager getInstance() 110 { 111 if (sInstance == null) 112 { 113 sInstance = new ComponentManager(); 114 sInstance.init(); 75 /** 76 * TODO: comment 77 * 78 * @return 79 */ 80 public static synchronized void clearInstance() { 81 instance = null; 115 82 } 116 return sInstance;117 }118 83 119 //----------------------------------------------------------------------------------------------- 120 /** 121 * TODO: comment 122 * 123 */ 124 //----------------------------------------------------------------------------------------------- 125 private void init() 126 { 127 mNodeEqualityRuleManager = new NodeEqualityRuleManager(); 128 mNodeEqualityRuleManager.init(); 129 130 mTemporalRelationshipRuleManager = 131 new TemporalRelationshipRuleManager(mNodeEqualityRuleManager); 132 mTemporalRelationshipRuleManager.init(); 84 /** 85 * TODO: comment 86 * 87 * @return 88 */ 89 private static synchronized ComponentManager getInstance() { 90 if (instance == null) { 91 instance = new ComponentManager(); 92 instance.init(); 93 } 94 return instance; 95 } 133 96 134 mTaskTreeBuilder = new TaskTreeBuilderImpl(); 135 mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 136 } 97 /** 98 * TODO: comment 99 * 100 */ 101 private void init() { 102 nodeEqualityRuleManager = new NodeEqualityRuleManager(); 103 nodeEqualityRuleManager.init(); 104 105 temporalRelationshipRuleManager = 106 new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 107 temporalRelationshipRuleManager.init(); 108 109 taskTreeBuilder = new TaskTreeBuilder(); 110 taskTreeNodeFactory = new TaskTreeNodeFactory(); 111 } 137 112 138 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManager.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:14:21 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.manager; 10 8 11 import java.util.Observable;12 import java.util.Observer;13 9 import java.util.logging.Logger; 14 10 15 import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; 16 import de.ugoe.cs.quest.eventcore.userinteraction.InteractionEvent; 17 import de.ugoe.cs.quest.eventcore.userinteraction.KeyInteraction; 18 import de.ugoe.cs.quest.eventcore.userinteraction.KeyboardFocusChange; 19 import de.ugoe.cs.quest.eventcore.userinteraction.UserInteractionProvider; 20 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 21 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 22 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 23 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 24 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 25 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 11 import de.ugoe.cs.quest.eventcore.Event; 12 import de.ugoe.cs.quest.eventcore.IEventTarget; 13 import de.ugoe.cs.quest.eventcore.gui.KeyInteraction; 14 import de.ugoe.cs.quest.eventcore.gui.KeyboardFocusChange; 15 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 20 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 26 21 27 //-------------------------------------------------------------------------------------------------28 22 /** 29 23 * TODO comment 30 * 24 * 31 25 * @version $Revision: $ $Date: $ 32 * @author 26 * @author 2011, last modified by $Author: $ 33 27 */ 34 //------------------------------------------------------------------------------------------------- 35 public class TaskTreeManager implements Observer 36 { 37 /** */ 38 private static final int MAX_INTERACTIONS_TILL_RULE_APPLICATION = 100; 28 public class TaskTreeManager { 29 30 /** */ 31 private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100; 39 32 40 /** */ 41 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 42 43 /** */ 44 private TaskTreeBuilder mTaskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 45 46 /** */ 47 private TaskTreeNodeFactory mTaskTreeNodeFactory = 48 ComponentManager.getDefaultTaskTreeNodeFactory(); 49 50 /** */ 51 private int mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION; 52 53 /** */ 54 private Sequence mRootSequence; 55 56 /** */ 57 private GUIElement mCurrentKeyboardFocusGUIElement; 33 /** */ 34 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 58 35 59 //----------------------------------------------------------------------------------------------- 60 /** 61 * TODO: comment 62 * 63 */ 64 //----------------------------------------------------------------------------------------------- 65 public TaskTreeManager() 66 { 67 mRootSequence = mTaskTreeNodeFactory.createNewSequence(); 68 } 36 /** */ 37 private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 69 38 70 //----------------------------------------------------------------------------------------------- 71 /* (non-Javadoc) 72 * @see java.util.Observer#update(java.util.Observable, java.lang.Object) 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void update(Observable observable, Object event) 76 { 77 if ((observable instanceof UserInteractionProvider) && 78 (event instanceof InteractionEvent)) 39 /** */ 40 private ITaskTreeNodeFactory taskTreeNodeFactory = 41 ComponentManager.getDefaultTaskTreeNodeFactory(); 42 43 /** */ 44 private int eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 45 46 /** */ 47 private ISequence rootSequence; 48 49 /** */ 50 private IEventTarget currentKeyboardFocusGUIElement; 51 52 /** 53 * TODO: comment 54 * 55 */ 56 public TaskTreeManager() { 57 rootSequence = taskTreeNodeFactory.createNewSequence(); 58 } 59 60 /** 61 * 62 */ 63 public void handleNewEvent(Event event) { 64 if (event.getType() instanceof KeyInteraction) { 65 if (currentKeyboardFocusGUIElement == null) { 66 currentKeyboardFocusGUIElement = event.getTarget(); 67 } 68 69 addEventTask 70 (taskTreeNodeFactory.createNewEventTask 71 (event.getType(), currentKeyboardFocusGUIElement)); 72 } 73 else { 74 addEventTask 75 (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 76 } 77 } 78 79 /** 80 * 81 */ 82 public synchronized ITaskTree getTaskTree() { 83 LOG.info("applying rules temporal relationship generation rules"); 84 85 ISequence currentRootSequence = rootSequence.clone(); 86 ComponentManager.getTemporalRelationshipRuleManager().applyRules 87 (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true); 88 89 return taskTreeNodeFactory.createTaskTree(currentRootSequence); 90 } 91 92 /** 93 * @param task 94 */ 95 private synchronized void addEventTask(IEventTask task) { 96 handleEventTask(task); 97 } 98 99 /** 100 * adds the task to the current or the new sequence. The decision depends on the type of task. 101 * If the task finishes the current sequence, the sequence is marked as finished If the task 102 * does not start a new sequence, it is added to the current sequence, before it is marked s 103 * finished. Otherwise it is added to a new sequence. 104 */ 105 private void handleEventTask(IEventTask eventTask) { 106 if (eventTask.getEventType() instanceof KeyboardFocusChange) { 107 currentKeyboardFocusGUIElement = eventTask.getEventTarget(); 108 } 109 else { 110 LOG.info("handling event task \"" + eventTask + "\""); 111 addTaskToSequence(eventTask, currentKeyboardFocusGUIElement); 112 } 113 } 114 115 /** 116 * 117 */ 118 private void addTaskToSequence(ITaskTreeNode task, IEventTarget currentKeyboardFocusGUIElement) 79 119 { 80 handleNewInteractionEvent((InteractionEvent) event); 120 taskTreeBuilder.addChild(rootSequence, task); 121 122 if (--eventsTillRuleApplication == 0) { 123 eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 124 125 LOG.info("applying rules temporal relationship generation rules"); 126 ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence, 127 taskTreeBuilder, 128 taskTreeNodeFactory, 129 false); 130 } 81 131 } 82 else83 {84 LOG.warning("could not handle notification of " + observable + " regarding " + event);85 }86 }87 88 //-----------------------------------------------------------------------------------------------89 /**90 *91 */92 //-----------------------------------------------------------------------------------------------93 public void handleNewInteractionEvent(InteractionEvent event)94 {95 if (event.getInteraction() instanceof KeyInteraction)96 {97 if (mCurrentKeyboardFocusGUIElement == null)98 {99 mCurrentKeyboardFocusGUIElement = event.getGUIElement();100 }101 102 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask103 (mCurrentKeyboardFocusGUIElement, event.getInteraction()));104 }105 else106 {107 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask108 (event.getGUIElement(), event.getInteraction()));109 }110 }111 112 //-----------------------------------------------------------------------------------------------113 /**114 *115 */116 //-----------------------------------------------------------------------------------------------117 public synchronized TaskTree getTaskTree()118 {119 LOG.info("applying rules temporal relationship generation rules");120 121 Sequence rootSequence = mRootSequence.clone();122 ComponentManager.getTemporalRelationshipRuleManager().applyRules123 (rootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, true);124 125 return mTaskTreeNodeFactory.createTaskTree(rootSequence);126 }127 128 //-----------------------------------------------------------------------------------------------129 /**130 * @param task131 */132 //-----------------------------------------------------------------------------------------------133 private synchronized void addInteractionTask(InteractionTask task)134 {135 handleInteractionTask(task);136 }137 138 //-----------------------------------------------------------------------------------------------139 /**140 * adds the task to the current or the new sequence. The decision depends on the type141 * of task. If the task finishes the current sequence, the sequence is marked as finished142 * If the task does not start a new sequence, it is added to the current sequence, before it143 * is marked s finished. Otherwise it is added to a new sequence.144 */145 //-----------------------------------------------------------------------------------------------146 private void handleInteractionTask(InteractionTask interactionTask)147 {148 if (interactionTask.getInteraction() instanceof KeyboardFocusChange)149 {150 mCurrentKeyboardFocusGUIElement = interactionTask.getGUIElement();151 }152 else153 {154 LOG.info("handling interaction task \"" + interactionTask + "\"");155 addTaskToSequence(interactionTask, mCurrentKeyboardFocusGUIElement);156 }157 }158 159 //-----------------------------------------------------------------------------------------------160 /**161 * TODO: comment162 *163 * @param interactionTask164 */165 //-----------------------------------------------------------------------------------------------166 /*private boolean handleAndCorrectFocusChanges(InteractionTask interactionTask)167 {168 GUIElement newGUIElement = interactionTask.getGUIElement();169 170 // find the identical parent element171 GUIElement identicalParentGUIElement = null;172 173 while ((identicalParentGUIElement == null) && (newGUIElement != null))174 {175 GUIElement currentGUIElement = mCurrentGUIElement;176 177 while ((identicalParentGUIElement == null) && (currentGUIElement != null))178 {179 if (newGUIElement.equals(currentGUIElement))180 {181 identicalParentGUIElement = newGUIElement;182 }183 else184 {185 currentGUIElement = currentGUIElement.getParent();186 }187 }188 189 newGUIElement = newGUIElement.getParent();190 }191 192 // now create focus lost interactions for each GUI element, that is not common with the193 // hierarchy of the new GUI element194 GUIElement currentGUIElement = mCurrentGUIElement;195 196 List<InteractionTask> tasksToBeAdded = new ArrayList<InteractionTask>();197 198 while ((currentGUIElement != null) &&199 ((identicalParentGUIElement == null) ||200 (!currentGUIElement.equals(identicalParentGUIElement))))201 {202 tasksToBeAdded.add203 (mTaskTreeNodeFactory.createNewInteractionTask(currentGUIElement, new FocusLost()));204 currentGUIElement = currentGUIElement.getParent();205 }206 207 // now create focus received interactions for each GUI element, that is not common with208 // with the old one. Ensure, that if the current interaction is a focus reception, that209 // it is used instead of a generated one210 newGUIElement = interactionTask.getGUIElement();211 212 int index = tasksToBeAdded.size();213 while ((newGUIElement != null) &&214 ((identicalParentGUIElement == null) ||215 (!newGUIElement.equals(identicalParentGUIElement))))216 {217 tasksToBeAdded.add(index, mTaskTreeNodeFactory.createNewInteractionTask218 (newGUIElement, new FocusReceived()));219 newGUIElement = newGUIElement.getParent();220 }221 222 // this part ensures, that the original focus reception, if any, is preserved as is.223 boolean taskAlreadyHandled = false;224 if (interactionTask.getInteraction() instanceof FocusReceived)225 {226 if (tasksToBeAdded.size() > 0)227 {228 tasksToBeAdded.set(tasksToBeAdded.size() - 1, interactionTask);229 }230 //else231 //{232 // in this case, we already have focus on the element to which the focus shall be changed.233 // therefore, we discard the new focus change on the same element.234 //}235 236 taskAlreadyHandled = true;237 }238 239 // now that all tasks are determined, add them to the sequence240 for (InteractionTask task : tasksToBeAdded)241 {242 addTaskToSequence(task);243 }244 245 mCurrentGUIElement = interactionTask.getGUIElement();246 247 return taskAlreadyHandled;248 }*/249 250 //-----------------------------------------------------------------------------------------------251 /**252 *253 */254 //-----------------------------------------------------------------------------------------------255 private void addTaskToSequence(TaskTreeNode task, GUIElement currentKeyboardFocusGUIElement)256 {257 mTaskTreeBuilder.addChild(mRootSequence, task);258 259 if (--mInteractionsTillRuleApplication == 0)260 {261 mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION;262 263 LOG.info("applying rules temporal relationship generation rules");264 ComponentManager.getTemporalRelationshipRuleManager().applyRules265 (mRootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, false);266 }267 }268 132 269 133 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/IterationComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 * TODO comment 14 * <p> 15 * This class is capable of comparing Iterations. Iterations equal at distinct levels 16 * in distinct situations. The following table shows the results of the comparison for the 17 * specific situations (the parameters are commutative). In any other situation, the comparison 18 * returns <code>NodeEquality.UNEQUAL</code>: 19 * </p> 20 * 21 * <table border="1"> 22 * <tr> 23 * <th>iteration 1</th> 24 * <th>iteration 2</th> 25 * <th>comparison result</th> 26 * </tr> 27 * <tr> 28 * <td>any iteration</td> 29 * <td>any iteration with a child that is lexically equal to the child of iteration 1</td> 30 * <td><code>NodeEquality.LEXICALLY_EQUAL</code></td> 31 * </tr> 32 * <tr> 33 * <td>any iteration</td> 34 * <td>any iteration with a child that is syntactically equal to the child of iteration 1</td> 35 * <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 36 * </tr> 37 * <tr> 38 * <td>any iteration</td> 39 * <td>any iteration with a child that is semantically equal to the child of iteration 1</td> 40 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 41 * </tr> 42 * <tr> 43 * <td>an iteration with a selection of syntactically equal children</td> 44 * <td>an iteration with a child that is syntactically equal to the children of the child 45 * selection of iteration 1</td> 46 * <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 47 * </tr> 48 * <tr> 49 * <td>an iteration with a selection of semantically equal children</td> 50 * <td>an iteration with a child that is semantically equal to the children of the child 51 * selection of iteration 1</td> 52 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 53 * </tr> 54 * </table> 17 55 * 18 56 * @version $Revision: $ $Date: 19.02.2012$ 19 57 * @author 2012, last modified by $Author: patrick$ 20 58 */ 21 //------------------------------------------------------------------------------------------------- 22 public class IterationComparisonRule implements NodeComparisonRule 23 { 24 /** */ 25 private NodeEqualityRuleManager mRuleManager; 59 public class IterationComparisonRule implements NodeComparisonRule { 60 61 /** the rule manager for internally comparing task tree nodes */ 62 private NodeEqualityRuleManager mRuleManager; 26 63 27 //----------------------------------------------------------------------------------------------- 28 /** 29 * TODO: comment 30 * 31 */ 32 //----------------------------------------------------------------------------------------------- 33 IterationComparisonRule(NodeEqualityRuleManager ruleManager) 34 { 35 super(); 36 mRuleManager = ruleManager; 37 } 38 39 //----------------------------------------------------------------------------------------------- 40 /* (non-Javadoc) 41 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 42 */ 43 //----------------------------------------------------------------------------------------------- 44 @Override 45 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 46 { 47 if ((!(node1 instanceof Iteration)) || (!(node2 instanceof Iteration))) 48 { 49 return null; 50 } 51 52 // if both iterations do not have children, they are equal although this doesn't make sense 53 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) 54 { 55 return new NodesIdentical(); 56 } 57 58 TaskTreeNode child1 = node1.getChildren().get(0); 59 TaskTreeNode child2 = node2.getChildren().get(0); 60 61 // iterations may have 3 different structures. 62 // 1. they have one child, which is the iterated one 63 // 2. they have a sequence of children, which is iterated 64 // 3. they have a selection of different iterated variants (usually the variants are 65 // semantically equal) 66 // 67 // the permutations of the three variants in combination must be checked 68 69 // check if both nodes are the same variants of iterations and if their children are equal. 70 // This condition matches, if both iterations are the same variants of iteration. I.e. three 71 // combinations of the permutation are handled herewith. 72 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 73 74 if (nodeEquality.getStructuralEquality() || nodeEquality.getSemanticalEquality()) 75 { 76 return nodeEquality; 77 } 78 79 // compare one iteration with a single node as a child and another one with a selection of 80 // semantically equal nodes 81 if (selectionChildrenSemanticallyEqualNode(child1, child2)) 82 { 83 return new NodesSemanticallyEqual(); 64 /** 65 * <p> 66 * simple constructor to provide the rule with the node equality rule manager to be able 67 * to perform comparisons of the children of provided task tree nodes 68 * </p> 69 * 70 * @param ruleManager the rule manager for comparing task tree nodes 71 */ 72 IterationComparisonRule(NodeEqualityRuleManager ruleManager) { 73 super(); 74 mRuleManager = ruleManager; 84 75 } 85 76 86 // all other combinations (i.e. sequence with single child and sequence with selection) 87 // can not match 88 return null; 89 } 77 /* 78 * (non-Javadoc) 79 * 80 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 81 */ 82 @Override 83 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 84 if ((!(node1 instanceof IIteration)) || (!(node2 instanceof IIteration))) { 85 return null; 86 } 90 87 91 //----------------------------------------------------------------------------------------------- 92 /** 93 * TODO: comment 94 * 95 * @param taskTreeNode 96 * @param taskTreeNode2 97 * @return 98 */ 99 //----------------------------------------------------------------------------------------------- 100 private boolean selectionChildrenSemanticallyEqualNode(TaskTreeNode taskTreeNode, 101 TaskTreeNode taskTreeNode2) 102 { 103 Selection selection = null; 104 TaskTreeNode node = null; 105 if (taskTreeNode instanceof Selection) 88 // if both iterations do not have children, they are equal although this doesn't make sense 89 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 90 return NodeEquality.IDENTICAL; 91 } 92 93 ITaskTreeNode child1 = node1.getChildren().get(0); 94 ITaskTreeNode child2 = node2.getChildren().get(0); 95 96 // iterations may have 3 different structures. 97 // 1. they have one child, which is the iterated one 98 // 2. they have a sequence of children, which is iterated 99 // 3. they have a selection of different iterated variants (usually the variants are 100 // semantically equal) 101 // 102 // the permutations of the three variants in combination must be checked 103 104 // check if both nodes are the same variants of iterations and if their children are equal. 105 // This condition matches, if both iterations are the same variants of iteration. I.e. three 106 // combinations of the permutation are handled herewith. 107 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 108 109 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 110 return nodeEquality; 111 } 112 113 // compare one iteration with a single node as a child and another one with a selection of 114 // semantically equal nodes 115 return selectionChildrenSemanticallyEqualNode(child1, child2); 116 117 // all other combinations (i.e. sequence with single child and sequence with selection) 118 // can not match 119 } 120 121 /** 122 * <p> 123 * compares two task tree nodes. One of them must be a selection of at least semantically 124 * equal children. The other one can be any task tree node. The method returns a node equality 125 * that is not <code>NodeEquality.UNEQUAL</code> if the other node is at least semantically 126 * equal to the children of the selection. It returns more concrete equalities, if the 127 * equality between the other node and the children of the selection is more concrete. 128 * </p> 129 * 130 * @param taskTreeNode the first task tree node to compare 131 * @param taskTreeNode2 the second task tree node to compare 132 * 133 * @return as described 134 */ 135 private NodeEquality selectionChildrenSemanticallyEqualNode(ITaskTreeNode taskTreeNode, 136 ITaskTreeNode taskTreeNode2) 106 137 { 107 selection = (Selection) taskTreeNode; 108 node = taskTreeNode2; 138 ISelection selection = null; 139 ITaskTreeNode node = null; 140 if (taskTreeNode instanceof ISelection) { 141 selection = (ISelection) taskTreeNode; 142 node = taskTreeNode2; 143 } 144 else if (taskTreeNode2 instanceof ISelection) { 145 selection = (ISelection) taskTreeNode2; 146 node = taskTreeNode; 147 } 148 else { 149 return NodeEquality.UNEQUAL; 150 } 151 152 NodeEquality lessConcreteEqualityForAllComparisons = NodeEquality.IDENTICAL; 153 154 for (ITaskTreeNode child : selection.getChildren()) { 155 NodeEquality nodeEquality = mRuleManager.applyRules(node, child); 156 157 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 158 return NodeEquality.UNEQUAL; 159 } 160 else if (!lessConcreteEqualityForAllComparisons.isAtLeast(nodeEquality)) { 161 lessConcreteEqualityForAllComparisons = nodeEquality; 162 } 163 } 164 165 return lessConcreteEqualityForAllComparisons; 109 166 } 110 else if (taskTreeNode2 instanceof Selection)111 {112 selection = (Selection) taskTreeNode2;113 node = taskTreeNode;114 }115 else116 {117 return false;118 }119 120 for (TaskTreeNode child : selection.getChildren())121 {122 NodeEquality nodeEquality = mRuleManager.applyRules(node, child);123 124 if (!nodeEquality.getStructuralEquality() && !nodeEquality.getSemanticalEquality())125 {126 return false;127 }128 }129 130 return true;131 }132 167 133 168 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: EqualityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 * TODO comment 12 * <p> 13 * A node comparison rule is used by the {@link NodeEqualityRuleManager} to compare task tree 14 * nodes with each other. It provides one method to be called for a comparison. 15 * </p> 15 16 * 16 17 * @version $Revision: $ $Date: 19.02.2012$ 17 18 * @author 2012, last modified by $Author: patrick$ 18 19 */ 19 //------------------------------------------------------------------------------------------------- 20 public interface NodeComparisonRule 21 { 20 public interface NodeComparisonRule { 22 21 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * compares two nodes with each other. The result of the method is either a node equality or 26 * null. If it is null, it means, that the rule is not able to correctly compare the two 27 * given nodes 28 */ 29 //----------------------------------------------------------------------------------------------- 30 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2); 31 22 /** 23 * <p> 24 * compares two nodes with each other. The result of the method is either a node equality or 25 * null. If it is null, it means, that the rule is not able to correctly compare the two given 26 * nodes 27 * </p> 28 * 29 * @param node1 the first task tree node to compare 30 * @param node2 the second task tree node to compare 31 * 32 * @return as described 33 */ 34 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2); 35 32 36 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEquality.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeEquality.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 * TODO comment 10 * <p> 11 * A node equality denotes, how equal two task tree nodes are. There are different equality levels 12 * which are similar to the usual design levels of GUI design. These levels are 13 * <ul> 14 * <li>conceptual design: defines the concepts to be edited using a GUI</li> 15 * <li>semantical design: defines the possible functions for editing the concepts</li> 16 * <li>syntactical design: defines, which steps are needed to execute the functions</li> 17 * <li>lexical design: defines on the key stroke level, how the steps for executing a function 18 * can be performed</li> 19 * </ul> 20 * It is not possible to compare two task nodes conceptually. But the other design levels can be 21 * identified and compared. 22 * </p> 23 * <p> 24 * Nodes can be identical. This is the case if in the java virtual machine, their comparison 25 * using the <code>==</code> operator or the equals method return true. 26 * </p> 27 * <p> 28 * Nodes are lexically equal, if they represent the same events on a key stroke level to be 29 * carried out to execute the task. Identical nodes are also syntactically equal. 30 * </p> 31 * <p> 32 * Nodes are syntactically equal, if they differ in their events on key stroke level, but the 33 * syntactical result is the same. For example, entering the text "hello" into a text field can 34 * be done by entering the letters in their correct order, but also by copying the text into the 35 * text field. The syntactical result is the same: The text hello was entered. But the tasks 36 * lexically differ because the events on key stroke level are different. On the other hand, 37 * lexically equal nodes are also syntactically equal. 38 * </p> 39 * <p> 40 * Task tree nodes are semantically equal, if they execute the same function for editing the 41 * concepts. An example are a click on a button and a short cut, both executing the same function. 42 * These task tree nodes are syntactically and, therefore, also lexically different, but 43 * semantically equal. Syntactically equal task tree nodes are always also semantically equal. 44 * </p> 13 45 * 14 46 * @version $Revision: $ $Date: 19.02.2012$ 15 47 * @author 2012, last modified by $Author: patrick$ 16 48 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface NodeEquality 19 { 49 public enum NodeEquality { 50 IDENTICAL, 51 LEXICALLY_EQUAL, 52 SYNTACTICALLY_EQUAL, 53 SEMANTICALLY_EQUAL, 54 UNEQUAL; 20 55 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @return 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public boolean getStructuralEquality(); 29 30 //----------------------------------------------------------------------------------------------- 31 /** 32 * TODO: comment 33 * 34 * @return 35 */ 36 //----------------------------------------------------------------------------------------------- 37 public boolean getSemanticalEquality(); 38 56 /** 57 * <p> 58 * Checks for the current node equality, if it is at least identical to the 59 * provided one or even more concrete. As an example, the node equality identical also 60 * indicates, that the nodes are e.g. lexically, syntactically and semantically equal. 61 * Therefore, the method called on <code>IDENTICAL</code> with <code>SEMANTICALLY_EQUAL</code> 62 * as parameter will return true. If this method is called on <code>SYNTACTICALLY_EQUAL</code> 63 * with the parameter <code>IDENTICAL</code> instead, it returns false; 64 * </p> 65 * 66 * @param nodeEquality the node equality to compare with. 67 * 68 * @return as described 69 */ 70 public boolean isAtLeast(NodeEquality nodeEquality) 71 { 72 switch (nodeEquality) { 73 case IDENTICAL: 74 return 75 (this == IDENTICAL); 76 case LEXICALLY_EQUAL: 77 return 78 (this == IDENTICAL) || 79 (this == LEXICALLY_EQUAL); 80 case SYNTACTICALLY_EQUAL: 81 return 82 (this == IDENTICAL) || 83 (this == LEXICALLY_EQUAL) || 84 (this == SYNTACTICALLY_EQUAL); 85 case SEMANTICALLY_EQUAL: 86 return 87 (this == IDENTICAL) || 88 (this == LEXICALLY_EQUAL) || 89 (this == SYNTACTICALLY_EQUAL) || 90 (this == SEMANTICALLY_EQUAL); 91 case UNEQUAL: 92 return 93 (this == UNEQUAL); 94 default : 95 return false; 96 } 97 } 39 98 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeEqualityRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 9 import java.util.ArrayList; 11 10 import java.util.List; 12 //import java.util.logging.Logger;13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 13 16 //-------------------------------------------------------------------------------------------------17 14 /** 18 * TODO comment 15 * <p> 16 * The node equality rule manager is capable of comparing task tree nodes based on its internal list 17 * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the 18 * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and 19 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree 20 * nodes in the mentioned order. If a rule returns a node equality other than null, this equality is 21 * returned. Otherwise the next rule is asked. 22 * </p> 19 23 * 20 24 * @version $Revision: $ $Date: 19.02.2012$ 21 25 * @author 2012, last modified by $Author: patrick$ 22 26 */ 23 //------------------------------------------------------------------------------------------------- 24 public class NodeEqualityRuleManager 25 { 27 public class NodeEqualityRuleManager { 26 28 27 /** */28 //private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName());29 /** */ 30 // private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName()); 29 31 30 /** */31 private List<NodeComparisonRule> mRuleIndex = new ArrayList<NodeComparisonRule>();32 /** */ 33 private List<NodeComparisonRule> mRuleIndex = null; 32 34 33 //-----------------------------------------------------------------------------------------------34 /**35 * TODO: comment36 *37 */38 //-----------------------------------------------------------------------------------------------39 public void init()40 {41 mRuleIndex.add(new NodeIdentityRule());42 mRuleIndex.add(new IterationComparisonRule(this));43 mRuleIndex.add(new SequenceComparisonRule(this));44 mRuleIndex.add(new SelectionComparisonRule(this));45 }35 /** 36 * <p> 37 * initializes the node equality rule manager by filling the internal list of comparison rules. 38 * This method must be called before any other method is called on the rule manager. 39 * </p> 40 */ 41 public void init() { 42 mRuleIndex = new ArrayList<NodeComparisonRule>(); 43 mRuleIndex.add(new NodeIdentityRule()); 44 mRuleIndex.add(new IterationComparisonRule(this)); 45 mRuleIndex.add(new SequenceComparisonRule(this)); 46 mRuleIndex.add(new SelectionComparisonRule(this)); 47 } 46 48 47 //----------------------------------------------------------------------------------------------- 48 /** 49 * TODO: comment 50 * 51 * @param node1 52 * @param node2 53 * @return 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public NodeEquality applyRules(TaskTreeNode node1, TaskTreeNode node2) 57 { 58 //LOG.info("checking for equality of " + node1 + " and " + node2); 59 NodeEquality nodeEquality = null; 60 61 for (NodeComparisonRule rule : mRuleIndex) 49 /** 50 * <p> 51 * this method performs a comparison of the two provided task tree nodes. It iterates its 52 * internal comparison rules. If the first rule returns a node equality other than null, 53 * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality 54 * <code>NodeEquality.UNEQUAL</code> is returned. 55 * </p> 56 * 57 * @param node1 the first task tree node to be compared 58 * @param node2 the second task tree node to be compared 59 * 60 * @return as described 61 * 62 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 63 * manager before a call to this method. 64 */ 65 public NodeEquality applyRules(ITaskTreeNode node1, ITaskTreeNode node2) 66 throws IllegalStateException 62 67 { 63 nodeEquality = rule.compare(node1, node2); 64 65 if (nodeEquality != null) 66 { 67 //LOG.warning("used rule " + rule + " for equality check"); 68 return nodeEquality; 69 } 68 if (mRuleIndex == null) { 69 throw new IllegalStateException("not initialized"); 70 } 71 72 // LOG.info("checking for equality of " + node1 + " and " + node2); 73 NodeEquality nodeEquality = null; 74 75 for (NodeComparisonRule rule : mRuleIndex) { 76 nodeEquality = rule.compare(node1, node2); 77 78 if (nodeEquality != null) { 79 // LOG.warning("used rule " + rule + " for equality check"); 80 return nodeEquality; 81 } 82 } 83 84 // LOG.warning("no rule could be applied --> handling nodes as unequal"); 85 86 return NodeEquality.UNEQUAL; 70 87 } 71 72 //LOG.warning("no rule could be applied --> handling nodes as unequal");73 74 return new NodesUnequal();75 }76 88 77 89 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeIdentityRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 * TODO comment 12 * <p> 13 * This comparison rule returns <code>NodeEquality.IDENTICAL</code> if the comparison of the two 14 * task tree nodes using the <code>==</code> operator or the <code>equals</code> method return true. 15 * Else it returns null to denote, that it can not compare the nodes. 16 * </p> 15 17 * 16 18 * @version $Revision: $ $Date: 19.02.2012$ 17 19 * @author 2012, last modified by $Author: patrick$ 18 20 */ 19 //------------------------------------------------------------------------------------------------- 20 public class NodeIdentityRule implements NodeComparisonRule 21 { 21 public class NodeIdentityRule implements NodeComparisonRule { 22 22 23 //----------------------------------------------------------------------------------------------- 24 /* (non-Javadoc) 25 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 26 */ 27 //----------------------------------------------------------------------------------------------- 28 @Override 29 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 30 { 31 if (node1 == node2) 32 { 33 return new NodesIdentical(); 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 27 */ 28 @Override 29 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 30 if ((node1 == node2) || ((node1 != null) && (node1.equals(node2)))) { 31 return NodeEquality.IDENTICAL; 32 } 33 else { 34 return null; 35 } 34 36 } 35 else if ((node1 != null) && (node1.equals(node2)))36 {37 return new NodesEqual();38 }39 else40 {41 return null;42 }43 }44 37 45 38 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 * TODO comment 13 * <p> 14 * this node comparison rule is capable of comparing selections. If both selections do not have 15 * children, they are treated as lexically equal. If they have the same number of children other 16 * than 0 and all these children are lexically equal, then the selections are lexically equal. 17 * They are syntactically equal, if each child of both selections is syntactically equal to any 18 * other child. The rule can not compare semantical equality if the nodes are not at least 19 * syntactically equal and returns null, if it can not decide this. 20 * </p> 16 21 * 17 22 * @version $Revision: $ $Date: 19.02.2012$ 18 23 * @author 2012, last modified by $Author: patrick$ 19 24 */ 20 //------------------------------------------------------------------------------------------------- 21 public class SelectionComparisonRule implements NodeComparisonRule 22 { 25 public class SelectionComparisonRule implements NodeComparisonRule { 23 26 24 /***/25 private NodeEqualityRuleManager mRuleManager;27 /** the rule manager for internally comparing task tree nodes */ 28 private NodeEqualityRuleManager mRuleManager; 26 29 27 //----------------------------------------------------------------------------------------------- 28 /** 29 * TODO: comment 30 * 31 */ 32 SelectionComparisonRule(NodeEqualityRuleManager ruleManager) 33 { 34 super(); 35 mRuleManager = ruleManager; 36 } 30 /** 31 * <p> 32 * simple constructor to provide the rule with the node equality rule manager to be able 33 * to perform comparisons of the children of provided task tree nodes 34 * </p> 35 * 36 * @param ruleManager the rule manager for comparing task tree nodes 37 */ 38 SelectionComparisonRule(NodeEqualityRuleManager ruleManager) { 39 super(); 40 mRuleManager = ruleManager; 41 } 37 42 38 //----------------------------------------------------------------------------------------------- 39 /* (non-Javadoc) 40 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 41 */ 42 //----------------------------------------------------------------------------------------------- 43 @Override 44 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 45 { 46 if ((!(node1 instanceof Sequence)) || (!(node2 instanceof Sequence))) 47 { 48 return null; 43 /* 44 * (non-Javadoc) 45 * 46 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 47 */ 48 @Override 49 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 50 if ((!(node1 instanceof ISelection)) || (!(node2 instanceof ISelection))) { 51 return null; 52 } 53 54 // if both sequences do not have children, they are equal although this doesn't make sense 55 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 56 return NodeEquality.LEXICALLY_EQUAL; 57 } 58 59 // Selections are syntactically equal, if they have children, which are all syntactically 60 // equal. 61 // They are lexically equals, if they have the same number and order of lexically equal 62 // children 63 boolean lexicallyEqual = node1.getChildren().size() == node2.getChildren().size(); 64 65 for (int i = 0; i < node1.getChildren().size(); i++) { 66 ITaskTreeNode child1 = node1.getChildren().get(i); 67 boolean foundLexicallyEqualChild = false; 68 69 for (int j = 0; j < node2.getChildren().size(); j++) { 70 ITaskTreeNode child2 = node2.getChildren().get(j); 71 72 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 73 74 if (!nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 75 return null; 76 } 77 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 78 foundLexicallyEqualChild = true; 79 } 80 } 81 82 // if we compare two children at the same position and if they are lexically equal 83 // then it can be further expected, that the selections are lexically equal 84 lexicallyEqual &= foundLexicallyEqualChild; 85 } 86 87 if (lexicallyEqual) { 88 return NodeEquality.LEXICALLY_EQUAL; 89 } 90 else { 91 return NodeEquality.SYNTACTICALLY_EQUAL; 92 } 49 93 } 50 51 // if both sequences do not have children, they are equal although this doesn't make sense52 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0))53 {54 return new NodesEqual();55 }56 57 // Selections are semantically equal, if they have children, which are all semantically equal.58 // they are structurally equals, if they have the same number and order of structurally equal59 // children60 boolean structurallyEqual =61 node1.getChildren().size() == node2.getChildren().size();62 63 for (int i = 0; i < node1.getChildren().size(); i++)64 {65 TaskTreeNode child1 = node1.getChildren().get(i);66 67 for (int j = 0; j < node2.getChildren().size(); j++)68 {69 TaskTreeNode child2 = node2.getChildren().get(j);70 71 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);72 73 if (!nodeEquality.getSemanticalEquality())74 {75 return null;76 }77 else if (structurallyEqual && (i == j))78 {79 // if we compare two children at the same position and if they are structurally equal80 // then it can be further expected, that the selections are structurally equal81 structurallyEqual &= nodeEquality.getStructuralEquality();82 }83 }84 }85 86 if (structurallyEqual)87 {88 return new NodesEqual();89 }90 else91 {92 return new NodesSemanticallyEqual();93 }94 }95 96 94 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 * TODO comment 13 * <p> 14 * This rule is capable of comparing sequences. If both sequences do not have children, they are 15 * treated as lexically equal. Sequences are lexically equal, if they have the same number and 16 * order of lexically equal children. The rule can not decide, if two sequences are syntactically 17 * or semantically equal. 18 * </p> 16 19 * 17 20 * @version $Revision: $ $Date: 19.02.2012$ 18 21 * @author 2012, last modified by $Author: patrick$ 19 22 */ 20 //------------------------------------------------------------------------------------------------- 21 public class SequenceComparisonRule implements NodeComparisonRule 22 { 23 public class SequenceComparisonRule implements NodeComparisonRule { 23 24 25 /** the rule manager for internally comparing task tree nodes */ 26 private NodeEqualityRuleManager mRuleManager; 24 27 25 /** */ 26 private NodeEqualityRuleManager mRuleManager; 28 /** 29 * <p> 30 * simple constructor to provide the rule with the node equality rule manager to be able 31 * to perform comparisons of the children of provided task tree nodes 32 * </p> 33 * 34 * @param ruleManager the rule manager for comparing task tree nodes 35 */ 36 SequenceComparisonRule(NodeEqualityRuleManager ruleManager) { 37 super(); 38 mRuleManager = ruleManager; 39 } 27 40 28 //----------------------------------------------------------------------------------------------- 29 /** 30 * TODO: comment 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 SequenceComparisonRule(NodeEqualityRuleManager ruleManager) 35 { 36 super(); 37 mRuleManager = ruleManager; 38 } 41 /* 42 * (non-Javadoc) 43 * 44 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 45 */ 46 @Override 47 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 48 if ((!(node1 instanceof ISequence)) || (!(node2 instanceof ISequence))) { 49 return null; 50 } 39 51 40 //----------------------------------------------------------------------------------------------- 41 /* (non-Javadoc) 42 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 43 */ 44 //----------------------------------------------------------------------------------------------- 45 @Override 46 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 47 { 48 if ((!(node1 instanceof Sequence)) || (!(node2 instanceof Sequence))) 49 { 50 return null; 52 // if both sequences do not have children, they are equal although this doesn't make sense 53 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 54 return NodeEquality.LEXICALLY_EQUAL; 55 } 56 57 // 58 if (node1.getChildren().size() != node2.getChildren().size()) { 59 return null; 60 } 61 62 for (int i = 0; i < node1.getChildren().size(); i++) { 63 ITaskTreeNode child1 = node1.getChildren().get(i); 64 ITaskTreeNode child2 = node2.getChildren().get(i); 65 66 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 67 68 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 69 return null; 70 } 71 } 72 73 return NodeEquality.LEXICALLY_EQUAL; 51 74 } 52 53 // if both sequences do not have children, they are equal although this doesn't make sense54 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0))55 {56 return new NodesEqual();57 }58 59 // Sequences are equal, if they have the same number and order of children. If all the60 // children match structurally, then the sequences are structurally equal. Otherwise, if61 // at least one pair of children matches only semantically, then the sequences match only62 // semantically.63 if (node1.getChildren().size() != node2.getChildren().size())64 {65 return null;66 }67 68 boolean structurallyEqual = true;69 for (int i = 0; i < node1.getChildren().size(); i++)70 {71 TaskTreeNode child1 = node1.getChildren().get(i);72 TaskTreeNode child2 = node2.getChildren().get(i);73 74 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);75 76 structurallyEqual &= nodeEquality.getStructuralEquality();77 78 if (!structurallyEqual && !nodeEquality.getSemanticalEquality())79 {80 return null;81 }82 }83 84 if (structurallyEqual)85 {86 return new NodesEqual();87 }88 else89 {90 return new NodesSemanticallyEqual();91 }92 }93 75 94 76 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;12 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class DefaultGUIElementSequenceDetectionRule implements TemporalRelationshipRule 26 { 22 public class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 27 23 28 //----------------------------------------------------------------------------------------------- 29 /* (non-Javadoc) 30 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 31 */ 32 //----------------------------------------------------------------------------------------------- 33 @Override 34 public RuleApplicationResult apply(TaskTreeNode parent, 35 TaskTreeBuilder builder, 36 TaskTreeNodeFactory nodeFactory, 37 boolean finalize) 38 { 39 if (!(parent instanceof Sequence)) 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 28 * TaskTreeBuilder, TaskTreeNodeFactory) 29 */ 30 @Override 31 public RuleApplicationResult apply(ITaskTreeNode parent, 32 ITaskTreeBuilder builder, 33 ITaskTreeNodeFactory nodeFactory, 34 boolean finalize) 40 35 { 41 return null; 36 if (!(parent instanceof ISequence)) { 37 return null; 38 } 39 40 RuleApplicationResult result = new RuleApplicationResult(); 41 42 IEventTarget currentEventTarget = null; 43 int startingIndex = -1; 44 45 int index = 0; 46 while (index < parent.getChildren().size()) { 47 ITaskTreeNode child = parent.getChildren().get(index); 48 49 IEventTarget eventTarget = determineEventTarget(child); 50 51 if ((eventTarget != null) && (!eventTarget.equals(currentEventTarget))) { 52 if (startingIndex < 0) { 53 startingIndex = index; 54 currentEventTarget = eventTarget; 55 } 56 else { 57 handleEventTargetSequence(parent, startingIndex, index - 1, builder, 58 nodeFactory, result); 59 60 return result; 61 } 62 } 63 64 index++; 65 } 66 67 if (startingIndex > -1) { 68 if (finalize && (startingIndex > 0)) { 69 handleEventTargetSequence(parent, startingIndex, parent.getChildren().size() - 1, 70 builder, nodeFactory, result); 71 } 72 else { 73 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 74 } 75 } 76 77 return result; 42 78 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 GUIElement currentGUIElement = null; 47 int startingIndex = -1; 48 49 int index = 0; 50 while (index < parent.getChildren().size()) 79 80 /** 81 * TODO: comment 82 * 83 * @param child 84 * @return 85 */ 86 private IEventTarget determineEventTarget(ITaskTreeNode node) { 87 if (node instanceof IEventTask) { 88 return ((IEventTask) node).getEventTarget(); 89 } 90 else { 91 return null; 92 } 93 } 94 95 /** 96 * TODO: comment 97 * 98 */ 99 private void handleEventTargetSequence(ITaskTreeNode parent, 100 int startIndex, 101 int endIndex, 102 ITaskTreeBuilder builder, 103 ITaskTreeNodeFactory nodeFactory, 104 RuleApplicationResult result) 51 105 { 52 TaskTreeNode child = parent.getChildren().get(index); 53 54 GUIElement guiElement = determineGUIElement(child); 55 56 if ((guiElement != null) && (!guiElement.equals(currentGUIElement))) 57 { 58 if (startingIndex < 0) 59 { 60 startingIndex = index; 61 currentGUIElement = guiElement; 106 ISequence sequence = nodeFactory.createNewSequence(); 107 108 for (int i = startIndex; i <= endIndex; i++) { 109 builder.addChild(sequence, parent.getChildren().get(startIndex)); 110 builder.removeChild((ISequence) parent, startIndex); 62 111 } 63 else64 {65 handleGuiElementSequence(parent, startingIndex, index - 1, builder, nodeFactory, result);66 112 67 return result; 68 } 69 } 70 71 index++; 113 builder.addChild((ISequence) parent, startIndex, sequence); 114 115 result.addNewlyCreatedParentNode(sequence); 116 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 72 117 } 73 74 if (startingIndex > -1)75 {76 if (finalize && (startingIndex > 0))77 {78 handleGuiElementSequence79 (parent, startingIndex, parent.getChildren().size() - 1, builder, nodeFactory, result);80 }81 else82 {83 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);84 }85 }86 87 return result;88 }89 90 //-----------------------------------------------------------------------------------------------91 /**92 * TODO: comment93 *94 * @param child95 * @return96 */97 //-----------------------------------------------------------------------------------------------98 private GUIElement determineGUIElement(TaskTreeNode node)99 {100 if (node instanceof InteractionTask)101 {102 return ((InteractionTask) node).getGUIElement();103 }104 else105 {106 return null;107 }108 }109 110 //-----------------------------------------------------------------------------------------------111 /**112 * TODO: comment113 *114 */115 //-----------------------------------------------------------------------------------------------116 private void handleGuiElementSequence(TaskTreeNode parent,117 int startIndex,118 int endIndex,119 TaskTreeBuilder builder,120 TaskTreeNodeFactory nodeFactory,121 RuleApplicationResult result)122 {123 Sequence sequence = nodeFactory.createNewSequence();124 125 for (int i = startIndex; i <= endIndex; i++)126 {127 builder.addChild(sequence, parent.getChildren().get(startIndex));128 builder.removeChild((Sequence) parent, startIndex);129 }130 131 builder.addChild((Sequence) parent, startIndex, sequence);132 133 result.addNewlyCreatedParentNode(sequence);134 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);135 }136 118 137 119 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 10 import de.ugoe.cs.quest.eventcore.gui.IInteraction; 11 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 15 16 16 //-------------------------------------------------------------------------------------------------17 17 /** 18 18 * TODO comment … … 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 //------------------------------------------------------------------------------------------------- 24 public class DefaultSequenceDetectionRule implements TemporalRelationshipRule 25 { 23 public class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 26 24 27 //----------------------------------------------------------------------------------------------- 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 //----------------------------------------------------------------------------------------------- 32 @Override 33 public RuleApplicationResult apply(TaskTreeNode parent, 34 TaskTreeBuilder builder, 35 TaskTreeNodeFactory nodeFactory, 36 boolean finalize) 37 { 38 if (!(parent instanceof Sequence)) 25 /* 26 * (non-Javadoc) 27 * 28 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 29 * TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 @Override 32 public RuleApplicationResult apply(ITaskTreeNode parent, 33 ITaskTreeBuilder builder, 34 ITaskTreeNodeFactory nodeFactory, 35 boolean finalize) 39 36 { 40 return null; 37 if (!(parent instanceof ISequence)) { 38 return null; 39 } 40 41 RuleApplicationResult result = new RuleApplicationResult(); 42 int sequenceStartingIndex = -1; 43 44 int index = 0; 45 while (index < parent.getChildren().size()) { 46 ITaskTreeNode child = parent.getChildren().get(index); 47 48 if ((child instanceof IEventTask) && 49 (((IEventTask) child).getEventType() instanceof IInteraction)) 50 { 51 IInteraction eventType = (IInteraction) ((IEventTask) child).getEventType(); 52 53 if (eventType.finishesLogicalSequence() && (sequenceStartingIndex > -1)) 54 { 55 // There are several situations in which this implementation may cause infinite 56 // loops. This is because the rule manager will reapply rules until 57 // no rule is applied anymore. A sequence identified in a first iteration will 58 // be identified as a sequence also in a second iteration. As an example 59 // many sequences start with an interaction starting that sequence and end 60 // with an interaction ending that sequence. This will be reidentified as 61 // further subsequence. It must therefore be assured, that a sequence, that 62 // was once identified is not reidentified in a further application of the rule. 63 // For this, the implementation performs a kind of dry run. It creates a list of 64 // children that would belong to an identified sequence. Only if this list is 65 // not a reidentification then a new sequence is created and added to the 66 // parent. If it is a reidentification can be identified, if the list of 67 // children will contain all children of the parent, or if the list of children 68 // only consists of one sequence. Further, an identified sequence must at least 69 // have one child. 70 if (((sequenceStartingIndex != 0) || 71 (index != (parent.getChildren().size() - 1))) && 72 (((index - sequenceStartingIndex) > 0) || 73 (((index - sequenceStartingIndex) == 0) && 74 (!eventType.startsLogicalSequence())))) 75 { 76 boolean allNewChildrenAreSequences = true; 77 78 for (int j = sequenceStartingIndex; 79 ((allNewChildrenAreSequences) && (j < index)); j++) 80 { 81 allNewChildrenAreSequences &= 82 (parent.getChildren().get(j) instanceof ISequence); 83 } 84 85 if (!allNewChildrenAreSequences) { 86 ISequence sequence = nodeFactory.createNewSequence(); 87 88 for (int j = sequenceStartingIndex; j < index; j++) { 89 builder.addChild 90 (sequence, parent.getChildren().get(sequenceStartingIndex)); 91 builder.removeChild((ISequence) parent, sequenceStartingIndex); 92 } 93 94 if (!eventType.startsLogicalSequence()) { 95 builder.addChild 96 (sequence, parent.getChildren().get(sequenceStartingIndex)); 97 builder.removeChild((ISequence) parent, sequenceStartingIndex); 98 } 99 100 builder.addChild((ISequence) parent, sequenceStartingIndex, sequence); 101 102 result.addNewlyCreatedParentNode(sequence); 103 result.setRuleApplicationStatus 104 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 105 return result; 106 } 107 } 108 } 109 110 if (eventType.startsLogicalSequence()) { 111 sequenceStartingIndex = index; 112 } 113 } 114 115 index++; 116 } 117 118 if (sequenceStartingIndex >= 0) { 119 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 120 } 121 122 return result; 41 123 } 42 43 RuleApplicationResult result = new RuleApplicationResult();44 int sequenceStartingIndex = -1;45 46 int index = 0;47 while (index < parent.getChildren().size())48 {49 TaskTreeNode child = parent.getChildren().get(index);50 51 if (child instanceof InteractionTask)52 {53 if (((InteractionTask) child).getInteraction().finishesLogicalSequence() &&54 (sequenceStartingIndex > -1))55 {56 // There are several situations in which this implementation may cause infinite57 // loops. This is because the rule manager will reapply rules until58 // no rule is applied anymore. A sequence identified in a first iteration will59 // be identified as a sequence also in a second iteration. As an example60 // many sequences start with an interaction starting that sequence and end61 // with an interaction ending that sequence. This will be reidentified as further62 // subsequence. It must therefore be assured, that a sequence, that was once63 // identified is not reidentified in a further application of the rule. For this,64 // the implementation performs a kind of dry run. It creates a list of children65 // that would belong to an identified sequence. Only if this list is not a66 // reidentification then a new sequence is created and added to the parent. If it67 // is a reidentification can be identified, if the list of children will contain68 // all children of the parent, or if the list of children only consists of one69 // sequence. Further, an identified sequence must at least have one child.70 if (((sequenceStartingIndex != 0) || (index != (parent.getChildren().size() - 1))) &&71 (((index - sequenceStartingIndex) > 0) ||72 (((index - sequenceStartingIndex) == 0) &&73 (!((InteractionTask) child).getInteraction().startsLogicalSequence()))))74 {75 boolean allNewChildrenAreSequences = true;76 77 for (int j = sequenceStartingIndex; ((allNewChildrenAreSequences) && (j < index)); j++)78 {79 allNewChildrenAreSequences &= (parent.getChildren().get(j) instanceof Sequence);80 }81 82 if (!allNewChildrenAreSequences)83 {84 Sequence sequence = nodeFactory.createNewSequence();85 86 for (int j = sequenceStartingIndex; j < index; j++)87 {88 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));89 builder.removeChild((Sequence) parent, sequenceStartingIndex);90 }91 92 if (!((InteractionTask) child).getInteraction().startsLogicalSequence())93 {94 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));95 builder.removeChild((Sequence) parent, sequenceStartingIndex);96 }97 98 builder.addChild((Sequence) parent, sequenceStartingIndex, sequence);99 100 result.addNewlyCreatedParentNode(sequence);101 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);102 return result;103 }104 }105 }106 107 if (((InteractionTask) child).getInteraction().startsLogicalSequence())108 {109 sequenceStartingIndex = index;110 }111 }112 113 index++;114 }115 116 if (sequenceStartingIndex >= 0)117 {118 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);119 }120 121 return result;122 }123 124 124 125 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 16 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 17 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 18 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 19 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 20 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 21 22 //------------------------------------------------------------------------------------------------- 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class DefaultIterationDetectionRule implements TemporalRelationshipRule 31 { 32 /** */ 33 private NodeEqualityRuleManager mNodeEqualityRuleManager; 34 35 //----------------------------------------------------------------------------------------------- 36 /** 37 * TODO: comment 27 public class DefaultIterationDetectionRule implements TemporalRelationshipRule { 28 29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 31 32 /** 33 * TODO: comment 34 * 35 */ 36 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder treeBuilder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 // parent must already have at least 2 children 57 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) { 58 return null; 59 } 60 61 // iterations represent as a list of nodes that splits up in several equal sublists. If 62 // the remaining nodes also start an equal sublist, then the iteration may not be completed 63 // yet. So wait for further events to only identify completed iterations. 64 65 // to find longer iterations first, start with long sequences 66 for (int end = parent.getChildren().size() - 1; end > 0; end--) { 67 for (int start = 0; start < end; start++) { 68 List<ITaskTreeNode[]> equalVariants = 69 getEqualSublistVariantsInBoundaries(parent, start, end); 70 71 if (equalVariants != null) { 72 if (!finalize) { 73 // check, if the iteration may go on. This may be the case, if the detected 74 // iteration finishes with the last child of the parent, or if the 75 // remaining children, which were not identified as part of the iteration, 76 // start a further occurrence of the iteration 77 if (end == (parent.getChildren().size() - 1)) { 78 RuleApplicationResult result = new RuleApplicationResult(); 79 result.setRuleApplicationStatus 80 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 81 return result; 82 } 83 84 boolean allNodesEqual = true; 85 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 86 { 87 if ((end + i + 1) >= parent.getChildren().size()) { 88 break; 89 } 90 91 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 92 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 93 94 allNodesEqual &= 95 nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 96 } 97 98 if (allNodesEqual) { 99 RuleApplicationResult result = new RuleApplicationResult(); 100 result.setRuleApplicationStatus 101 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 102 return result; 103 } 104 } 105 106 RuleApplicationResult result = new RuleApplicationResult(); 107 IIteration newIteration = nodeFactory.createNewIteration(); 108 result.addNewlyCreatedParentNode(newIteration); 109 110 if (equalVariants.size() == 1) { 111 // all children are the same. Create an iteration of this child 112 if (equalVariants.get(0).length == 1) { 113 // all children are the same. Create an iteration of this child 114 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 115 } 116 else { 117 // there was an iteration of structurally equal sequences 118 ISequence sequence = nodeFactory.createNewSequence(); 119 result.addNewlyCreatedParentNode(sequence); 120 121 for (ITaskTreeNode node : equalVariants.get(0)) { 122 treeBuilder.addChild(sequence, node); 123 } 124 125 treeBuilder.setChild(newIteration, sequence); 126 } 127 } 128 else { 129 // there are distinct variants of semantically equal subsequences or 130 // children --> 131 // create an iterated selection 132 ISelection selection = nodeFactory.createNewSelection(); 133 result.addNewlyCreatedParentNode(selection); 134 135 for (ITaskTreeNode[] variant : equalVariants) { 136 if (variant.length == 1) { 137 treeBuilder.addChild(selection, variant[0]); 138 } 139 else { 140 ISequence sequence = nodeFactory.createNewSequence(); 141 result.addNewlyCreatedParentNode(sequence); 142 143 for (ITaskTreeNode node : variant) { 144 treeBuilder.addChild(sequence, node); 145 } 146 147 treeBuilder.addChild(selection, sequence); 148 } 149 } 150 151 treeBuilder.setChild(newIteration, selection); 152 } 153 154 // remove iterated children 155 for (int j = end; j >= start; j--) { 156 treeBuilder.removeChild((ISequence) parent, j); 157 } 158 159 // add the new iteration instead 160 treeBuilder.addChild((ISequence) parent, start, newIteration); 161 162 result.setRuleApplicationStatus 163 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 164 return result; 165 } 166 } 167 } 168 169 return null; 170 } 171 172 /** 173 * TODO: comment 174 * 175 * @return 176 */ 177 private List<ITaskTreeNode[]> getEqualSublistVariantsInBoundaries(ITaskTreeNode parent, 178 int start, 179 int end) 180 { 181 List<ITaskTreeNode[]> equalVariants = null; 182 183 int noOfChildrenInBoundaries = end - start + 1; 184 185 for (int subListLen = 1; subListLen <= (noOfChildrenInBoundaries / 2); subListLen++) 186 { 187 if ((noOfChildrenInBoundaries % subListLen) == 0) { 188 equalVariants = 189 getEqualSublistVariantsForSubListLength(parent, start, end, subListLen); 190 191 if (equalVariants != null) { 192 return equalVariants; 193 } 194 } 195 } 196 197 return null; 198 } 199 200 /** 38 201 * 39 202 */ 40 //----------------------------------------------------------------------------------------------- 41 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 42 { 43 super(); 44 mNodeEqualityRuleManager = nodeEqualityRuleManager; 45 } 46 47 //----------------------------------------------------------------------------------------------- 48 /* (non-Javadoc) 49 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 50 */ 51 //----------------------------------------------------------------------------------------------- 52 @Override 53 public RuleApplicationResult apply(TaskTreeNode parent, 54 TaskTreeBuilder treeBuilder, 55 TaskTreeNodeFactory nodeFactory, 56 boolean finalize) 57 { 58 if (!(parent instanceof Sequence)) 203 private List<ITaskTreeNode[]> getEqualSublistVariantsForSubListLength(ITaskTreeNode parent, 204 int start, 205 int end, 206 int subListLen) 59 207 { 60 return null; 61 } 62 63 // parent must already have at least 2 children 64 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) 65 { 66 return null; 67 } 68 69 // iterations represent as a list of nodes that splits up in several equal sublists. If 70 // the remaining nodes also start an equal sublist, then the iteration may not be completed 71 // yet. So wait for further interactions to only identify completed iterations. 72 73 // to find longer iterations first, start with long sequences 74 for (int end = parent.getChildren().size() - 1; end > 0; end--) 75 { 76 for (int start = 0; start < end; start++) 77 { 78 List<TaskTreeNode[]> equalVariants = 79 getEqualSublistVariantsInBoundaries(parent, start, end); 80 81 if (equalVariants != null) 208 List<ITaskTreeNode[]> equalVariants = new ArrayList<ITaskTreeNode[]>(); 209 ITaskTreeNode[] firstVariant = new ITaskTreeNode[subListLen]; 210 211 for (int i = 0; i < subListLen; i++) { 212 firstVariant[i] = parent.getChildren().get(start + i); 213 } 214 215 equalVariants.add(firstVariant); 216 217 for (int parentIdx = (start + subListLen); parentIdx <= end; parentIdx += subListLen) 82 218 { 83 if (!finalize) 84 { 85 // check, if the iteration may go on. This may be the case, if the detected iteration 86 // finishes with the last child of the parent, or if the remaining children, which were 87 // not identified as part of the iteration, start a further occurrence of the iteration 88 if (end == (parent.getChildren().size() - 1)) 89 { 90 RuleApplicationResult result = new RuleApplicationResult(); 91 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 92 return result; 93 } 94 95 boolean allNodesEqual = true; 96 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 97 { 98 if ((end + i + 1) >= parent.getChildren().size()) 99 { 100 break; 101 } 102 103 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 104 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 105 106 allNodesEqual &= 107 nodeEquality.getStructuralEquality() || nodeEquality.getSemanticalEquality(); 108 } 109 110 if (allNodesEqual) 111 { 112 RuleApplicationResult result = new RuleApplicationResult(); 113 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 114 return result; 115 } 116 } 117 118 RuleApplicationResult result = new RuleApplicationResult(); 119 Iteration newIteration = nodeFactory.createNewIteration(); 120 result.addNewlyCreatedParentNode(newIteration); 121 122 if (equalVariants.size() == 1) 123 { 124 // all children are the same. Create an iteration of this child 125 if (equalVariants.get(0).length == 1) 126 { 127 // all children are the same. Create an iteration of this child 128 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 129 } 130 else 131 { 132 // there was an iteration of structurally equal sequences 133 Sequence sequence = nodeFactory.createNewSequence(); 134 result.addNewlyCreatedParentNode(sequence); 135 136 for (TaskTreeNode node : equalVariants.get(0)) 137 { 138 treeBuilder.addChild(sequence, node); 139 } 140 141 treeBuilder.setChild(newIteration, sequence); 142 } 143 } 144 else 145 { 146 // there are distinct variants of semantically equal subsequences or children --> 147 // create an iterated selection 148 Selection selection = nodeFactory.createNewSelection(); 149 result.addNewlyCreatedParentNode(selection); 150 151 for (TaskTreeNode[] variant : equalVariants) 152 { 153 if (variant.length == 1) 154 { 155 treeBuilder.addChild(selection, variant[0]); 156 } 157 else 158 { 159 Sequence sequence = nodeFactory.createNewSequence(); 160 result.addNewlyCreatedParentNode(sequence); 161 162 for (TaskTreeNode node : variant) 163 { 164 treeBuilder.addChild(sequence, node); 165 } 166 167 treeBuilder.addChild(selection, sequence); 168 } 169 } 170 171 treeBuilder.setChild(newIteration, selection); 172 } 173 174 // remove iterated children 175 for (int j = end; j >= start; j--) 176 { 177 treeBuilder.removeChild((Sequence) parent, j); 178 } 179 180 // add the new iteration instead 181 treeBuilder.addChild((Sequence) parent, start, newIteration); 182 183 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 184 return result; 185 } 186 } 187 } 188 189 return null; 190 } 191 192 //----------------------------------------------------------------------------------------------- 193 /** 194 * TODO: comment 195 * 196 * @return 197 */ 198 //----------------------------------------------------------------------------------------------- 199 private List<TaskTreeNode[]> getEqualSublistVariantsInBoundaries(TaskTreeNode parent, 200 int start, 201 int end) 202 { 203 List<TaskTreeNode[]> equalVariants = null; 204 205 int noOfChildrenInBoundaries = end - start + 1; 206 207 for (int subListLength = 1; subListLength <= (noOfChildrenInBoundaries / 2); subListLength++) 208 { 209 if ((noOfChildrenInBoundaries % subListLength) == 0) 210 { 211 equalVariants = getEqualSublistVariantsForSubListLength(parent, start, end, subListLength); 212 213 if (equalVariants != null) 214 { 215 return equalVariants; 216 } 217 } 218 } 219 220 return null; 221 } 222 223 //----------------------------------------------------------------------------------------------- 224 /** 225 * 226 */ 227 //----------------------------------------------------------------------------------------------- 228 private List<TaskTreeNode[]> getEqualSublistVariantsForSubListLength(TaskTreeNode parent, 229 int start, 230 int end, 231 int subListLength) 232 { 233 List<TaskTreeNode[]> equalVariants = new ArrayList<TaskTreeNode[]>(); 234 TaskTreeNode[] firstVariant = new TaskTreeNode[subListLength]; 235 236 for (int i = 0; i < subListLength; i++) 237 { 238 firstVariant[i] = parent.getChildren().get(start + i); 239 } 240 241 equalVariants.add(firstVariant); 242 243 for (int parentIdx = (start + subListLength); parentIdx <= end; parentIdx += subListLength) 244 { 245 TaskTreeNode[] otherVariant = new TaskTreeNode[subListLength]; 246 247 for (int i = 0; i < subListLength; i++) 248 { 249 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 250 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 251 252 if (!nodeEquality.getStructuralEquality()) 253 { 254 if (nodeEquality.getSemanticalEquality()) 255 { 256 otherVariant[i] = parent.getChildren().get(parentIdx + i); 257 } 258 else 259 { 260 return null; 261 } 262 } 263 } 264 265 // check, if there is a semantically equal other variant. If so, add it to the list of 266 // variants 267 boolean semanticallyUnequal = false; 268 for (int i = 0; i < subListLength; i++) 269 { 270 if (otherVariant[i] == null) 271 { 272 otherVariant[i] = firstVariant[i]; 273 } 274 else 275 { 276 semanticallyUnequal = true; 277 } 278 } 279 280 if (semanticallyUnequal) 281 { 282 equalVariants.add(otherVariant); 283 } 284 } 285 286 return equalVariants; 287 } 219 ITaskTreeNode[] otherVariant = new ITaskTreeNode[subListLen]; 220 221 for (int i = 0; i < subListLen; i++) { 222 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 223 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 224 225 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 226 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 227 otherVariant[i] = parent.getChildren().get(parentIdx + i); 228 } 229 else { 230 return null; 231 } 232 } 233 } 234 235 // check, if there is a semantically equal other variant. If so, add it to the list of 236 // variants 237 boolean semanticallyUnequal = false; 238 for (int i = 0; i < subListLen; i++) { 239 if (otherVariant[i] == null) { 240 otherVariant[i] = firstVariant[i]; 241 } 242 else { 243 semanticallyUnequal = true; 244 } 245 } 246 247 if (semanticallyUnequal) { 248 equalVariants.add(otherVariant); 249 } 250 } 251 252 return equalVariants; 253 } 288 254 289 255 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultMouseClickReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonDown;12 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonInteraction;13 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonUp;14 import de.ugoe.cs.quest.eventcore. userinteraction.MouseClick;15 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;16 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 11 import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 12 import de.ugoe.cs.quest.eventcore.gui.MouseButtonUp; 13 import de.ugoe.cs.quest.eventcore.gui.MouseClick; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 19 21 //-------------------------------------------------------------------------------------------------22 20 /** 23 21 * TODO comment … … 26 24 * @author 2012, last modified by $Author: patrick$ 27 25 */ 28 //------------------------------------------------------------------------------------------------- 29 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule 30 { 26 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule { 31 27 32 //----------------------------------------------------------------------------------------------- 33 /* (non-Javadoc) 34 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Override 38 public RuleApplicationResult apply(TaskTreeNode parent, 39 TaskTreeBuilder builder, 40 TaskTreeNodeFactory nodeFactory, 41 boolean finalize) 42 { 43 if (!(parent instanceof Sequence)) 28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 32 * TaskTreeBuilder, TaskTreeNodeFactory) 33 */ 34 @Override 35 public RuleApplicationResult apply(ITaskTreeNode parent, 36 ITaskTreeBuilder builder, 37 ITaskTreeNodeFactory nodeFactory, 38 boolean finalize) 44 39 { 45 return null; 40 if (!(parent instanceof ISequence)) { 41 return null; 42 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 int index = 0; 47 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end 48 { 49 if (mouseClickSequenceFound(parent.getChildren().get(index), 50 parent.getChildren().get(index + 1), 51 parent.getChildren().get(index + 2))) 52 { 53 builder.removeChild((ISequence) parent, index); 54 builder.removeChild((ISequence) parent, index); 55 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 56 return result; 57 } 58 else if 59 ((parent.getChildren().get(index) instanceof ISequence) && 60 (parent.getChildren().get(index).getChildren().size() == 2) && 61 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0), 62 parent.getChildren().get(index).getChildren().get(1), 63 parent.getChildren().get(index + 1)))) 64 { 65 builder.removeChild((ISequence) parent, index); 66 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 67 return result; 68 } 69 70 index++; 71 } 72 73 return result; 46 74 } 47 48 RuleApplicationResult result = new RuleApplicationResult();49 50 int index = 0;51 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end52 {53 if (mouseClickSequenceFound(parent.getChildren().get(index),54 parent.getChildren().get(index + 1),55 parent.getChildren().get(index + 2)))56 {57 builder.removeChild((Sequence) parent, index);58 builder.removeChild((Sequence) parent, index);59 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);60 return result;61 }62 else if ((parent.getChildren().get(index) instanceof Sequence) &&63 (parent.getChildren().get(index).getChildren().size() == 2) &&64 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0),65 parent.getChildren().get(index).getChildren().get(1),66 parent.getChildren().get(index + 1))))67 {68 builder.removeChild((Sequence) parent, index);69 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);70 return result;71 }72 73 index++;74 }75 76 return result;77 }78 75 79 //----------------------------------------------------------------------------------------------- 80 /** 76 /** 81 77 * 82 78 */ 83 //----------------------------------------------------------------------------------------------- 84 private boolean mouseClickSequenceFound(TaskTreeNode mouseButtonDown, 85 TaskTreeNode mouseButtonUp, 86 TaskTreeNode mouseClick) 87 { 88 // check the first in a row of three for validity 89 if (!(mouseButtonDown instanceof InteractionTask)) 79 private boolean mouseClickSequenceFound(ITaskTreeNode mouseButtonDown, 80 ITaskTreeNode mouseButtonUp, 81 ITaskTreeNode mouseClick) 90 82 { 91 return false; 83 // check the first in a row of three for validity 84 if (!(mouseButtonDown instanceof IEventTask)) { 85 return false; 86 } 87 88 IEventTarget eventTarget = ((IEventTask) mouseButtonDown).getEventTarget(); 89 90 if (!(((IEventTask) mouseButtonDown).getEventType() instanceof MouseButtonDown)) { 91 return false; 92 } 93 94 MouseButtonInteraction.Button button = 95 ((MouseButtonDown) ((IEventTask) mouseButtonDown).getEventType()).getButton(); 96 97 // check the second node for validity 98 if (!(mouseButtonUp instanceof IEventTask)) { 99 return false; 100 } 101 102 if (!eventTarget.equals(((IEventTask) mouseButtonUp).getEventTarget())) { 103 return false; 104 } 105 106 if (!(((IEventTask) mouseButtonUp).getEventType() instanceof MouseButtonUp)) { 107 return false; 108 } 109 110 if (!button.equals(((MouseButtonUp) ((IEventTask) mouseButtonUp).getEventType()) 111 .getButton())) 112 { 113 return false; 114 } 115 116 // check the third node for validity 117 if (!(mouseClick instanceof IEventTask)) { 118 return false; 119 } 120 121 if (!eventTarget.equals(((IEventTask) mouseClick).getEventTarget())) { 122 return false; 123 } 124 125 if (!(((IEventTask) mouseClick).getEventType() instanceof MouseClick)) { 126 return false; 127 } 128 129 if (!button.equals(((MouseClick) ((IEventTask) mouseClick).getEventType()).getButton())) { 130 return false; 131 } 132 133 return true; 92 134 } 93 94 GUIElement guiElement = ((InteractionTask) mouseButtonDown).getGUIElement();95 96 if (!(((InteractionTask) mouseButtonDown).getInteraction() instanceof MouseButtonDown))97 {98 return false;99 }100 101 MouseButtonInteraction.Button button =102 ((MouseButtonDown) ((InteractionTask) mouseButtonDown).getInteraction()).getButton();103 104 105 // check the second node for validity106 if (!(mouseButtonUp instanceof InteractionTask))107 {108 return false;109 }110 111 if (!guiElement.equals(((InteractionTask) mouseButtonUp).getGUIElement()))112 {113 return false;114 }115 116 if (!(((InteractionTask) mouseButtonUp).getInteraction() instanceof MouseButtonUp))117 {118 return false;119 }120 121 if (!button.equals122 (((MouseButtonUp) ((InteractionTask) mouseButtonUp).getInteraction()).getButton()))123 {124 return false;125 }126 127 128 // check the third node for validity129 if (!(mouseClick instanceof InteractionTask))130 {131 return false;132 }133 134 if (!guiElement.equals(((InteractionTask) mouseClick).getGUIElement()))135 {136 return false;137 }138 139 if (!(((InteractionTask) mouseClick).getInteraction() instanceof MouseClick))140 {141 return false;142 }143 144 if (!button.equals(((MouseClick) ((InteractionTask) mouseClick).getInteraction()).getButton()))145 {146 return false;147 }148 149 return true;150 }151 135 152 136 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 12 11 import java.util.Locale; 13 12 14 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;15 import de.ugoe.cs.quest.eventcore.gui model.TextArea;16 import de.ugoe.cs.quest.eventcore.gui model.TextField;17 import de.ugoe.cs.quest.eventcore. userinteraction.KeyInteraction;18 import de.ugoe.cs.quest.eventcore. userinteraction.KeyPressed;19 import de.ugoe.cs.quest.eventcore. userinteraction.KeyReleased;20 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;21 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;22 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;23 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;24 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;25 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;13 import de.ugoe.cs.quest.eventcore.IEventTarget; 14 import de.ugoe.cs.quest.eventcore.gui.KeyInteraction; 15 import de.ugoe.cs.quest.eventcore.gui.KeyPressed; 16 import de.ugoe.cs.quest.eventcore.gui.KeyReleased; 17 import de.ugoe.cs.quest.eventcore.guimodel.ITextArea; 18 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 19 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 20 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 21 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 22 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 26 25 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMap; 27 26 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMapFactory; 28 27 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 29 28 30 //-------------------------------------------------------------------------------------------------31 29 /** 32 30 * TODO comment … … 35 33 * @author 2012, last modified by $Author: patrick$ 36 34 */ 37 //------------------------------------------------------------------------------------------------- 38 public class DefaultTextInputReductionRule implements TemporalRelationshipRule 39 { 40 /** */ 41 private KeyboardMap mKeyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 42 43 //----------------------------------------------------------------------------------------------- 44 /* (non-Javadoc) 45 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 46 */ 47 //----------------------------------------------------------------------------------------------- 48 @Override 49 public RuleApplicationResult apply(TaskTreeNode parent, 50 TaskTreeBuilder builder, 51 TaskTreeNodeFactory nodeFactory, 52 boolean finalize) 53 { 54 if ((!(parent instanceof Sequence)) || 55 (parent instanceof TextInputInteractionTask)) 35 public class DefaultTextInputReductionRule implements TemporalRelationshipRule { 36 37 /** */ 38 private KeyboardMap keyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 39 40 /* 41 * (non-Javadoc) 42 * 43 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 44 */ 45 @Override 46 public RuleApplicationResult apply(ITaskTreeNode parent, 47 ITaskTreeBuilder builder, 48 ITaskTreeNodeFactory nodeFactory, 49 boolean finalize) 56 50 { 57 return null; 58 } 59 60 RuleApplicationResult result = new RuleApplicationResult(); 61 int textEntryStartIndex = -1; 62 GUIElement currentGUIElement = null; 63 64 int index = 0; 65 TaskTreeNode task = null; 66 while (index < parent.getChildren().size()) 51 if ((!(parent instanceof ISequence)) || (parent instanceof ITextInputEventTask)) { 52 return null; 53 } 54 55 RuleApplicationResult result = new RuleApplicationResult(); 56 int textEntryStartIndex = -1; 57 IEventTarget currentEventTarget = null; 58 59 int index = 0; 60 ITaskTreeNode task = null; 61 while (index < parent.getChildren().size()) { 62 task = parent.getChildren().get(index); 63 if (isKeyInteraction(task) && 64 isDataInputEventTarget(((IEventTask) task).getEventTarget())) 65 { 66 if (textEntryStartIndex < 0) { 67 textEntryStartIndex = index; 68 currentEventTarget = ((IEventTask) task).getEventTarget(); 69 } 70 else if (!currentEventTarget.equals(((IEventTask) task).getEventTarget())) { 71 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, 72 currentEventTarget, builder, nodeFactory, result); 73 return result; 74 } 75 } 76 else if (textEntryStartIndex >= 0) { 77 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentEventTarget, 78 builder, nodeFactory, result); 79 return result; 80 } 81 82 index++; 83 } 84 85 if (textEntryStartIndex >= 0) { 86 if (finalize) { 87 handleTextEntrySequence(parent, textEntryStartIndex, 88 parent.getChildren().size() - 1, currentEventTarget, 89 builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param taskTreeNode 103 * @return 104 */ 105 private boolean isKeyInteraction(ITaskTreeNode taskTreeNode) { 106 if ((taskTreeNode instanceof IEventTask)) { 107 return (((IEventTask) taskTreeNode).getEventType() instanceof KeyInteraction); 108 } 109 else { 110 return false; 111 } 112 } 113 114 /** 115 * TODO: comment 116 * 117 * @param textEntryStartIndex 118 * @param i 119 * @param result 120 * @return 121 */ 122 private void handleTextEntrySequence(ITaskTreeNode parent, 123 int startIndex, 124 int endIndex, 125 IEventTarget eventTarget, 126 ITaskTreeBuilder builder, 127 ITaskTreeNodeFactory nodeFactory, 128 RuleApplicationResult result) 67 129 { 68 task = parent.getChildren().get(index); 69 if (isKeyInteraction(task) && isDataInputGUIElement(((InteractionTask) task).getGUIElement())) 70 { 71 if (textEntryStartIndex < 0) 72 { 73 textEntryStartIndex = index; 74 currentGUIElement = ((InteractionTask) task).getGUIElement(); 75 } 76 else if (!currentGUIElement.equals(((InteractionTask) task).getGUIElement())) 77 { 78 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 79 builder, nodeFactory, result); 80 return result; 81 } 82 } 83 else if (textEntryStartIndex >= 0) 84 { 85 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 86 builder, nodeFactory, result); 87 return result; 88 } 89 90 index++; 91 } 92 93 if (textEntryStartIndex >= 0) 130 ITextInputEventTask textInput = nodeFactory.createNewTextInputEventTask(eventTarget); 131 132 for (int i = startIndex; i <= endIndex; i++) { 133 builder.addChild(textInput, parent.getChildren().get(startIndex)); 134 builder.removeChild((ISequence) parent, startIndex); 135 } 136 137 builder.addChild((ISequence) parent, startIndex, textInput); 138 139 StringBuffer enteredText = new StringBuffer(); 140 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 141 textInput.setEnteredText(enteredText.toString()); 142 143 result.addNewlyCreatedParentNode(textInput); 144 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 145 } 146 147 /** 148 * TODO: comment 149 * 150 * @param eventTarget 151 * @return 152 */ 153 private boolean isDataInputEventTarget(IEventTarget eventTarget) { 154 return ((eventTarget instanceof ITextField) || (eventTarget instanceof ITextArea)); 155 } 156 157 /** 158 * TODO: comment 159 * 160 * @param sequence 161 * @param enteredText 162 */ 163 private void determineEnteredText(ITaskTreeNode node, 164 List<VirtualKey> pressedKeys, 165 StringBuffer enteredText) 94 166 { 95 if (finalize) 96 { 97 handleTextEntrySequence(parent, textEntryStartIndex, parent.getChildren().size() - 1, 98 currentGUIElement, builder, nodeFactory, result); 99 } 100 else 101 { 102 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 103 } 104 } 105 106 return result; 107 } 108 109 //----------------------------------------------------------------------------------------------- 110 /** 111 * TODO: comment 112 * 113 * @param taskTreeNode 114 * @return 115 */ 116 //----------------------------------------------------------------------------------------------- 117 private boolean isKeyInteraction(TaskTreeNode taskTreeNode) 118 { 119 if ((taskTreeNode instanceof InteractionTask)) 120 { 121 return (((InteractionTask) taskTreeNode).getInteraction() instanceof KeyInteraction); 122 } 123 else 124 { 125 return false; 126 } 127 } 128 129 //----------------------------------------------------------------------------------------------- 130 /** 131 * TODO: comment 132 * 133 * @param textEntryStartIndex 134 * @param i 135 * @param result 136 * @return 137 */ 138 //----------------------------------------------------------------------------------------------- 139 private void handleTextEntrySequence(TaskTreeNode parent, 140 int startIndex, 141 int endIndex, 142 GUIElement guiElement, 143 TaskTreeBuilder builder, 144 TaskTreeNodeFactory nodeFactory, 145 RuleApplicationResult result) 146 { 147 TextInputInteractionTask textInput = nodeFactory.createNewTextInputInteractionTask(guiElement); 148 149 for (int i = startIndex; i <= endIndex; i++) 150 { 151 builder.addChild(textInput, parent.getChildren().get(startIndex)); 152 builder.removeChild((Sequence) parent, startIndex); 153 } 154 155 builder.addChild((Sequence) parent, startIndex, textInput); 156 157 StringBuffer enteredText = new StringBuffer(); 158 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 159 textInput.setEnteredText(enteredText.toString()); 160 161 result.addNewlyCreatedParentNode(textInput); 162 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 163 } 164 165 //----------------------------------------------------------------------------------------------- 166 /** 167 * TODO: comment 168 * 169 * @param guiElement 170 * @return 171 */ 172 //----------------------------------------------------------------------------------------------- 173 private boolean isDataInputGUIElement(GUIElement guiElement) 174 { 175 return ((guiElement instanceof TextField) || (guiElement instanceof TextArea)); 176 } 177 178 //----------------------------------------------------------------------------------------------- 179 /** 180 * TODO: comment 181 * 182 * @param sequence 183 * @param enteredText 184 */ 185 //----------------------------------------------------------------------------------------------- 186 private void determineEnteredText(TaskTreeNode node, 187 List<VirtualKey> pressedKeys, 188 StringBuffer enteredText) 189 { 190 if ((node instanceof Sequence) || (node instanceof TextInputInteractionTask)) 191 { 192 for (TaskTreeNode child : node.getChildren()) 193 { 194 if (child instanceof InteractionTask) 195 { 196 if (((InteractionTask) child).getInteraction() instanceof KeyPressed) 197 { 198 VirtualKey key = ((KeyPressed) ((InteractionTask) child).getInteraction()).getKey(); 199 200 pressedKeys.add(key); 201 202 if (key == VirtualKey.BACK_SPACE) 203 { 204 if (enteredText.length() > 0) 205 { 206 enteredText.deleteCharAt(enteredText.length() - 1); 207 } 208 } 209 else if (key == VirtualKey.ENTER) 210 { 211 // text fields only contain one line of code. Therefore the return is ignored. 212 if (!(((InteractionTask) child).getGUIElement() instanceof TextField)) 213 { 214 enteredText.append(getCharacter(key, pressedKeys)); 215 } 216 } 217 else 218 { 219 char theChar = getCharacter(key, pressedKeys); 220 if (theChar != Character.UNASSIGNED) 221 { 222 enteredText.append(theChar); 223 } 224 } 225 } 226 else if (((InteractionTask) child).getInteraction() instanceof KeyReleased) 227 { 228 pressedKeys.remove(((KeyReleased) ((InteractionTask) child).getInteraction()).getKey()); 229 } 230 } 231 else 232 { 233 determineEnteredText(child, pressedKeys, enteredText); 234 } 235 } 236 } 237 } 238 239 //----------------------------------------------------------------------------------------------- 240 /** 241 * TODO: comment 242 * 243 * @param key 244 * @param pressedKeys 245 * @return 246 */ 247 //----------------------------------------------------------------------------------------------- 248 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) 249 { 250 boolean numlock = false; 251 boolean shift = false; 252 boolean altgr = false; 253 254 for (VirtualKey pressedKey : pressedKeys) 255 { 256 if (pressedKey.isShiftKey()) 257 { 258 shift = !shift; 259 } 260 else if (pressedKey == VirtualKey.ALT_GRAPH) 261 { 262 altgr = !altgr; 263 } 264 else if (pressedKey == VirtualKey.NUM_LOCK) 265 { 266 numlock = !numlock; 267 } 268 } 269 270 return mKeyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 271 } 167 if ((node instanceof ISequence) || (node instanceof ITextInputEventTask)) { 168 for (ITaskTreeNode child : node.getChildren()) { 169 if (child instanceof IEventTask) { 170 if (((IEventTask) child).getEventType() instanceof KeyPressed) { 171 VirtualKey key = 172 ((KeyPressed) ((IEventTask) child).getEventType()).getKey(); 173 174 pressedKeys.add(key); 175 176 if (key == VirtualKey.BACK_SPACE) { 177 if (enteredText.length() > 0) { 178 enteredText.deleteCharAt(enteredText.length() - 1); 179 } 180 } 181 else if (key == VirtualKey.ENTER) { 182 // text fields only contain one line of code. Therefore the return is 183 // ignored. 184 if (!(((IEventTask) child).getEventTarget() instanceof ITextField)) { 185 enteredText.append(getCharacter(key, pressedKeys)); 186 } 187 } 188 else { 189 char theChar = getCharacter(key, pressedKeys); 190 if (theChar != Character.UNASSIGNED) { 191 enteredText.append(theChar); 192 } 193 } 194 } 195 else if (((IEventTask) child).getEventType() instanceof KeyReleased) { 196 pressedKeys.remove 197 (((KeyReleased) ((IEventTask) child).getEventType()).getKey()); 198 } 199 } 200 else { 201 determineEnteredText(child, pressedKeys, enteredText); 202 } 203 } 204 } 205 } 206 207 /** 208 * TODO: comment 209 * 210 * @param key 211 * @param pressedKeys 212 * @return 213 */ 214 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) { 215 boolean numlock = false; 216 boolean shift = false; 217 boolean altgr = false; 218 219 for (VirtualKey pressedKey : pressedKeys) { 220 if (pressedKey.isShiftKey()) { 221 shift = !shift; 222 } 223 else if (pressedKey == VirtualKey.ALT_GRAPH) { 224 altgr = !altgr; 225 } 226 else if (pressedKey == VirtualKey.NUM_LOCK) { 227 numlock = !numlock; 228 } 229 } 230 231 return keyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 232 } 272 233 273 234 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationResult.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationResult.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 … … 11 11 import java.util.List; 12 12 13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 14 15 //-------------------------------------------------------------------------------------------------16 15 /** 17 16 * TODO comment … … 20 19 * @author 2012, last modified by $Author: patrick$ 21 20 */ 22 //------------------------------------------------------------------------------------------------- 23 public class RuleApplicationResult 24 { 21 public class RuleApplicationResult { 25 22 26 /** */ 27 private RuleApplicationStatus mStatus = RuleApplicationStatus.RULE_NOT_APPLIED; 28 29 /** */ 30 private List<TaskTreeNode> mNewParents = new ArrayList<TaskTreeNode>(); 23 /** */ 24 private RuleApplicationStatus status = RuleApplicationStatus.RULE_NOT_APPLIED; 31 25 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * TODO: comment 35 * 36 * @param b 37 */ 38 //----------------------------------------------------------------------------------------------- 39 public RuleApplicationResult() 40 { 41 // this is the default indicating nothing so far 42 } 26 /** */ 27 private List<ITaskTreeNode> newParents = new ArrayList<ITaskTreeNode>(); 43 28 44 //----------------------------------------------------------------------------------------------- 45 /** 46 * TODO: comment 47 * 48 * @param b 49 */ 50 //----------------------------------------------------------------------------------------------- 51 public void setRuleApplicationStatus(RuleApplicationStatus status) 52 { 53 mStatus = status; 54 } 29 /** 30 * TODO: comment 31 * 32 * @param b 33 */ 34 public RuleApplicationResult() { 35 // this is the default indicating nothing so far 36 } 55 37 56 //----------------------------------------------------------------------------------------------- 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 //----------------------------------------------------------------------------------------------- 63 public RuleApplicationStatus getRuleApplicationStatus() 64 { 65 return mStatus; 66 } 38 /** 39 * TODO: comment 40 * 41 * @param b 42 */ 43 public void setRuleApplicationStatus(RuleApplicationStatus status) { 44 this.status = status; 45 } 67 46 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * TODO: comment 71 * 72 * @param sequence 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void addNewlyCreatedParentNode(TaskTreeNode newParent) 76 { 77 mNewParents.add(newParent); 78 } 47 /** 48 * TODO: comment 49 * 50 * @return 51 */ 52 public RuleApplicationStatus getRuleApplicationStatus() { 53 return status; 54 } 79 55 80 //----------------------------------------------------------------------------------------------- 81 /** 82 * TODO: comment 83 * 84 * @return 85 */ 86 //----------------------------------------------------------------------------------------------- 87 public List<TaskTreeNode> getNewlyCreatedParentNodes() 88 { 89 return mNewParents; 90 } 56 /** 57 * TODO: comment 58 * 59 * @param sequence 60 */ 61 public void addNewlyCreatedParentNode(ITaskTreeNode newParent) { 62 newParents.add(newParent); 63 } 64 65 /** 66 * TODO: comment 67 * 68 * @return 69 */ 70 public List<ITaskTreeNode> getNewlyCreatedParentNodes() { 71 return newParents; 72 } 91 73 92 74 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationStatus.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationStatus.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: pharms $ $Date: 09.07.2012 $ … … 5 4 // Creation : 2012 by pharms 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: pharms$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public enum RuleApplicationStatus 19 { 20 RULE_APPLICATION_FINISHED, 21 RULE_APPLICATION_FEASIBLE, 22 RULE_NOT_APPLIED; 16 public enum RuleApplicationStatus { 17 RULE_APPLICATION_FINISHED, 18 RULE_APPLICATION_FEASIBLE, 19 RULE_NOT_APPLIED; 23 20 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 14 * TODO comment … … 19 17 * @author 2012, last modified by $Author: patrick$ 20 18 */ 21 //------------------------------------------------------------------------------------------------- 22 public interface TemporalRelationshipRule 23 { 19 public interface TemporalRelationshipRule { 24 20 25 //-----------------------------------------------------------------------------------------------26 21 /** 27 22 * applies the rule to the given situation and returns a rule application result, if this was 28 23 * successful 29 24 */ 30 //----------------------------------------------------------------------------------------------- 31 public RuleApplicationResult apply(TaskTreeNode parent, 32 TaskTreeBuilder builder, 33 TaskTreeNodeFactory nodeFactory, 34 boolean finalize); 25 public RuleApplicationResult apply(ITaskTreeNode parent, 26 ITaskTreeBuilder builder, 27 ITaskTreeNodeFactory nodeFactory, 28 boolean finalize); 35 29 36 30 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 13 12 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;16 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 18 17 19 //-------------------------------------------------------------------------------------------------20 18 /** 21 19 * TODO comment … … 24 22 * @author 2012, last modified by $Author: patrick$ 25 23 */ 26 //------------------------------------------------------------------------------------------------- 27 public class TemporalRelationshipRuleManager 28 { 29 /** */ 30 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 24 public class TemporalRelationshipRuleManager { 25 26 /** */ 27 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 31 28 32 /** */33 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 34 31 35 /** */36 private List<TemporalRelationshipRule> mRuleIndex = new ArrayList<TemporalRelationshipRule>();32 /** */ 33 private List<TemporalRelationshipRule> ruleIndex = new ArrayList<TemporalRelationshipRule>(); 37 34 38 //----------------------------------------------------------------------------------------------- 39 /** 40 * TODO: comment 35 /** 36 * TODO: comment 37 * 38 */ 39 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) { 40 super(); 41 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 42 } 43 44 /** 45 * TODO: comment 46 * 47 */ 48 public void init() { 49 LOG.info("initializing"); 50 51 ruleIndex.add(new DefaultMouseClickReductionRule()); 52 ruleIndex.add(new DefaultTextInputReductionRule()); 53 ruleIndex.add(new DefaultEventTargetSequenceDetectionRule()); 54 ruleIndex.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager)); 55 ruleIndex.add(new DefaultGuiEventSequenceDetectionRule()); 56 ruleIndex.add(new DefaultIterationDetectionRule(nodeEqualityRuleManager)); 57 } 58 59 /** 60 * returns true, if there is a rule that matches the current situation and if, therefore, a new 61 * temporal relationship has been added to the tree. 62 * 63 * @param parent 64 * @param newChild 65 * @return 66 */ 67 public void applyRules(ITaskTreeNode parent, 68 ITaskTreeBuilder builder, 69 ITaskTreeNodeFactory nodeFactory, 70 boolean finalize) 71 { 72 applyRules(parent, builder, nodeFactory, finalize, ""); 73 } 74 75 /** 76 * returns true, if there is a rule that matches the current situation and if, therefore, a new 77 * temporal relationship has been added to the tree. 78 * 79 * @param parent 80 * @param newChild 81 * @return 82 */ 83 private int applyRules(ITaskTreeNode parent, 84 ITaskTreeBuilder builder, 85 ITaskTreeNodeFactory nodeFactory, 86 boolean finalize, 87 String logIndent) 88 { 89 LOG.info(logIndent + "applying rules for " + parent); 90 91 int noOfRuleApplications = 0; 92 93 for (TemporalRelationshipRule rule : ruleIndex) { 94 RuleApplicationResult result; 95 do { 96 // LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent); 97 result = rule.apply(parent, builder, nodeFactory, finalize); 98 99 if ((result != null) && 100 (result.getRuleApplicationStatus() == 101 RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 102 { 103 LOG.info(logIndent + "applied rule " + rule + " on " + parent); 104 noOfRuleApplications++; 105 106 for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 107 noOfRuleApplications += 108 applyRules(newParent, builder, nodeFactory, true, logIndent + " "); 109 } 110 } 111 } 112 while ((result != null) && 113 (result.getRuleApplicationStatus() == 114 RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 115 116 if ((!finalize) && 117 (result != null) && 118 (result.getRuleApplicationStatus() == 119 RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 120 { 121 // in this case, don't go on applying rules, which should not be applied yet 122 break; 123 } 124 } 125 126 if (noOfRuleApplications <= 0) { 127 LOG.warning(logIndent + "no rules applied --> no temporal relationship generated"); 128 } 129 130 return noOfRuleApplications; 131 } 132 133 /** 41 134 * 42 135 */ 43 //----------------------------------------------------------------------------------------------- 44 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) 45 { 46 super(); 47 mNodeEqualityRuleManager = nodeEqualityRuleManager; 48 } 49 50 //----------------------------------------------------------------------------------------------- 51 /** 52 * TODO: comment 53 * 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public void init() 57 { 58 LOG.info("initializing"); 59 60 mRuleIndex.add(new DefaultMouseClickReductionRule()); 61 mRuleIndex.add(new DefaultTextInputReductionRule()); 62 mRuleIndex.add(new DefaultGUIElementSequenceDetectionRule()); 63 mRuleIndex.add(new TrackBarSelectionDetectionRule(mNodeEqualityRuleManager)); 64 mRuleIndex.add(new DefaultSequenceDetectionRule()); 65 mRuleIndex.add(new DefaultIterationDetectionRule(mNodeEqualityRuleManager)); 66 } 67 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * returns true, if there is a rule that matches the current situation and if, therefore, a 71 * new temporal relationship has been added to the tree. 72 * 73 * @param parent 74 * @param newChild 75 * @return 76 */ 77 //----------------------------------------------------------------------------------------------- 78 public void applyRules(TaskTreeNode parent, 79 TaskTreeBuilder builder, 80 TaskTreeNodeFactory nodeFactory, 81 boolean finalize) 82 { 83 applyRules(parent, builder, nodeFactory, finalize, ""); 84 } 85 86 //----------------------------------------------------------------------------------------------- 87 /** 88 * returns true, if there is a rule that matches the current situation and if, therefore, a 89 * new temporal relationship has been added to the tree. 90 * 91 * @param parent 92 * @param newChild 93 * @return 94 */ 95 //----------------------------------------------------------------------------------------------- 96 private int applyRules(TaskTreeNode parent, 97 TaskTreeBuilder builder, 98 TaskTreeNodeFactory nodeFactory, 99 boolean finalize, 100 String logIndent) 101 { 102 LOG.info(logIndent + "applying rules for " + parent); 103 104 int noOfRuleApplications = 0; 105 106 for (TemporalRelationshipRule rule : mRuleIndex) 107 { 108 RuleApplicationResult result; 109 do 110 { 111 //LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent); 112 result = rule.apply(parent, builder, nodeFactory, finalize); 113 114 if ((result != null) && 115 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 116 { 117 LOG.info(logIndent + "applied rule " + rule + " on " + parent); 118 noOfRuleApplications++; 119 120 for (TaskTreeNode newParent : result.getNewlyCreatedParentNodes()) 121 { 122 noOfRuleApplications += 123 applyRules(newParent, builder, nodeFactory, true, logIndent + " "); 124 } 125 } 126 } 127 while ((result != null) && 128 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 129 130 if ((!finalize) && (result != null) && 131 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 132 { 133 // in this case, don't go on applying rules, which should not be applied yet 134 break; 135 } 136 } 137 138 if (noOfRuleApplications <= 0) 139 { 140 LOG.warning(logIndent + "no rules applied --> no temporal relationship generated"); 141 } 142 143 return noOfRuleApplications; 144 } 145 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 /*private void dumpTask(TaskTreeNode task, String indent) 152 { 153 System.err.print(indent); 154 System.err.print(task); 155 System.err.println(" "); 156 157 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) 158 { 159 for (TaskTreeNode child : task.getChildren()) 160 { 161 dumpTask(child, indent + " "); 162 } 163 } 164 }*/ 136 /* 137 * private void dumpTask(TaskTreeNode task, String indent) { System.err.print(indent); 138 * System.err.print(task); System.err.println(" "); 139 * 140 * if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { for (TaskTreeNode 141 * child : task.getChildren()) { dumpTask(child, indent + " "); } } } 142 */ 165 143 166 144 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TrackBarSelectionDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore.gui model.TrackBar;11 import de.ugoe.cs.quest.eventcore. userinteraction.ValueSelection;9 import de.ugoe.cs.quest.eventcore.gui.ValueSelection; 10 import de.ugoe.cs.quest.eventcore.guimodel.ITrackBar; 12 11 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 14 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;15 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;16 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;17 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;20 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;13 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 21 20 22 //-------------------------------------------------------------------------------------------------23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule 31 { 27 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule { 32 28 33 /** */34 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 35 31 36 //----------------------------------------------------------------------------------------------- 37 /** 38 * TODO: comment 32 /** 33 * TODO: comment 34 * 35 */ 36 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder builder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 RuleApplicationResult result = new RuleApplicationResult(); 57 58 int valueSelectionStartIndex = -1; 59 60 int index = 0; 61 while (index < parent.getChildren().size()) { 62 ITaskTreeNode child = parent.getChildren().get(index); 63 64 if ((child instanceof IEventTask) && 65 (((IEventTask) child).getEventTarget() instanceof ITrackBar) && 66 (((IEventTask) child).getEventType() instanceof ValueSelection)) 67 { 68 if (valueSelectionStartIndex < 0) { 69 // let the show begin 70 valueSelectionStartIndex = index; 71 } 72 } 73 else if (valueSelectionStartIndex >= 0) { 74 // current child is no more value selection. But the preceding tasks were. 75 // Therefore, 76 // create an iteration with the different selectable values as selection children 77 handleValueSelections(valueSelectionStartIndex, index - 1, parent, builder, 78 nodeFactory, result); 79 80 return result; 81 } 82 83 index++; 84 } 85 86 if (valueSelectionStartIndex >= 0) { 87 if (finalize) { 88 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, 89 parent, builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param valueSelectionStartIndex 103 * @param i 104 */ 105 private void handleValueSelections(int startIndex, 106 int endIndex, 107 ITaskTreeNode parent, 108 ITaskTreeBuilder builder, 109 ITaskTreeNodeFactory nodeFactory, 110 RuleApplicationResult result) 111 { 112 IIteration iteration = nodeFactory.createNewIteration(); 113 result.addNewlyCreatedParentNode(iteration); 114 115 ISelection selection = nodeFactory.createNewSelection(); 116 result.addNewlyCreatedParentNode(selection); 117 builder.setChild(iteration, selection); 118 119 for (int i = endIndex - startIndex; i >= 0; i--) { 120 addChildIfNecessary(selection, parent.getChildren().get(startIndex), builder, 121 nodeFactory, result); 122 builder.removeChild((ISequence) parent, startIndex); 123 } 124 125 builder.addChild((ISequence) parent, startIndex, iteration); 126 127 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 128 } 129 130 /** 39 131 * 40 132 */ 41 //----------------------------------------------------------------------------------------------- 42 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 43 { 44 super(); 45 mNodeEqualityRuleManager = nodeEqualityRuleManager; 46 } 133 private void addChildIfNecessary(ISelection parentSelection, 134 ITaskTreeNode node, 135 ITaskTreeBuilder builder, 136 ITaskTreeNodeFactory nodeFactory, 137 RuleApplicationResult result) 138 { 139 for (int i = 0; i < parentSelection.getChildren().size(); i++) { 140 ITaskTreeNode child = parentSelection.getChildren().get(i); 47 141 48 //----------------------------------------------------------------------------------------------- 49 /* (non-Javadoc) 50 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 51 */ 52 //----------------------------------------------------------------------------------------------- 53 @Override 54 public RuleApplicationResult apply(TaskTreeNode parent, 55 TaskTreeBuilder builder, 56 TaskTreeNodeFactory nodeFactory, 57 boolean finalize) 58 { 59 if (!(parent instanceof Sequence)) 60 { 61 return null; 62 } 63 64 RuleApplicationResult result = new RuleApplicationResult(); 65 66 int valueSelectionStartIndex = -1; 67 68 int index = 0; 69 while (index < parent.getChildren().size()) 70 { 71 TaskTreeNode child = parent.getChildren().get(index); 72 73 if ((child instanceof InteractionTask) && 74 (((InteractionTask) child).getGUIElement() instanceof TrackBar) && 75 (((InteractionTask) child).getInteraction() instanceof ValueSelection)) 76 { 77 if (valueSelectionStartIndex < 0) 78 { 79 // let the show begin 80 valueSelectionStartIndex = index; 81 } 82 } 83 else if (valueSelectionStartIndex >= 0) 84 { 85 // current child is no more value selection. But the preceding tasks were. Therefore, 86 // create an iteration with the different selectable values as selection children 87 handleValueSelections 88 (valueSelectionStartIndex, index - 1, parent, builder, nodeFactory, result); 89 90 return result; 91 } 92 93 index++; 94 } 95 96 if (valueSelectionStartIndex >= 0) 97 { 98 if (finalize) 99 { 100 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, parent, 101 builder, nodeFactory, result); 102 } 103 else 104 { 105 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 106 } 107 } 108 109 return result; 110 } 142 if (child instanceof IEventTask) { 143 // check, if the new node is a variant for the current event task 144 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 145 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 146 // the node is a variant. If it not structurally equal, a new sub-selection for 147 // the existing and the new node must be created. Otherwise, the new node does 148 // not need to be added 149 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 150 ISelection selection = nodeFactory.createNewSelection(); 151 result.addNewlyCreatedParentNode(selection); 152 builder.addChild(parentSelection, selection); 111 153 112 //----------------------------------------------------------------------------------------------- 113 /** 114 * TODO: comment 115 * 116 * @param valueSelectionStartIndex 117 * @param i 118 */ 119 //----------------------------------------------------------------------------------------------- 120 private void handleValueSelections(int startIndex, 121 int endIndex, 122 TaskTreeNode parent, 123 TaskTreeBuilder builder, 124 TaskTreeNodeFactory nodeFactory, 125 RuleApplicationResult result) 126 { 127 Iteration iteration = nodeFactory.createNewIteration(); 128 result.addNewlyCreatedParentNode(iteration); 129 130 Selection selection = nodeFactory.createNewSelection(); 131 result.addNewlyCreatedParentNode(selection); 132 builder.setChild(iteration, selection); 133 134 for (int i = endIndex - startIndex; i >= 0 ; i--) 135 { 136 addChildIfNecessary 137 (selection, parent.getChildren().get(startIndex), builder, nodeFactory, result); 138 builder.removeChild((Sequence) parent, startIndex); 139 } 140 141 builder.addChild((Sequence) parent, startIndex, iteration); 142 143 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 144 } 154 builder.addChild(selection, child); 155 builder.addChild(selection, node); 156 builder.removeChild(parentSelection, child); 157 } 145 158 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 private void addChildIfNecessary(Selection parentSelection, 152 TaskTreeNode node, 153 TaskTreeBuilder builder, 154 TaskTreeNodeFactory nodeFactory, 155 RuleApplicationResult result) 156 { 157 for (int i = 0; i < parentSelection.getChildren().size(); i++) 158 { 159 TaskTreeNode child = parentSelection.getChildren().get(i); 159 return; 160 } 161 } 162 else if (child instanceof ISelection) { 163 // check, if the new node is a variant for the semantically equal children of the 164 // current 165 // selection 166 boolean addNode = true; 167 for (int j = 0; j < child.getChildren().size(); j++) { 168 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 169 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 170 // the new node is no semantical equivalent of the nodes in the current 171 // selection - break up 172 addNode = false; 173 break; 174 } 175 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 176 addNode = false; 177 break; 178 } 179 } 160 180 161 if (child instanceof InteractionTask) 162 { 163 // check, if the new node is a variant for the current interaction task 164 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 165 if (nodeEquality.getSemanticalEquality()) 166 { 167 // the node is a variant. If it not structurally equal, a new sub-selection for the 168 // existing and the new node must be created. Otherwise, the new node does not need 169 // to be added 170 if (!nodeEquality.getStructuralEquality()) 171 { 172 Selection selection = nodeFactory.createNewSelection(); 173 result.addNewlyCreatedParentNode(selection); 174 builder.addChild(parentSelection, selection); 175 176 builder.addChild(selection, child); 177 builder.addChild(selection, node); 178 builder.removeChild(parentSelection, child); 179 } 180 181 return; 182 } 183 } 184 else if (child instanceof Selection) 185 { 186 // check, if the new node is a variant for the semantically equal children of the current 187 // selection 188 boolean addNode = true; 189 for (int j = 0; j < child.getChildren().size(); j++) 190 { 191 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 192 if (!nodeEquality.getSemanticalEquality()) 193 { 194 // the new node is no semantical equivalent of the nodes in the current selection - 195 // break up 196 addNode = false; 197 break; 198 } 199 else if (nodeEquality.getStructuralEquality()) 200 { 201 addNode = false; 202 break; 203 } 181 if (addNode) { 182 // the node is a semantical equivalent to all the nodes in the existing 183 // sub-selection 184 // but it is not structurally identical to either of them. Therefore add it. 185 builder.addChild((ISelection) child, node); 186 return; 187 } 188 } 204 189 } 205 190 206 if (addNode) 207 { 208 // the node is a semantical equivalent to all the nodes in the existing sub-selection 209 // but it is not structurally identical to either of them. Therefore add it. 210 builder.addChild((Selection) child, node); 211 return; 212 } 213 } 191 // if we did not return in the previous checks, then the node must be added 192 builder.addChild(parentSelection, node); 214 193 } 215 216 // if we did not return in the previous checks, then the node must be added217 builder.addChild(parentSelection, node);218 }219 194 220 195 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/IEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: InteractionTask.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 19:44:52 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; 10 8 11 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;12 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 13 11 14 //-------------------------------------------------------------------------------------------------15 12 /** 16 13 * TODO comment 17 * 14 * 18 15 * @version $Revision: $ $Date: $ 19 * @author 16 * @author 2011, last modified by $Author: $ 20 17 */ 21 //------------------------------------------------------------------------------------------------- 22 public interface InteractionTask extends TaskTreeNode 23 { 24 //----------------------------------------------------------------------------------------------- 25 /** 26 * @return Returns the interaction. 27 */ 28 //----------------------------------------------------------------------------------------------- 29 public Interaction getInteraction(); 18 public interface IEventTask extends ITaskTreeNode { 19 20 /** 21 * @return Returns the event type. 22 */ 23 public IEventType getEventType(); 30 24 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * @return Returns the GUIElement. 34 */ 35 //----------------------------------------------------------------------------------------------- 36 public GUIElement getGUIElement(); 25 /** 26 * @return Returns the event target. 27 */ 28 public IEventTarget getEventTarget(); 29 30 /** 31 * TODO: comment 32 * 33 * @return 34 */ 35 public IEventTask clone(); 37 36 38 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/IIteration.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Iteration.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Iteration extends TemporalRelationship 19 { 15 public interface IIteration extends ITemporalRelationship { 16 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public IIteration clone(); 20 23 21 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ISelection.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Selection.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Selection extends TemporalRelationship 19 { 15 public interface ISelection extends ITemporalRelationship { 16 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public ISelection clone(); 20 23 21 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ISequence.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Sequence.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Sequence extends TemporalRelationship 19 { 15 public interface ISequence extends ITemporalRelationship { 20 16 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @return 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public Sequence clone(); 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public ISequence clone(); 29 23 30 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTree.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTree.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 9 import java.util.Map; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public interface TaskTree extends Cloneable 21 { 17 public interface ITaskTree extends Cloneable { 22 18 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * TODO: comment 26 * 27 * @return 28 */ 29 //----------------------------------------------------------------------------------------------- 30 public TaskTreeNode getRoot(); 19 /** 20 * TODO: comment 21 * 22 * @return 23 */ 24 public ITaskTreeNode getRoot(); 31 25 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * TODO: comment 35 * 36 * @return 37 */ 38 //----------------------------------------------------------------------------------------------- 39 public Map<TaskTreeNode, NodeInfo> getTaskMap(); 26 /** 27 * TODO: comment 28 * 29 * @return 30 */ 31 public Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap(); 40 32 41 //----------------------------------------------------------------------------------------------- 42 /** 43 * 44 */ 45 //----------------------------------------------------------------------------------------------- 46 public TaskTree clone(); 33 /** 34 * 35 */ 36 public ITaskTree clone(); 47 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeBuilder.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeBuilder.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeifc; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: patrick$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface TaskTreeBuilder 19 { 16 public interface ITaskTreeBuilder { 20 17 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @param sequence 26 * @param task 27 */ 28 //----------------------------------------------------------------------------------------------- 29 void addChild(Sequence parent, TaskTreeNode child); 18 /** 19 * TODO: comment 20 * 21 * @param sequence 22 * @param task 23 */ 24 void addChild(ISequence parent, ITaskTreeNode child); 30 25 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * TODO: comment 34 * 35 * @param parent 36 * @param index 37 * @param sequence 38 */ 39 //----------------------------------------------------------------------------------------------- 40 void addChild(Sequence parent, int index, TaskTreeNode child); 26 /** 27 * TODO: comment 28 * 29 * @param parent 30 * @param index 31 * @param sequence 32 */ 33 void addChild(ISequence parent, int index, ITaskTreeNode child); 41 34 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * TODO: comment 45 * 46 * @param sequence 47 * @param task 48 */ 49 //----------------------------------------------------------------------------------------------- 50 void addChild(Selection parent, TaskTreeNode child); 35 /** 36 * TODO: comment 37 * 38 * @param sequence 39 * @param task 40 */ 41 void addChild(ISelection parent, ITaskTreeNode child); 51 42 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * TODO: comment 55 * 56 * @param sequence 57 * @param task 58 */ 59 //----------------------------------------------------------------------------------------------- 60 void addChild(TextInputInteractionTask parent, TaskTreeNode child); 43 /** 44 * TODO: comment 45 * 46 * @param sequence 47 * @param task 48 */ 49 void addChild(ITextInputEventTask parent, ITaskTreeNode child); 61 50 62 //----------------------------------------------------------------------------------------------- 63 /** 64 * TODO: comment 65 * 66 * @param iteration 67 * @param newChild 68 */ 69 //----------------------------------------------------------------------------------------------- 70 void setChild(Iteration iteration, TaskTreeNode newChild); 51 /** 52 * TODO: comment 53 * 54 * @param iteration 55 * @param newChild 56 */ 57 void setChild(IIteration iteration, ITaskTreeNode newChild); 71 58 72 //----------------------------------------------------------------------------------------------- 73 /** 74 * TODO: comment 75 * 76 * @param parent 77 * @param i 78 */ 79 //----------------------------------------------------------------------------------------------- 80 void removeChild(Sequence parent, int index); 59 /** 60 * TODO: comment 61 * 62 * @param parent 63 * @param i 64 */ 65 void removeChild(ISequence parent, int index); 81 66 82 //----------------------------------------------------------------------------------------------- 83 /** 84 * TODO: comment 85 * 86 * @param parent 87 * @param i 88 */ 89 //----------------------------------------------------------------------------------------------- 90 void removeChild(Selection parent, TaskTreeNode child); 67 /** 68 * TODO: comment 69 * 70 * @param parent 71 * @param i 72 */ 73 void removeChild(ISelection parent, ITaskTreeNode child); 91 74 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * TODO: comment 95 * 96 * @param parent 97 * @param i 98 */ 99 //----------------------------------------------------------------------------------------------- 100 void setDescription(TaskTreeNode parent, String description); 75 /** 76 * TODO: comment 77 * 78 * @param parent 79 * @param i 80 */ 81 void setDescription(ITaskTreeNode node, String description); 101 82 102 83 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNode.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Task.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 19:42:29 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; … … 11 9 import java.util.List; 12 10 13 //-------------------------------------------------------------------------------------------------14 11 /** 15 12 * TODO comment 16 * 13 * 17 14 * @version $Revision: $ $Date: $ 18 * @author 15 * @author 2011, last modified by $Author: $ 19 16 */ 20 //------------------------------------------------------------------------------------------------- 21 public interface TaskTreeNode extends Cloneable 22 { 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public String getName(); 17 public interface ITaskTreeNode extends Cloneable { 29 18 30 //----------------------------------------------------------------------------------------------- 31 /** 32 */ 33 //----------------------------------------------------------------------------------------------- 34 //public void addChild(TaskTreeNode child); 35 36 //----------------------------------------------------------------------------------------------- 37 /** 38 */ 39 //----------------------------------------------------------------------------------------------- 40 //public void removeChild(int index); 41 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * 45 */ 46 //----------------------------------------------------------------------------------------------- 47 public String getDescription(); 19 /** 20 * 21 */ 22 public String getName(); 48 23 49 //----------------------------------------------------------------------------------------------- 50 /** 51 */ 52 //----------------------------------------------------------------------------------------------- 53 public List<TaskTreeNode> getChildren(); 54 55 //----------------------------------------------------------------------------------------------- 56 /** 57 * 58 */ 59 //----------------------------------------------------------------------------------------------- 60 public boolean equals(TaskTreeNode taskTreeNode); 24 /** 25 * 26 */ 27 public String getDescription(); 61 28 62 //----------------------------------------------------------------------------------------------- 63 /** 64 * 65 */ 66 //----------------------------------------------------------------------------------------------- 67 public int hashCode(); 29 /** 30 * 31 */ 32 public List<ITaskTreeNode> getChildren(); 68 33 69 //----------------------------------------------------------------------------------------------- 70 /** 71 * 72 */ 73 //----------------------------------------------------------------------------------------------- 74 public TaskTreeNode clone(); 34 /** 35 * 36 */ 37 public boolean equals(ITaskTreeNode taskTreeNode); 38 39 /** 40 * 41 */ 42 public int hashCode(); 43 44 /** 45 * 46 */ 47 public ITaskTreeNode clone(); 48 75 49 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNodeFactory.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeNodeFactory.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 13 * TODO comment … … 18 16 * @author 2012, last modified by $Author: patrick$ 19 17 */ 20 //------------------------------------------------------------------------------------------------- 21 public interface TaskTreeNodeFactory 18 public interface ITaskTreeNodeFactory 22 19 { 23 20 24 //-----------------------------------------------------------------------------------------------25 21 /** 26 22 * TODO: comment 27 23 * 28 * @param GUIElement29 * @param interaction24 * @param eventType 25 * @param eventTarget 30 26 * @return 31 27 */ 32 //----------------------------------------------------------------------------------------------- 33 InteractionTask createNewInteractionTask(GUIElement guiElement, 34 Interaction interaction); 28 IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget); 35 29 36 //-----------------------------------------------------------------------------------------------37 30 /** 38 31 * TODO: comment … … 40 33 * @return 41 34 */ 42 //----------------------------------------------------------------------------------------------- 43 Sequence createNewSequence(); 35 ISequence createNewSequence(); 44 36 45 //-----------------------------------------------------------------------------------------------46 37 /** 47 38 * TODO: comment … … 49 40 * @return 50 41 */ 51 //----------------------------------------------------------------------------------------------- 52 TextInputInteractionTask createNewTextInputInteractionTask(GUIElement guiElement); 42 ITextInputEventTask createNewTextInputEventTask(IEventTarget eventTarget); 53 43 54 //-----------------------------------------------------------------------------------------------55 44 /** 56 45 * TODO: comment … … 58 47 * @return 59 48 */ 60 //----------------------------------------------------------------------------------------------- 61 Iteration createNewIteration(); 49 IIteration createNewIteration(); 62 50 63 //-----------------------------------------------------------------------------------------------64 51 /** 65 52 * TODO: comment … … 67 54 * @return 68 55 */ 69 //----------------------------------------------------------------------------------------------- 70 Selection createNewSelection(); 56 ISelection createNewSelection(); 71 57 72 //-----------------------------------------------------------------------------------------------73 58 /** 74 59 * TODO: comment … … 77 62 * @return 78 63 */ 79 //----------------------------------------------------------------------------------------------- 80 TaskTree createTaskTree(TaskTreeNode root); 64 ITaskTree createTaskTree(ITaskTreeNode root); 81 65 82 66 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNodeInfo.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeInfo.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; 10 8 11 //-------------------------------------------------------------------------------------------------12 9 /** 13 10 * TODO comment … … 16 13 * @author 2012, last modified by $Author: patrick$ 17 14 */ 18 //------------------------------------------------------------------------------------------------- 19 public interface NodeInfo 20 { 15 public interface ITaskTreeNodeInfo { 21 16 22 //----------------------------------------------------------------------------------------------- 23 /** 24 * 25 */ 26 //----------------------------------------------------------------------------------------------- 27 public TaskTreeNode getTask(); 17 /** 18 * 19 */ 20 public ITaskTreeNode getTask(); 28 21 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public int getNoOfOccurencesInTree(); 22 /** 23 * 24 */ 25 public int getNoOfOccurencesInTree(); 35 26 36 //----------------------------------------------------------------------------------------------- 37 /** 38 * 39 */ 40 //----------------------------------------------------------------------------------------------- 41 public long getLastUpdate(); 27 /** 28 * 29 */ 30 public long getLastUpdate(); 42 31 43 32 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITemporalRelationship.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationship.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 // ------------------------------------------------------------------------------------------------- 18 public interface TemporalRelationship extends TaskTreeNode 19 { 15 public interface ITemporalRelationship extends ITaskTreeNode { 16 17 /** 18 * 19 */ 20 public ITemporalRelationship clone(); 20 21 21 22 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITextInputEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TextInputSequence.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 10.06.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeifc; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: patrick$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface TextInputInteractionTask extends InteractionTask 19 { 20 //----------------------------------------------------------------------------------------------- 21 /** 22 * TODO: comment 23 * 24 * @return 25 */ 26 //----------------------------------------------------------------------------------------------- 27 public TextInputInteractionTask clone(); 16 public interface ITextInputEventTask extends IEventTask { 17 18 /** 19 * 20 */ 21 public String getEnteredText(); 28 22 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public String getEnteredText(); 23 /** 24 * TODO: comment 25 * 26 * @param string 27 */ 28 public void setEnteredText(String text); 29 30 /** 31 * TODO: comment 32 * 33 * @return 34 */ 35 public ITextInputEventTask clone(); 35 36 36 //-----------------------------------------------------------------------------------------------37 /**38 * TODO: comment39 *40 * @param string41 */42 //-----------------------------------------------------------------------------------------------43 public void setEnteredText(String text);44 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/EventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: InteractionTask.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:57:52 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 10 8 11 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;12 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;13 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 11 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 13 16 //-------------------------------------------------------------------------------------------------17 14 /** 18 15 * TODO comment 19 * 16 * 20 17 * @version $Revision: $ $Date: $ 21 * @author 18 * @author 2011, last modified by $Author: $ 22 19 */ 23 //------------------------------------------------------------------------------------------------- 24 public class InteractionTaskImpl extends TaskTreeNodeImpl implements InteractionTask 25 { 26 /** */ 27 private GUIElement mGUIElement; 28 29 /** */ 30 private Interaction mInteraction; 20 public class EventTask extends TaskTreeNode implements IEventTask { 21 22 /** */ 23 private IEventType eventType; 31 24 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * @param guiElement 35 * @param interaction 36 */ 37 //----------------------------------------------------------------------------------------------- 38 InteractionTaskImpl(GUIElement guiElement, Interaction interaction) 39 { 40 super(interaction.getName() + "(" + guiElement + ")"); 41 super.setDescription(interaction + " on " + guiElement); 42 mGUIElement = guiElement; 43 mInteraction = interaction; 44 } 25 /** */ 26 private IEventTarget eventTarget; 45 27 46 //----------------------------------------------------------------------------------------------- 47 /** 48 * @return Returns the interaction. 49 */ 50 //----------------------------------------------------------------------------------------------- 51 public Interaction getInteraction() 52 { 53 return mInteraction; 54 } 28 /** 29 * @param eventType 30 * @param eventTarget 31 */ 32 EventTask(IEventType eventType, IEventTarget eventTarget) { 33 super(eventType.getName() + "(" + eventTarget + ")"); 34 super.setDescription(eventType + " on " + eventTarget); 35 this.eventType = eventType; 36 this.eventTarget = eventTarget; 37 } 55 38 56 57 //----------------------------------------------------------------------------------------------- 58 /** 59 * @return Returns the GUIElement. 60 */ 61 //----------------------------------------------------------------------------------------------- 62 public GUIElement getGUIElement() 63 { 64 return mGUIElement; 65 } 39 /** 40 * @return Returns the interaction. 41 */ 42 public IEventType getEventType() { 43 return eventType; 44 } 66 45 67 //----------------------------------------------------------------------------------------------- 68 /* (non-Javadoc) 69 * @see de.harms.ctte.Task#equals(de.harms.ctte.Task) 70 */ 71 //----------------------------------------------------------------------------------------------- 72 @Override 73 public boolean equals(TaskTreeNode task) 74 { 75 if (!(task instanceof InteractionTask)) 76 { 77 return false; 46 /** 47 * @return Returns the GUIElement. 48 */ 49 public IEventTarget getEventTarget() { 50 return eventTarget; 78 51 } 79 80 GUIElement otherInteractionElem = ((InteractionTask) task).getGUIElement(); 81 Interaction otherInteraction = ((InteractionTask) task).getInteraction(); 82 83 if ((((mGUIElement == null) && (otherInteractionElem == null)) || 84 ((mGUIElement != null) && (mGUIElement.equals(otherInteractionElem)))) && 85 (((mInteraction == null) && (otherInteraction == null)) || 86 ((mInteraction != null) && (mInteraction.equals(otherInteraction))))) 87 { 88 return true; 52 53 /* 54 * (non-Javadoc) 55 * 56 * @see de.harms.ctte.Task#equals(de.harms.ctte.Task) 57 */ 58 @Override 59 public boolean equals(ITaskTreeNode task) { 60 if (!(task instanceof IEventTask)) { 61 return false; 62 } 63 64 IEventType otherType = ((IEventTask) task).getEventType(); 65 IEventTarget otherTarget = ((IEventTask) task).getEventTarget(); 66 67 if (((eventType == otherType) || 68 ((eventType != null) && (eventType.equals(otherType)))) && 69 ((eventTarget == otherTarget) || 70 ((eventTarget != null) && (eventTarget.equals(otherTarget))))) 71 { 72 return true; 73 } 74 75 return false; 89 76 } 90 91 return false;92 }93 77 94 //----------------------------------------------------------------------------------------------- 95 /* (non-Javadoc) 96 * @see de.harms.tasktrees.TreeNode#clone() 97 */ 98 //----------------------------------------------------------------------------------------------- 99 @Override 100 public InteractionTaskImpl clone() 101 { 102 // GUI element and interaction are unchangeable and do not need to be cloned 103 return (InteractionTaskImpl) super.clone(); 104 } 78 /* 79 * (non-Javadoc) 80 * 81 * @see de.harms.tasktrees.TreeNode#clone() 82 */ 83 @Override 84 public EventTask clone() { 85 // Event type and target are unchangeable and do not need to be cloned 86 return (EventTask) super.clone(); 87 } 105 88 106 89 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Iteration.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Iteration.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;10 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 12 13 //-------------------------------------------------------------------------------------------------14 13 /** 15 14 * TODO comment … … 18 17 * @author 2012, last modified by $Author: patrick$ 19 18 */ 20 //------------------------------------------------------------------------------------------------- 21 public class IterationImpl extends TaskTreeNodeImpl implements Iteration 22 { 19 public class Iteration extends TaskTreeNode implements IIteration { 23 20 24 //----------------------------------------------------------------------------------------------- 25 /** 26 * 27 */ 28 //----------------------------------------------------------------------------------------------- 29 IterationImpl() 30 { 31 super("Iteration"); 32 } 21 /** 22 * 23 */ 24 Iteration() { 25 super("Iteration"); 26 } 33 27 34 //-----------------------------------------------------------------------------------------------35 /* (non-Javadoc)36 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode)37 */38 //-----------------------------------------------------------------------------------------------39 @Override40 public void addChild(TaskTreeNode child)41 {42 // adding more children is not allowed43 throw new UnsupportedOperationException();44 }28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode) 32 */ 33 @Override 34 public void addChild(ITaskTreeNode child) { 35 // adding more children is not allowed 36 throw new UnsupportedOperationException 37 ("iterations may not have a list of children. Use setChild() instead."); 38 } 45 39 46 //----------------------------------------------------------------------------------------------- 47 /** 48 * TODO: comment 49 * 50 * @param selection 51 * @return 52 */ 53 //----------------------------------------------------------------------------------------------- 54 public void setChild(TaskTreeNode child) 55 { 56 if (super.getChildren().size() > 0) 57 { 58 super.removeChild(0); 40 /** 41 * TODO: comment 42 * 43 * @param selection 44 * @return 45 */ 46 public void setChild(ITaskTreeNode child) { 47 if (super.getChildren().size() > 0) { 48 super.removeChild(0); 49 } 50 super.addChild(child); 59 51 } 60 super.addChild(child);61 }62 52 63 //----------------------------------------------------------------------------------------------- 64 /* (non-Javadoc) 65 * @see java.lang.Object#clone() 66 */ 67 //----------------------------------------------------------------------------------------------- 68 @Override 69 public IterationImpl clone() 70 { 71 return (IterationImpl) super.clone(); 72 } 53 /* 54 * (non-Javadoc) 55 * 56 * @see java.lang.Object#clone() 57 */ 58 @Override 59 public Iteration clone() { 60 return (Iteration) super.clone(); 61 } 73 62 74 63 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/NodeInfo.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeInfo.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 05.11.2011 19:24:14 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; … … 12 10 import java.util.List; 13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 14 17 18 //-------------------------------------------------------------------------------------------------19 15 /** 20 16 * TODO comment 21 * 17 * 22 18 * @version $Revision: $ $Date: $ 23 * @author 19 * @author 2011, last modified by $Author: $ 24 20 */ 25 //------------------------------------------------------------------------------------------------- 26 public class NodeInfoImpl implements NodeInfo 27 { 28 /** */ 29 private TaskTreeNode mTask; 30 31 /** */ 32 private long mLastUpdate; 21 public class NodeInfo implements ITaskTreeNodeInfo { 22 23 /** */ 24 private ITaskTreeNode task; 33 25 34 /** */35 private List<TaskTreeNode> mParentNodes = new ArrayList<TaskTreeNode>();26 /** */ 27 private long lastUpdate; 36 28 37 //----------------------------------------------------------------------------------------------- 38 /** 39 * @param node 40 */ 41 //----------------------------------------------------------------------------------------------- 42 NodeInfoImpl(TaskTreeNode task) 43 { 44 mTask = task; 45 mLastUpdate = System.currentTimeMillis(); 46 } 29 /** */ 30 private List<ITaskTreeNode> parentNodes = new ArrayList<ITaskTreeNode>(); 47 31 48 //----------------------------------------------------------------------------------------------- 49 /* (non-Javadoc) 50 * @see de.ugoe.cs.tasktree.treeifc.NodeInfo#getTask() 51 */ 52 //----------------------------------------------------------------------------------------------- 53 @Override 54 public TaskTreeNode getTask() 55 { 56 return mTask; 57 } 32 /** 33 * @param node 34 */ 35 NodeInfo(ITaskTreeNode task) { 36 this.task = task; 37 lastUpdate = System.currentTimeMillis(); 38 } 58 39 59 //----------------------------------------------------------------------------------------------- 60 /* (non-Javadoc) 61 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getNoOfOccurencesInTree() 62 */ 63 //----------------------------------------------------------------------------------------------- 64 @Override 65 public int getNoOfOccurencesInTree() 66 { 67 return mParentNodes.size(); 68 } 40 /* 41 * (non-Javadoc) 42 * 43 * @see de.ugoe.cs.tasktree.treeifc.NodeInfo#getTask() 44 */ 45 @Override 46 public ITaskTreeNode getTask() { 47 return task; 48 } 69 49 70 //----------------------------------------------------------------------------------------------- 71 /* (non-Javadoc) 72 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getLastUpdate() 73 */ 74 //----------------------------------------------------------------------------------------------- 75 @Override 76 public long getLastUpdate() 77 { 78 return mLastUpdate; 79 } 50 /* 51 * (non-Javadoc) 52 * 53 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getNoOfOccurencesInTree() 54 */ 55 @Override 56 public int getNoOfOccurencesInTree() { 57 return parentNodes.size(); 58 } 80 59 81 //----------------------------------------------------------------------------------------------- 82 /** 83 * TODO: comment 84 * 85 */ 86 //----------------------------------------------------------------------------------------------- 87 void addParent(TaskTreeNode parent) 88 { 89 mParentNodes.add(parent); 90 } 60 /* 61 * (non-Javadoc) 62 * 63 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getLastUpdate() 64 */ 65 @Override 66 public long getLastUpdate() { 67 return lastUpdate; 68 } 91 69 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * TODO: comment 95 * 96 */ 97 //----------------------------------------------------------------------------------------------- 98 void removeParent(TaskTreeNode parent) 99 { 100 mParentNodes.remove(parent); 101 } 70 /** 71 * TODO: comment 72 * 73 */ 74 void addParent(ITaskTreeNode parent) { 75 parentNodes.add(parent); 76 } 102 77 103 //----------------------------------------------------------------------------------------------- 104 /* (non-Javadoc) 105 * @see java.lang.Object#toString() 106 */ 107 //----------------------------------------------------------------------------------------------- 108 @Override 109 public synchronized String toString() 110 { 111 return "NodeInfo(" + mTask + ", " + mParentNodes.size() + " parents)"; 112 } 113 78 /** 79 * TODO: comment 80 * 81 */ 82 void removeParent(ITaskTreeNode parent) { 83 parentNodes.remove(parent); 84 } 85 86 /* 87 * (non-Javadoc) 88 * 89 * @see java.lang.Object#toString() 90 */ 91 @Override 92 public synchronized String toString() { 93 return "NodeInfo(" + task + ", " + parentNodes.size() + " parents)"; 94 } 95 114 96 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Selection.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Selection.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class SelectionImpl extends TaskTreeNodeImpl implements Selection 21 { 17 public class Selection extends TaskTreeNode implements ISelection { 22 18 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * TODO: comment 26 * 27 * @param name 28 */ 29 //----------------------------------------------------------------------------------------------- 30 SelectionImpl() 31 { 32 super("Selection"); 33 } 19 /** 20 * TODO: comment 21 * 22 * @param name 23 */ 24 Selection() { 25 super("Selection"); 26 } 34 27 35 //----------------------------------------------------------------------------------------------- 36 /* (non-Javadoc) 37 * @see java.lang.Object#clone() 38 */ 39 //----------------------------------------------------------------------------------------------- 40 @Override 41 public SelectionImpl clone() 42 { 43 return (SelectionImpl) super.clone(); 44 } 28 /* 29 * (non-Javadoc) 30 * 31 * @see java.lang.Object#clone() 32 */ 33 @Override 34 public Selection clone() { 35 return (Selection) super.clone(); 36 } 45 37 46 38 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Sequence.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Sequence.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class SequenceImpl extends TaskTreeNodeImpl implements Sequence 21 { 22 //----------------------------------------------------------------------------------------------- 23 /** 24 * TODO: comment 25 * 26 * @param name 27 */ 28 //----------------------------------------------------------------------------------------------- 29 SequenceImpl() 30 { 31 super("Sequence"); 32 } 17 public class Sequence extends TaskTreeNode implements ISequence { 18 19 /** 20 * TODO: comment 21 * 22 * @param name 23 */ 24 Sequence() { 25 super("Sequence"); 26 } 33 27 34 //----------------------------------------------------------------------------------------------- 35 /** 36 * TODO: comment 37 * 38 * @param name 39 */ 40 //----------------------------------------------------------------------------------------------- 41 SequenceImpl(String name) 42 { 43 super(name); 44 } 28 /** 29 * TODO: comment 30 * 31 * @param name 32 */ 33 Sequence(String name) { 34 super(name); 35 } 45 36 46 //----------------------------------------------------------------------------------------------- 47 /* (non-Javadoc) 48 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 49 */ 50 //----------------------------------------------------------------------------------------------- 51 @Override 52 public SequenceImpl clone() 53 { 54 return (SequenceImpl) super.clone(); 55 } 37 /* 38 * (non-Javadoc) 39 * 40 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 41 */ 42 @Override 43 public Sequence clone() { 44 return (Sequence) super.clone(); 45 } 56 46 57 47 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTree.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTree.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 … … 11 10 import java.util.Map; 12 11 13 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeImpl implements TaskTree 26 { 27 /** the map of nodes */ 28 private Map<TaskTreeNode, NodeInfo> mTaskMap; 29 30 /** the root node of the task tree */ 31 private TaskTreeNode mRootNode; 32 33 //----------------------------------------------------------------------------------------------- 34 /** 35 * TODO: comment 36 * 37 */ 38 //----------------------------------------------------------------------------------------------- 39 TaskTreeImpl(TaskTreeNode rootNode) 40 { 41 mRootNode = rootNode; 42 } 22 public class TaskTree implements ITaskTree { 23 24 /** the map of nodes */ 25 private Map<ITaskTreeNode, ITaskTreeNodeInfo> taskMap; 43 26 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public TaskTreeNode getRoot() 51 { 52 return mRootNode; 53 } 27 /** the root node of the task tree */ 28 private ITaskTreeNode rootNode; 54 29 55 //----------------------------------------------------------------------------------------------- 56 /* (non-Javadoc) 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 58 */ 59 //----------------------------------------------------------------------------------------------- 60 @Override 61 public synchronized Map<TaskTreeNode, NodeInfo> getTaskMap() 62 { 63 if (mTaskMap == null) 64 { 65 mTaskMap = new HashMap<TaskTreeNode, NodeInfo>(); 66 addNodeToMap(mRootNode, null); 30 /** 31 * TODO: comment 32 * 33 */ 34 TaskTree(ITaskTreeNode rootNode) { 35 this.rootNode = rootNode; 67 36 } 68 return mTaskMap;69 }70 37 71 //----------------------------------------------------------------------------------------------- 72 /** 73 * TODO: comment 74 * 75 * @param rootNode 76 */ 77 //----------------------------------------------------------------------------------------------- 78 private void addNodeToMap(TaskTreeNode node, TaskTreeNode parent) 79 { 80 NodeInfoImpl nodeInfo = (NodeInfoImpl) mTaskMap.get(node); 81 82 if (nodeInfo == null) 83 { 84 nodeInfo = new NodeInfoImpl(node); 85 mTaskMap.put(node, nodeInfo); 38 /* 39 * (non-Javadoc) 40 * 41 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 42 */ 43 @Override 44 public ITaskTreeNode getRoot() { 45 return rootNode; 86 46 } 87 88 if (parent != null) 89 { 90 // through first removing an existing parent it is assured, that a parent is recorded 91 // only once. This is needed, because parent may be reused in a tree as well, but we always 92 // iterate the whole tree 93 nodeInfo.removeParent(parent); 94 nodeInfo.addParent(parent); 47 48 /* 49 * (non-Javadoc) 50 * 51 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 52 */ 53 @Override 54 public synchronized Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap() { 55 if (taskMap == null) { 56 taskMap = new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 57 addNodeToMap(rootNode, null); 58 } 59 return taskMap; 95 60 } 96 97 for (TaskTreeNode child : node.getChildren()) 98 { 99 addNodeToMap(child, node); 61 62 /** 63 * TODO: comment 64 * 65 * @param rootNode 66 */ 67 private void addNodeToMap(ITaskTreeNode node, ITaskTreeNode parent) { 68 NodeInfo nodeInfo = (NodeInfo) taskMap.get(node); 69 70 if (nodeInfo == null) { 71 nodeInfo = new NodeInfo(node); 72 taskMap.put(node, nodeInfo); 73 } 74 75 if (parent != null) { 76 // through first removing an existing parent it is assured, that a parent is recorded 77 // only once. This is needed, because parent may be reused in a tree as well, but we 78 // always iterate the whole tree 79 nodeInfo.removeParent(parent); 80 nodeInfo.addParent(parent); 81 } 82 83 for (ITaskTreeNode child : node.getChildren()) { 84 addNodeToMap(child, node); 85 } 100 86 } 101 }102 87 103 //----------------------------------------------------------------------------------------------- 104 /* (non-Javadoc) 105 * @see java.lang.Object#clone() 106 */ 107 //----------------------------------------------------------------------------------------------- 108 @Override 109 public TaskTreeImpl clone() 110 { 111 TaskTreeImpl clone = null; 112 try 113 { 114 clone = (TaskTreeImpl) super.clone(); 115 116 clone.mRootNode = mRootNode.clone(); 117 118 // the clone will create the task map itself, when it is first retrieved 119 clone.mTaskMap = null; 120 88 /* 89 * (non-Javadoc) 90 * 91 * @see java.lang.Object#clone() 92 */ 93 @Override 94 public TaskTree clone() { 95 TaskTree clone = null; 96 try { 97 clone = (TaskTree) super.clone(); 98 99 clone.rootNode = rootNode.clone(); 100 101 // the clone will create the task map itself, when it is first retrieved 102 clone.taskMap = null; 103 104 } 105 catch (CloneNotSupportedException e) { 106 // this should never happen. Therefore simply dump the exception 107 e.printStackTrace(); 108 } 109 110 return clone; 121 111 } 122 catch (CloneNotSupportedException e)123 {124 // this should never happen. Therefore simply dump the exception125 e.printStackTrace();126 }127 128 return clone;129 }130 112 131 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeBuilder.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeBuilderImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;12 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;9 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeBuilderImpl implements TaskTreeBuilder 26 { 27 //-----------------------------------------------------------------------------------------------28 /* (non-Javadoc)29 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode)30 */31 //-----------------------------------------------------------------------------------------------32 @Override33 public void addChild(Sequence parent, TaskTreeNode child)34 {35 if (!(parent instanceof SequenceImpl))36 {37 throw new IllegalArgumentException 38 ("illegal type of task tree node provided: " + parent.getClass());22 public class TaskTreeBuilder implements ITaskTreeBuilder { 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode) 28 */ 29 @Override 30 public void addChild(ISequence parent, ITaskTreeNode child) { 31 if (!(parent instanceof Sequence)) { 32 throw new IllegalArgumentException 33 ("illegal type of task tree node provided: " + parent.getClass()); 34 } 35 36 addChildInternal(parent, -1, child); 39 37 } 40 38 41 addChildInternal(parent, -1, child); 42 } 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 43 */ 44 @Override 45 public void addChild(ISequence parent, int index, ITaskTreeNode child) { 46 if (!(parent instanceof Sequence)) { 47 throw new IllegalArgumentException 48 ("illegal type of task tree node provided: " + parent.getClass()); 49 } 43 50 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public void addChild(Sequence parent, int index, TaskTreeNode child) 51 { 52 if (!(parent instanceof SequenceImpl)) 53 { 54 throw new IllegalArgumentException 55 ("illegal type of task tree node provided: " + parent.getClass()); 51 addChildInternal(parent, index, child); 56 52 } 57 53 58 addChildInternal(parent, index, child); 59 } 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 58 */ 59 @Override 60 public void addChild(ISelection parent, ITaskTreeNode child) { 61 if (!(parent instanceof Selection)) { 62 throw new IllegalArgumentException 63 ("illegal type of task tree node provided: " + parent.getClass()); 64 } 60 65 61 //----------------------------------------------------------------------------------------------- 62 /* (non-Javadoc) 63 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 64 */ 65 //----------------------------------------------------------------------------------------------- 66 @Override 67 public void addChild(Selection parent, TaskTreeNode child) 68 { 69 if (!(parent instanceof SelectionImpl)) 70 { 71 throw new IllegalArgumentException 72 ("illegal type of task tree node provided: " + parent.getClass()); 66 addChildInternal(parent, -1, child); 73 67 } 74 68 75 addChildInternal(parent, -1, child); 76 } 69 /* 70 * (non-Javadoc) 71 * 72 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc. 73 * TextInputEventTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 74 */ 75 @Override 76 public void addChild(ITextInputEventTask parent, ITaskTreeNode child) { 77 if (!(parent instanceof TextInputEventTask)) { 78 throw new IllegalArgumentException 79 ("illegal type of task tree node provided: " + parent.getClass()); 80 } 77 81 78 //----------------------------------------------------------------------------------------------- 79 /* (non-Javadoc) 80 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc.TextInputInteractionTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 81 */ 82 //----------------------------------------------------------------------------------------------- 83 @Override 84 public void addChild(TextInputInteractionTask parent, TaskTreeNode child) 85 { 86 if (!(parent instanceof TextInputInteractionTaskImpl)) 87 { 88 throw new IllegalArgumentException 89 ("illegal type of task tree node provided: " + parent.getClass()); 82 addChildInternal(parent, -1, child); 90 83 } 91 84 92 addChildInternal(parent, -1, child); 93 } 85 /* 86 * (non-Javadoc) 87 * 88 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 89 */ 90 @Override 91 public void setChild(IIteration iteration, ITaskTreeNode newChild) { 92 if (!(iteration instanceof Iteration)) { 93 throw new IllegalArgumentException 94 ("illegal type of iteration provided: " + iteration.getClass()); 95 } 94 96 95 //----------------------------------------------------------------------------------------------- 96 /* (non-Javadoc) 97 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 98 */ 99 //----------------------------------------------------------------------------------------------- 100 @Override 101 public void setChild(Iteration iteration, TaskTreeNode newChild) 102 { 103 if (!(iteration instanceof IterationImpl)) 104 { 105 throw new IllegalArgumentException 106 ("illegal type of iteration provided: " + iteration.getClass()); 97 if (!(newChild instanceof TaskTreeNode)) { 98 throw new IllegalArgumentException 99 ("illegal type of task tree node provided: " + newChild.getClass()); 100 } 101 102 ((Iteration) iteration).setChild(newChild); 107 103 } 108 104 109 if (!(newChild instanceof TaskTreeNodeImpl)) 110 { 111 throw new IllegalArgumentException 112 ("illegal type of task tree node provided: " + newChild.getClass()); 113 } 114 115 ((IterationImpl) iteration).setChild(determineNode(newChild)); 116 } 105 /* 106 * (non-Javadoc) 107 * 108 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 109 */ 110 @Override 111 public void removeChild(ISequence parent, int index) { 112 if (!(parent instanceof TaskTreeNode)) { 113 throw new IllegalArgumentException 114 ("illegal type of task tree node provided: " + parent.getClass()); 115 } 117 116 118 //----------------------------------------------------------------------------------------------- 119 /* (non-Javadoc) 120 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 121 */ 122 //----------------------------------------------------------------------------------------------- 123 @Override 124 public void removeChild(Sequence parent, int index) 125 { 126 if (!(parent instanceof TaskTreeNodeImpl)) 127 { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 117 ((TaskTreeNode) parent).removeChild(index); 130 118 } 131 119 132 ((TaskTreeNodeImpl) parent).removeChild(index); 133 } 120 /* 121 * (non-Javadoc) 122 * 123 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 124 */ 125 @Override 126 public void removeChild(ISelection parent, ITaskTreeNode child) { 127 if (!(parent instanceof TaskTreeNode)) { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 130 } 134 131 135 //----------------------------------------------------------------------------------------------- 136 /* (non-Javadoc) 137 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 138 */ 139 //----------------------------------------------------------------------------------------------- 140 @Override 141 public void removeChild(Selection parent, TaskTreeNode child) 142 { 143 if (!(parent instanceof TaskTreeNodeImpl)) 144 { 145 throw new IllegalArgumentException 146 ("illegal type of task tree node provided: " + parent.getClass()); 132 for (int i = 0; i < parent.getChildren().size(); i++) { 133 if ((parent.getChildren().get(i) == child) || 134 ((parent.getChildren().get(i) != null) && 135 (parent.getChildren().get(i).equals(child)))) 136 { 137 ((TaskTreeNode) parent).removeChild(i); 138 break; 139 } 140 } 147 141 } 148 142 149 for (int i = 0; i < parent.getChildren().size(); i++) 150 { 151 if ((parent.getChildren().get(i) == child) || 152 ((parent.getChildren().get(i) != null) && (parent.getChildren().get(i).equals(child)))) 153 { 154 ((TaskTreeNodeImpl) parent).removeChild(i); 155 break; 156 } 157 } 158 } 143 /* 144 * (non-Javadoc) 145 * 146 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 147 */ 148 @Override 149 public void setDescription(ITaskTreeNode parent, String description) { 150 if (!(parent instanceof TaskTreeNode)) { 151 throw new IllegalArgumentException 152 ("illegal type of task tree node provided: " + parent.getClass()); 153 } 159 154 160 //----------------------------------------------------------------------------------------------- 161 /* (non-Javadoc) 162 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 163 */ 164 //----------------------------------------------------------------------------------------------- 165 @Override 166 public void setDescription(TaskTreeNode parent, String description) 167 { 168 if (!(parent instanceof TaskTreeNodeImpl)) 169 { 170 throw new IllegalArgumentException 171 ("illegal type of task tree node provided: " + parent.getClass()); 155 ((TaskTreeNode) parent).setDescription(description); 172 156 } 173 157 174 ((TaskTreeNodeImpl) parent).setDescription(description); 175 } 176 177 //----------------------------------------------------------------------------------------------- 178 /** 158 /** 179 159 * 180 160 */ 181 //----------------------------------------------------------------------------------------------- 182 private void addChildInternal(TaskTreeNode parent, int index, TaskTreeNode child) 183 { 184 if (!(child instanceof TaskTreeNodeImpl)) 185 { 186 throw new IllegalArgumentException 187 ("illegal type of task tree node provided: " + child.getClass()); 161 private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { 162 if (!(child instanceof TaskTreeNode)) { 163 throw new IllegalArgumentException 164 ("illegal type of task tree node provided: " + child.getClass()); 165 } 166 167 if (index > -1) { 168 ((TaskTreeNode) parent).addChild(index, child); 169 } 170 else { 171 ((TaskTreeNode) parent).addChild(child); 172 } 188 173 } 189 190 if (index > -1)191 {192 ((TaskTreeNodeImpl) parent).addChild(index, determineNode(child));193 }194 else195 {196 ((TaskTreeNodeImpl) parent).addChild(determineNode(child));197 }198 }199 200 //-----------------------------------------------------------------------------------------------201 /**202 * TODO: comment203 *204 * @param newChild205 * @return206 */207 //-----------------------------------------------------------------------------------------------208 private TaskTreeNode determineNode(TaskTreeNode newNode)209 {210 return newNode;211 /*TaskTreeNode node = mTaskMap.get(newNode);212 if (node == null)213 {214 node = newNode;215 mTaskMap.put(node, node);216 }217 218 return node;*/219 }220 174 221 175 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeNode.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TreeNode.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 11:00:46 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; … … 12 10 import java.util.List; 13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 15 16 17 //------------------------------------------------------------------------------------------------- 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 13 18 14 /** 19 15 * TODO comment 20 * 16 * 21 17 * @version $Revision: $ $Date: $ 22 * @author 18 * @author 2011, last modified by $Author: $ 23 19 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeNodeImpl implements TaskTreeNode 26 { 27 /** */ 28 private static int sTemporalId = 0; 29 30 /** */ 31 private String mName; 32 33 /** */ 34 private String mDescription; 35 36 /** */ 37 private int mId; 38 39 /** children */ 40 private List<TaskTreeNode> mChildren; 41 42 //----------------------------------------------------------------------------------------------- 43 /** 44 */ 45 //----------------------------------------------------------------------------------------------- 46 TaskTreeNodeImpl(String name) 47 { 48 mName = name; 49 mId = getNewId(); 50 } 51 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * TODO: comment 55 * 56 * @return 57 */ 58 //----------------------------------------------------------------------------------------------- 59 private static synchronized int getNewId() 60 { 61 if (sTemporalId == Integer.MAX_VALUE) 62 { 63 sTemporalId = 0; 64 } 65 66 return sTemporalId++; 67 } 68 69 //----------------------------------------------------------------------------------------------- 70 /** 71 * @return Returns the name. 72 */ 73 //----------------------------------------------------------------------------------------------- 74 public String getName() 75 { 76 return mName; 77 } 78 79 //----------------------------------------------------------------------------------------------- 80 /* (non-Javadoc) 81 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#getDescription() 82 */ 83 //----------------------------------------------------------------------------------------------- 84 @Override 85 public String getDescription() 86 { 87 return mDescription; 88 } 89 90 //----------------------------------------------------------------------------------------------- 91 /** 92 */ 93 //----------------------------------------------------------------------------------------------- 94 public synchronized List<TaskTreeNode> getChildren() 95 { 96 if ((mChildren == null) || (mChildren.size() == 0)) 97 { 98 return new ArrayList<TaskTreeNode>(); 99 } 100 101 return mChildren.subList(0, mChildren.size()); 102 } 103 104 //----------------------------------------------------------------------------------------------- 105 /* (non-Javadoc) 106 * @see de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 107 */ 108 //----------------------------------------------------------------------------------------------- 109 @Override 110 public boolean equals(TaskTreeNode taskTreeNode) 111 { 112 if (!this.getClass().isInstance(taskTreeNode)) 113 { 114 return false; 115 } 116 117 if (taskTreeNode.hashCode() != hashCode()) 118 { 119 return false; 120 } 121 122 TaskTreeNodeImpl other = (TaskTreeNodeImpl) taskTreeNode; 123 124 if (mId != other.mId) 125 { 126 return false; 127 } 128 129 if (!mName.equals(other.mName)) 130 { 131 return false; 132 } 133 134 synchronized (other) 135 { 136 if (mChildren == null) 137 { 138 return (other.mChildren == null); 139 } 140 else if (other.mChildren == null) 141 { 142 return (mChildren == null); 143 } 144 else if (other.mChildren.size() != mChildren.size()) 145 { 146 return false; 147 } 148 149 for (int i = 0; i < mChildren.size(); i++) 150 { 151 if (!mChildren.get(i).equals(other.mChildren.get(i))) 152 { 153 return false; 154 } 155 } 156 } 157 158 return true; 159 } 160 161 //----------------------------------------------------------------------------------------------- 162 /* (non-Javadoc) 163 * @see java.lang.Object#hashCode() 164 */ 165 //----------------------------------------------------------------------------------------------- 166 @Override 167 public synchronized int hashCode() 168 { 169 return getClass().getSimpleName().hashCode(); 170 } 171 172 //----------------------------------------------------------------------------------------------- 173 /* (non-Javadoc) 174 * @see java.lang.Object#toString() 175 */ 176 //----------------------------------------------------------------------------------------------- 177 @Override 178 public synchronized String toString() 179 { 180 if (mChildren == null) 181 { 182 return mName + "(" + mId + ")"; 183 } 184 else 185 { 186 return mName + "(" + mId + ", " + mChildren.size() + " children)"; 187 } 188 } 189 190 //----------------------------------------------------------------------------------------------- 191 /** 192 * TODO: comment 193 * 194 * @param i 195 * @return 196 */ 197 //----------------------------------------------------------------------------------------------- 198 void setDescription(String description) 199 { 200 mDescription = description; 201 } 202 203 //----------------------------------------------------------------------------------------------- 204 /** 205 */ 206 //----------------------------------------------------------------------------------------------- 207 synchronized void addChild(TaskTreeNode child) 208 { 209 if (mChildren == null) 210 { 211 mChildren = new ArrayList<TaskTreeNode>(); 212 } 213 214 mChildren.add(child); 215 } 216 217 //----------------------------------------------------------------------------------------------- 218 /** 219 */ 220 //----------------------------------------------------------------------------------------------- 221 synchronized void addChild(int index, TaskTreeNode child) 222 { 223 if (mChildren == null) 224 { 225 mChildren = new ArrayList<TaskTreeNode>(); 226 } 227 228 mChildren.add(index, child); 229 } 230 231 //----------------------------------------------------------------------------------------------- 232 /** 233 * TODO: comment 234 * 235 * @param i 236 * @return 237 */ 238 //----------------------------------------------------------------------------------------------- 239 synchronized TaskTreeNode removeChild(int index) 240 { 241 return mChildren.remove(index); 242 } 243 244 //----------------------------------------------------------------------------------------------- 245 /* (non-Javadoc) 246 * @see java.lang.Object#clone() 247 */ 248 //----------------------------------------------------------------------------------------------- 249 @Override 250 public TaskTreeNode clone() 251 { 252 TaskTreeNodeImpl clone = null; 253 try 254 { 255 clone = (TaskTreeNodeImpl) super.clone(); 256 257 if (mChildren != null) 258 { 259 clone.mChildren = new ArrayList<TaskTreeNode>(); 260 261 for (TaskTreeNode child : mChildren) 262 { 263 clone.mChildren.add(child.clone()); 264 } 265 } 266 267 } 268 catch (CloneNotSupportedException e) 269 { 270 // this should never happen. Therefore simply dump the exception 271 e.printStackTrace(); 272 } 273 274 return clone; 275 } 20 public class TaskTreeNode implements ITaskTreeNode { 21 /** */ 22 private static int temporalId = 0; 23 24 /** */ 25 private String name; 26 27 /** */ 28 private String description; 29 30 /** */ 31 private int id; 32 33 /** children */ 34 private List<ITaskTreeNode> children; 35 36 /** 37 * 38 */ 39 public TaskTreeNode(String name) { 40 this.name = name; 41 id = getNewId(); 42 } 43 44 /** 45 * TODO: comment 46 * 47 * @return 48 */ 49 private static synchronized int getNewId() { 50 if (temporalId == Integer.MAX_VALUE) { 51 temporalId = 0; 52 } 53 54 return temporalId++; 55 } 56 57 /** 58 * @return Returns the name. 59 */ 60 public String getName() { 61 return name; 62 } 63 64 /* 65 * (non-Javadoc) 66 * 67 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#getDescription() 68 */ 69 @Override 70 public String getDescription() { 71 return description; 72 } 73 74 /** 75 * 76 */ 77 public synchronized List<ITaskTreeNode> getChildren() { 78 if ((children == null) || (children.size() == 0)) { 79 return new ArrayList<ITaskTreeNode>(); 80 } 81 82 return children.subList(0, children.size()); 83 } 84 85 /* 86 * (non-Javadoc) 87 * 88 * @see de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 89 */ 90 @Override 91 public boolean equals(ITaskTreeNode taskTreeNode) { 92 if (!this.getClass().isInstance(taskTreeNode)) { 93 return false; 94 } 95 96 if (taskTreeNode.hashCode() != hashCode()) { 97 return false; 98 } 99 100 TaskTreeNode other = (TaskTreeNode) taskTreeNode; 101 102 if (id != other.id) { 103 return false; 104 } 105 106 if (!name.equals(other.name)) { 107 return false; 108 } 109 110 synchronized (other) { 111 if (children == null) { 112 return (other.children == null); 113 } 114 else if (other.children == null) { 115 return (children == null); 116 } 117 else if (other.children.size() != children.size()) { 118 return false; 119 } 120 121 for (int i = 0; i < children.size(); i++) { 122 if (!children.get(i).equals(other.children.get(i))) { 123 return false; 124 } 125 } 126 } 127 128 return true; 129 } 130 131 /* 132 * (non-Javadoc) 133 * 134 * @see java.lang.Object#hashCode() 135 */ 136 @Override 137 public synchronized int hashCode() { 138 return getClass().getSimpleName().hashCode(); 139 } 140 141 /* 142 * (non-Javadoc) 143 * 144 * @see java.lang.Object#toString() 145 */ 146 @Override 147 public synchronized String toString() { 148 if (children == null) { 149 return name + "(" + id + ")"; 150 } 151 else { 152 return name + "(" + id + ", " + children.size() + " children)"; 153 } 154 } 155 156 /** 157 * TODO: comment 158 * 159 * @param i 160 * @return 161 */ 162 void setDescription(String description) { 163 this.description = description; 164 } 165 166 /** 167 * 168 */ 169 synchronized void addChild(ITaskTreeNode child) { 170 if (children == null) { 171 children = new ArrayList<ITaskTreeNode>(); 172 } 173 174 children.add(child); 175 } 176 177 /** 178 * 179 */ 180 synchronized void addChild(int index, ITaskTreeNode child) { 181 if (children == null) { 182 children = new ArrayList<ITaskTreeNode>(); 183 } 184 185 children.add(index, child); 186 } 187 188 /** 189 * TODO: comment 190 * 191 * @param i 192 * @return 193 */ 194 synchronized ITaskTreeNode removeChild(int index) { 195 return children.remove(index); 196 } 197 198 /* 199 * (non-Javadoc) 200 * 201 * @see java.lang.Object#clone() 202 */ 203 @Override 204 public ITaskTreeNode clone() { 205 TaskTreeNode clone = null; 206 try { 207 clone = (TaskTreeNode) super.clone(); 208 209 if (children != null) { 210 clone.children = new ArrayList<ITaskTreeNode>(); 211 212 for (ITaskTreeNode child : children) { 213 clone.children.add(child.clone()); 214 } 215 } 216 217 } 218 catch (CloneNotSupportedException e) { 219 // this should never happen. Therefore simply dump the exception 220 e.printStackTrace(); 221 } 222 223 return clone; 224 } 276 225 277 226 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeNodeFactory.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeNodeFactoryImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;12 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;13 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;14 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;15 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;16 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;19 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;10 import de.ugoe.cs.quest.eventcore.IEventTarget; 11 import de.ugoe.cs.quest.eventcore.IEventType; 12 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 13 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 20 20 21 //-------------------------------------------------------------------------------------------------22 21 /** 23 22 * TODO comment … … 26 25 * @author 2012, last modified by $Author: patrick$ 27 26 */ 28 //------------------------------------------------------------------------------------------------- 29 public class TaskTreeNodeFactoryImpl implements TaskTreeNodeFactory 30 { 27 public class TaskTreeNodeFactory implements ITaskTreeNodeFactory { 31 28 32 //----------------------------------------------------------------------------------------------- 33 /* (non-Javadoc) 34 * @see TaskTreeNodeFactory#createNewInteractionTask(GUIElement, Interaction) 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Override 38 public InteractionTask createNewInteractionTask(GUIElement guiElement, 39 Interaction interaction) 40 { 41 return new InteractionTaskImpl(guiElement, interaction); 42 } 29 /* 30 * (non-Javadoc) 31 * 32 * @see TaskTreeNodeFactory#createNewEventTask(IEventType, IEventTarget) 33 */ 34 @Override 35 public IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget) { 36 return new EventTask(eventType, eventTarget); 37 } 43 38 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSequence() 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public Sequence createNewSequence() 51 { 52 return new SequenceImpl(); 53 } 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSequence() 43 */ 44 @Override 45 public ISequence createNewSequence() { 46 return new Sequence(); 47 } 54 48 55 //----------------------------------------------------------------------------------------------- 56 /* (non-Javadoc) 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewTextInputInteractionTask() 58 */ 59 //----------------------------------------------------------------------------------------------- 60 @Override 61 public TextInputInteractionTask createNewTextInputInteractionTask(GUIElement guiElement) 62 { 63 return new TextInputInteractionTaskImpl(guiElement); 64 } 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewTextInputEventTask(eventTarget) 53 */ 54 @Override 55 public ITextInputEventTask createNewTextInputEventTask(IEventTarget eventTarget) { 56 return new TextInputEventTask(eventTarget); 57 } 65 58 66 //----------------------------------------------------------------------------------------------- 67 /* (non-Javadoc) 68 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewIteration() 69 */ 70 //----------------------------------------------------------------------------------------------- 71 @Override 72 public Iteration createNewIteration() 73 { 74 return new IterationImpl(); 75 } 59 /* 60 * (non-Javadoc) 61 * 62 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewIteration() 63 */ 64 @Override 65 public IIteration createNewIteration() { 66 return new Iteration(); 67 } 76 68 77 //----------------------------------------------------------------------------------------------- 78 /* (non-Javadoc) 79 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSelection() 80 */ 81 //----------------------------------------------------------------------------------------------- 82 @Override 83 public Selection createNewSelection() 84 { 85 return new SelectionImpl(); 86 } 69 /* 70 * (non-Javadoc) 71 * 72 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSelection() 73 */ 74 @Override 75 public ISelection createNewSelection() { 76 return new Selection(); 77 } 87 78 88 //----------------------------------------------------------------------------------------------- 89 /* (non-Javadoc) 90 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createTaskTree(de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 91 */ 92 //----------------------------------------------------------------------------------------------- 93 @Override 94 public TaskTree createTaskTree(TaskTreeNode root) 95 { 96 return new TaskTreeImpl(root); 97 } 79 /* 80 * (non-Javadoc) 81 * 82 * @see 83 * de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createTaskTree(de.ugoe.cs.tasktree.treeifc 84 * .TaskTreeNode) 85 */ 86 @Override 87 public ITaskTree createTaskTree(ITaskTreeNode root) { 88 return new TaskTree(root); 89 } 98 90 99 91 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TextInputEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TextInputSequenceImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 10.06.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.TextInput;12 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.gui.TextInput; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 14 * TODO comment … … 19 17 * @author 2012, last modified by $Author: patrick$ 20 18 */ 21 //------------------------------------------------------------------------------------------------- 22 public class TextInputInteractionTaskImpl extends InteractionTaskImpl 23 implements TextInputInteractionTask 24 { 19 public class TextInputEventTask extends EventTask implements ITextInputEventTask { 25 20 26 /** the text, that was finally entered in this sequence without all backspaces, etc. */ 27 private String mEnteredText; 28 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * TODO: comment 32 * 33 * @param name 34 */ 35 //----------------------------------------------------------------------------------------------- 36 TextInputInteractionTaskImpl(GUIElement guiElement) 37 { 38 super(guiElement, new TextInput()); 39 } 21 /** the text, that was finally entered in this sequence without all backspaces, etc. */ 22 private String enteredText; 40 23 41 //----------------------------------------------------------------------------------------------- 42 /* (non-Javadoc) 43 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 44 */ 45 //----------------------------------------------------------------------------------------------- 46 @Override 47 public TextInputInteractionTaskImpl clone() 48 { 49 // entered text is unchangeable and does not need to be cloned 50 return (TextInputInteractionTaskImpl) super.clone(); 51 } 24 /** 25 * TODO: comment 26 * 27 * @param name 28 */ 29 TextInputEventTask(IEventTarget eventTarget) { 30 super(new TextInput(), eventTarget); 31 } 52 32 53 //-----------------------------------------------------------------------------------------------54 /* (non-Javadoc)55 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#getEnteredText()56 */57 //-----------------------------------------------------------------------------------------------58 @Override59 public String getEnteredText()60 {61 return mEnteredText;62 }33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 37 */ 38 @Override 39 public TextInputEventTask clone() { 40 // entered text is unchangeable and does not need to be cloned 41 return (TextInputEventTask) super.clone(); 42 } 63 43 64 //----------------------------------------------------------------------------------------------- 65 /* (non-Javadoc) 66 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#setEnteredText(java.lang.String) 67 */ 68 //----------------------------------------------------------------------------------------------- 69 @Override 70 public void setEnteredText(String text) 71 { 72 mEnteredText = text; 73 } 44 /* 45 * (non-Javadoc) 46 * 47 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#getEnteredText() 48 */ 49 @Override 50 public String getEnteredText() { 51 return enteredText; 52 } 74 53 75 //----------------------------------------------------------------------------------------------- 76 /* (non-Javadoc) 77 * @see java.lang.Object#toString() 78 */ 79 //----------------------------------------------------------------------------------------------- 80 @Override 81 public synchronized String toString() 82 { 83 if (super.getChildren() == null) 84 { 85 return super.getName(); 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#setEnteredText(java.lang.String) 58 */ 59 @Override 60 public void setEnteredText(String text) { 61 enteredText = text; 86 62 } 87 else 88 { 89 return "TextInputInteraction(\"" + mEnteredText + "\", " + super.getChildren().size() + 90 " children)"; 63 64 /* 65 * (non-Javadoc) 66 * 67 * @see java.lang.Object#toString() 68 */ 69 @Override 70 public synchronized String toString() { 71 if (super.getChildren() == null) { 72 return super.getName(); 73 } 74 else { 75 return 76 "TextInputInteraction(\"" + enteredText + "\", " + super.getChildren().size() + 77 " children)"; 78 } 91 79 } 92 } 93 80 94 81 }
Note: See TracChangeset
for help on using the changeset viewer.