aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar nagilooh <ficsorattila96@gmail.com>2023-08-25 13:09:30 +0200
committerLibravatar nagilooh <ficsorattila96@gmail.com>2023-08-25 13:09:30 +0200
commit96a6ea2aabe8f04915daf2a680683352148c2fa3 (patch)
tree3386b7760fa3c91fe4820c4865ff2aa670093621
parentAdd new transformation rule actions (diff)
downloadrefinery-96a6ea2aabe8f04915daf2a680683352148c2fa3.tar.gz
refinery-96a6ea2aabe8f04915daf2a680683352148c2fa3.tar.zst
refinery-96a6ea2aabe8f04915daf2a680683352148c2fa3.zip
Add delete action and additional tests for equals
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java14
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java19
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java17
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java12
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java17
-rw-r--r--subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java246
6 files changed, 316 insertions, 9 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java
index 181a5020..7598de0a 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java
@@ -6,7 +6,7 @@ import tools.refinery.store.tuple.Tuple;
6public class ActivationSymbol extends ActionSymbol { 6public class ActivationSymbol extends ActionSymbol {
7 7
8 private final int index; 8 private final int index;
9 private Tuple value = null; 9 private Tuple value;
10 10
11 public ActivationSymbol() { 11 public ActivationSymbol() {
12 this(0); 12 this(0);
@@ -36,16 +36,24 @@ public class ActivationSymbol extends ActionSymbol {
36 if (obj == this) { 36 if (obj == this) {
37 return true; 37 return true;
38 } 38 }
39 if (!(obj instanceof ActivationSymbol)) { 39 if (!(obj instanceof ActivationSymbol other)) {
40 return false; 40 return false;
41 } 41 }
42 return index == ((ActivationSymbol) obj).index; 42
43 if (index != other.index) {
44 return false;
45 }
46 if (value == null) {
47 return other.value == null;
48 }
49 return value.equals(other.value);
43 } 50 }
44 51
45 @Override 52 @Override
46 public int hashCode() { 53 public int hashCode() {
47 int result = 17; 54 int result = 17;
48 result = 31 * result + Integer.hashCode(index); 55 result = 31 * result + Integer.hashCode(index);
56 result = 31 * result + value.hashCode();
49 return result; 57 return result;
50 } 58 }
51} 59}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java
index 589a33c4..c7cc4600 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java
@@ -18,10 +18,27 @@ public class DeleteAction implements AtomicAction {
18 dseAdapter.deleteObject(symbol.getValue(activation)); 18 dseAdapter.deleteObject(symbol.getValue(activation));
19 } 19 }
20 20
21
22 @Override 21 @Override
23 public DeleteAction prepare(Model model) { 22 public DeleteAction prepare(Model model) {
24 dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); 23 dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class);
25 return this; 24 return this;
26 } 25 }
26
27 @Override
28 public boolean equals(Object obj) {
29 if (obj == this) {
30 return true;
31 }
32 if (!(obj instanceof DeleteAction other)) {
33 return false;
34 }
35 return this.symbol.getClass() == other.symbol.getClass();
36 }
37
38 @Override
39 public int hashCode() {
40 int result = 17;
41 result = 31 * result + symbol.getClass().hashCode();
42 return result;
43 }
27} 44}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java
index 5c02bd45..7adab93b 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java
@@ -51,13 +51,26 @@ public class InsertAction<T> implements AtomicAction {
51 if (!interpretation.equals(other.interpretation)) { 51 if (!interpretation.equals(other.interpretation)) {
52 return false; 52 return false;
53 } 53 }
54 return value.equals(other.value); 54 if (value == null) {
55 if (other.value != null) {
56 return false;
57 }
58 }
59 else if (!value.equals(other.value)) {
60 return false;
61 }
62 for (var i = 0; i < symbols.length; i++) {
63 if (!symbols[i].equals(other.symbols[i])) {
64 return false;
65 }
66 }
67 return true;
55 } 68 }
56 69
57 @Override 70 @Override
58 public int hashCode() { 71 public int hashCode() {
59 int result = 17; 72 int result = 17;
60 result = 31 * result + Integer.hashCode(symbols.length); 73 result = 31 * result + Arrays.hashCode(symbols);
61 result = 31 * result + interpretation.hashCode(); 74 result = 31 * result + interpretation.hashCode();
62 result = 31 * result + value.hashCode(); 75 result = 31 * result + value.hashCode();
63 return result; 76 return result;
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java
index 3c69b9a0..acdc3cae 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java
@@ -30,11 +30,19 @@ public class NewItemSymbol extends ActionSymbol {
30 if (obj == this) { 30 if (obj == this) {
31 return true; 31 return true;
32 } 32 }
33 return obj instanceof NewItemSymbol; 33 if (!(obj instanceof NewItemSymbol other)) {
34 return false;
35 }
36 if (value == null) {
37 return other.value == null;
38 }
39 return value.equals(other.value);
34 } 40 }
35 41
36 @Override 42 @Override
37 public int hashCode() { 43 public int hashCode() {
38 return 42; 44 int result = 17;
45 result = 31 * result + value.hashCode();
46 return result;
39 } 47 }
40} 48}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
index 2e58a8c4..19ab4575 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
@@ -9,6 +9,7 @@ import java.util.*;
9public class TransformationAction { 9public class TransformationAction {
10 private final List<ActionSymbol> actionSymbols = new ArrayList<>(); 10 private final List<ActionSymbol> actionSymbols = new ArrayList<>();
11 private final List<InsertAction<?>> insertActions = new ArrayList<>(); 11 private final List<InsertAction<?>> insertActions = new ArrayList<>();
12 private final List<DeleteAction> deleteActions = new ArrayList<>();
12 private boolean configured = false; 13 private boolean configured = false;
13 private final Map<Integer, List<Tuple2>> activationSymbolUsageMap = new LinkedHashMap<>(); 14 private final Map<Integer, List<Tuple2>> activationSymbolUsageMap = new LinkedHashMap<>();
14 15
@@ -24,6 +25,12 @@ public class TransformationAction {
24 return this; 25 return this;
25 } 26 }
26 27
28 public TransformationAction add(DeleteAction action) {
29 checkConfigured();
30 deleteActions.add(action);
31 return this;
32 }
33
27 private void checkConfigured() { 34 private void checkConfigured() {
28 if (configured) { 35 if (configured) {
29 throw new IllegalStateException("Action already configured."); 36 throw new IllegalStateException("Action already configured.");
@@ -37,6 +44,9 @@ public class TransformationAction {
37 for (InsertAction<?> action : insertActions) { 44 for (InsertAction<?> action : insertActions) {
38 action.prepare(model); 45 action.prepare(model);
39 } 46 }
47 for (DeleteAction action : deleteActions) {
48 action.prepare(model);
49 }
40 50
41 for (var insertAction : insertActions) { 51 for (var insertAction : insertActions) {
42 var actionIndex = insertActions.indexOf(insertAction); 52 var actionIndex = insertActions.indexOf(insertAction);
@@ -59,6 +69,9 @@ public class TransformationAction {
59 for (InsertAction<?> action : insertActions) { 69 for (InsertAction<?> action : insertActions) {
60 action.fire(activation); 70 action.fire(activation);
61 } 71 }
72 for (DeleteAction action : deleteActions) {
73 action.fire(activation);
74 }
62 return true; 75 return true;
63 } 76 }
64 77
@@ -79,6 +92,9 @@ public class TransformationAction {
79 if (!insertActions.equals(other.insertActions)) { 92 if (!insertActions.equals(other.insertActions)) {
80 return false; 93 return false;
81 } 94 }
95 if (!deleteActions.equals(other.deleteActions)) {
96 return false;
97 }
82 return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap); 98 return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap);
83 99
84 } 100 }
@@ -88,6 +104,7 @@ public class TransformationAction {
88 var result = 17; 104 var result = 17;
89 result = 31 * result + actionSymbols.hashCode(); 105 result = 31 * result + actionSymbols.hashCode();
90 result = 31 * result + insertActions.hashCode(); 106 result = 31 * result + insertActions.hashCode();
107 result = 31 * result + deleteActions.hashCode();
91 return result; 108 return result;
92 } 109 }
93} 110}
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java
index d54bc7d3..e29260e9 100644
--- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java
+++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java
@@ -124,7 +124,8 @@ public class ActionEqualsTest {
124 void actionSymbolGlobalOrderTest() { 124 void actionSymbolGlobalOrderTest() {
125 var newItemSymbol1 = new NewItemSymbol(); 125 var newItemSymbol1 = new NewItemSymbol();
126 var activationSymbol1 = new ActivationSymbol(); 126 var activationSymbol1 = new ActivationSymbol();
127 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); 127 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
128 activationSymbol1);
128 129
129 var action1 = new TransformationAction(); 130 var action1 = new TransformationAction();
130 action1.add(newItemSymbol1); 131 action1.add(newItemSymbol1);
@@ -388,4 +389,247 @@ public class ActionEqualsTest {
388 389
389 assertNotEquals(action1, action2); 390 assertNotEquals(action1, action2);
390 } 391 }
392
393 @Test
394 void deleteActionTest() {
395 var newItemSymbol = new NewItemSymbol();
396 var activationSymbol = new ActivationSymbol(0);
397 var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol,
398 activationSymbol);
399 var deleteAction = new DeleteAction(activationSymbol);
400
401 var action1 = new TransformationAction();
402 action1.add(newItemSymbol);
403 action1.add(activationSymbol);
404 action1.add(insertAction);
405 action1.add(deleteAction);
406 action1.prepare(model);
407
408 var action2 = new TransformationAction();
409 action2.add(newItemSymbol);
410 action2.add(activationSymbol);
411 action2.add(insertAction);
412 action2.add(deleteAction);
413 action2.prepare(model);
414
415 assertEquals(action1, action2);
416 }
417
418 @Test
419 void deleteActionMissingTest() {
420 var newItemSymbol = new NewItemSymbol();
421 var activationSymbol = new ActivationSymbol(0);
422 var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol,
423 activationSymbol);
424 var deleteAction = new DeleteAction(activationSymbol);
425
426 var action1 = new TransformationAction();
427 action1.add(newItemSymbol);
428 action1.add(activationSymbol);
429 action1.add(insertAction);
430 action1.add(deleteAction);
431 action1.prepare(model);
432
433 var action2 = new TransformationAction();
434 action2.add(newItemSymbol);
435 action2.add(activationSymbol);
436 action2.add(insertAction);
437 action2.prepare(model);
438
439 assertNotEquals(action1, action2);
440 }
441
442 @Test
443 void deleteActionIdenticalTest() {
444 var newItemSymbol = new NewItemSymbol();
445 var activationSymbol = new ActivationSymbol(0);
446 var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol,
447 activationSymbol);
448 var deleteAction1 = new DeleteAction(activationSymbol);
449 var deleteAction2 = new DeleteAction(activationSymbol);
450
451 var action1 = new TransformationAction();
452 action1.add(newItemSymbol);
453 action1.add(activationSymbol);
454 action1.add(insertAction);
455 action1.add(deleteAction1);
456 action1.prepare(model);
457
458 var action2 = new TransformationAction();
459 action2.add(newItemSymbol);
460 action2.add(activationSymbol);
461 action2.add(insertAction);
462 action2.add(deleteAction2);
463 action2.prepare(model);
464
465 assertEquals(action1, action2);
466 }
467
468 @Test
469 void deleteActionSymbolTypeTest() {
470 var newItemSymbol = new NewItemSymbol();
471 var activationSymbol = new ActivationSymbol(0);
472 var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol,
473 activationSymbol);
474 var deleteAction1 = new DeleteAction(activationSymbol);
475 var deleteAction2 = new DeleteAction(newItemSymbol);
476
477 var action1 = new TransformationAction();
478 action1.add(newItemSymbol);
479 action1.add(activationSymbol);
480 action1.add(insertAction);
481 action1.add(deleteAction1);
482 action1.prepare(model);
483
484 var action2 = new TransformationAction();
485 action2.add(newItemSymbol);
486 action2.add(activationSymbol);
487 action2.add(insertAction);
488 action2.add(deleteAction2);
489 action2.prepare(model);
490
491 assertNotEquals(action1, action2);
492 }
493
494 @Test
495 void deleteActionOrderTest() {
496 var newItemSymbol = new NewItemSymbol();
497 var activationSymbol = new ActivationSymbol(0);
498 var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol,
499 activationSymbol);
500 var deleteAction1 = new DeleteAction(activationSymbol);
501 var deleteAction2 = new DeleteAction(newItemSymbol);
502
503 var action1 = new TransformationAction();
504 action1.add(newItemSymbol);
505 action1.add(activationSymbol);
506 action1.add(insertAction);
507 action1.add(deleteAction1);
508 action1.add(deleteAction2);
509 action1.prepare(model);
510
511 var action2 = new TransformationAction();
512 action2.add(newItemSymbol);
513 action2.add(activationSymbol);
514 action2.add(insertAction);
515 action2.add(deleteAction2);
516 action2.add(deleteAction1);
517 action2.prepare(model);
518
519 assertNotEquals(action1, action2);
520 }
521
522 @Test
523 void actionsMixedOrderTest() {
524 var newItemSymbol1 = new NewItemSymbol();
525 var activationSymbol1 = new ActivationSymbol();
526 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
527 activationSymbol1);
528 var deleteAction1 = new DeleteAction(newItemSymbol1);
529
530 var newItemSymbol2 = new NewItemSymbol();
531 var activationSymbol2 = new ActivationSymbol();
532 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
533 activationSymbol2);
534 var deleteAction2 = new DeleteAction(activationSymbol2);
535
536 var action1 = new TransformationAction();
537 action1.add(newItemSymbol1);
538 action1.add(newItemSymbol2);
539 action1.add(activationSymbol1);
540 action1.add(activationSymbol2);
541 action1.add(insertAction1);
542 action1.add(insertAction2);
543 action1.add(deleteAction1);
544 action1.add(deleteAction2);
545 action1.prepare(model);
546
547 var action2 = new TransformationAction();
548 action2.add(deleteAction1);
549 action2.add(newItemSymbol1);
550 action2.add(insertAction1);
551 action2.add(newItemSymbol2);
552 action2.add(deleteAction2);
553 action2.add(activationSymbol1);
554 action2.add(insertAction2);
555 action2.add(activationSymbol2);
556 action2.prepare(model);
557
558 assertEquals(action1, action2);
559 }
560
561 @Test
562 void twoUnpreparedActionsTest() {
563 var newItemSymbol1 = new NewItemSymbol();
564 var activationSymbol1 = new ActivationSymbol();
565 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
566 activationSymbol1);
567 var deleteAction1 = new DeleteAction(newItemSymbol1);
568
569 var newItemSymbol2 = new NewItemSymbol();
570 var activationSymbol2 = new ActivationSymbol();
571 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
572 activationSymbol2);
573 var deleteAction2 = new DeleteAction(activationSymbol2);
574
575 var action1 = new TransformationAction();
576 action1.add(newItemSymbol1);
577 action1.add(newItemSymbol2);
578 action1.add(activationSymbol1);
579 action1.add(activationSymbol2);
580 action1.add(insertAction1);
581 action1.add(insertAction2);
582 action1.add(deleteAction1);
583 action1.add(deleteAction2);
584
585 var action2 = new TransformationAction();
586 action2.add(deleteAction1);
587 action2.add(newItemSymbol1);
588 action2.add(insertAction1);
589 action2.add(newItemSymbol2);
590 action2.add(deleteAction2);
591 action2.add(activationSymbol1);
592 action2.add(insertAction2);
593 action2.add(activationSymbol2);
594
595 assertEquals(action1, action2);
596 }
597
598 @Test
599 void oneUnpreparedActionTest() {
600 var newItemSymbol1 = new NewItemSymbol();
601 var activationSymbol1 = new ActivationSymbol();
602 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
603 activationSymbol1);
604 var deleteAction1 = new DeleteAction(newItemSymbol1);
605
606 var newItemSymbol2 = new NewItemSymbol();
607 var activationSymbol2 = new ActivationSymbol();
608 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
609 activationSymbol2);
610 var deleteAction2 = new DeleteAction(activationSymbol2);
611
612 var action1 = new TransformationAction();
613 action1.add(newItemSymbol1);
614 action1.add(newItemSymbol2);
615 action1.add(activationSymbol1);
616 action1.add(activationSymbol2);
617 action1.add(insertAction1);
618 action1.add(insertAction2);
619 action1.add(deleteAction1);
620 action1.add(deleteAction2);
621 action1.prepare(model);
622
623 var action2 = new TransformationAction();
624 action2.add(deleteAction1);
625 action2.add(newItemSymbol1);
626 action2.add(insertAction1);
627 action2.add(newItemSymbol2);
628 action2.add(deleteAction2);
629 action2.add(activationSymbol1);
630 action2.add(insertAction2);
631 action2.add(activationSymbol2);
632
633 assertNotEquals(action1, action2);
634 }
391} 635}