aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java')
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java76
1 files changed, 45 insertions, 31 deletions
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 19ab4575..50387f53 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
@@ -7,15 +7,15 @@ import tools.refinery.store.tuple.Tuple2;
7import java.util.*; 7import java.util.*;
8 8
9public class TransformationAction { 9public class TransformationAction {
10 private final List<ActionSymbol> actionSymbols = new ArrayList<>(); 10 private final List<ActionVariable> actionVariables = 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 final List<DeleteAction> deleteActions = new ArrayList<>();
13 private boolean configured = false; 13 private boolean configured = false;
14 private final Map<Integer, List<Tuple2>> activationSymbolUsageMap = new LinkedHashMap<>(); 14 private final Map<Integer, List<Tuple2>> actionVariableUsageMap = new LinkedHashMap<>();
15 15
16 public TransformationAction add(ActionSymbol action) { 16 public TransformationAction add(ActionVariable action) {
17 checkConfigured(); 17 checkConfigured();
18 actionSymbols.add(action); 18 actionVariables.add(action);
19 return this; 19 return this;
20 } 20 }
21 21
@@ -38,7 +38,7 @@ public class TransformationAction {
38 } 38 }
39 39
40 public TransformationAction prepare(Model model) { 40 public TransformationAction prepare(Model model) {
41 for (ActionSymbol action : actionSymbols) { 41 for (ActionVariable action : actionVariables) {
42 action.prepare(model); 42 action.prepare(model);
43 } 43 }
44 for (InsertAction<?> action : insertActions) { 44 for (InsertAction<?> action : insertActions) {
@@ -50,11 +50,11 @@ public class TransformationAction {
50 50
51 for (var insertAction : insertActions) { 51 for (var insertAction : insertActions) {
52 var actionIndex = insertActions.indexOf(insertAction); 52 var actionIndex = insertActions.indexOf(insertAction);
53 var symbols = insertAction.getSymbols(); 53 var variables = insertAction.getVariables();
54 for (var i = 0; i < symbols.length; i++) { 54 for (var i = 0; i < variables.length; i++) {
55 var symbolGlobalIndex = actionSymbols.indexOf(symbols[i]); 55 var variablelGlobalIndex = actionVariables.indexOf(variables[i]);
56 activationSymbolUsageMap.computeIfAbsent(symbolGlobalIndex, k -> new ArrayList<>()); 56 actionVariableUsageMap.computeIfAbsent(variablelGlobalIndex, k -> new ArrayList<>());
57 activationSymbolUsageMap.get(symbolGlobalIndex).add(Tuple.of(actionIndex, i)); 57 actionVariableUsageMap.get(variablelGlobalIndex).add(Tuple.of(actionIndex, i));
58 } 58 }
59 } 59 }
60 60
@@ -63,7 +63,7 @@ public class TransformationAction {
63 } 63 }
64 64
65 public boolean fire(Tuple activation) { 65 public boolean fire(Tuple activation) {
66 for (ActionSymbol action : actionSymbols) { 66 for (ActionVariable action : actionVariables) {
67 action.fire(activation); 67 action.fire(activation);
68 } 68 }
69 for (InsertAction<?> action : insertActions) { 69 for (InsertAction<?> action : insertActions) {
@@ -75,36 +75,50 @@ public class TransformationAction {
75 return true; 75 return true;
76 } 76 }
77 77
78 // True if Symbols and InsertActions are inserted in same order, ActivationSymbols are equal (they have the same 78 // Returns true if ActionVariables and InsertActions are inserted in same order, ActionVariables are equal (they
79 // index for getting the value from the activation Tuple) and InsertActions are equal (they have the same arity 79 // have the same index for getting the value from the activation Tuple) and InsertActions are equal (they have
80 // and value to be set). 80 // the same arity and value to be set).
81 @Override 81 public boolean equalsWithSubstitution(TransformationAction other) {
82 public boolean equals(Object obj) { 82 if (other == this) {
83 if (obj == this) {
84 return true; 83 return true;
85 } 84 }
86 if (!(obj instanceof TransformationAction other)) { 85
86 if (actionVariables.size() != other.actionVariables.size()) {
87 return false; 87 return false;
88 } 88 }
89 if (!actionSymbols.equals(other.actionSymbols)) { 89
90 if (insertActions.size() != other.insertActions.size()) {
90 return false; 91 return false;
91 } 92 }
92 if (!insertActions.equals(other.insertActions)) { 93
94 if (deleteActions.size() != other.deleteActions.size()) {
93 return false; 95 return false;
94 } 96 }
95 if (!deleteActions.equals(other.deleteActions)) { 97
96 return false; 98 for (var i = 0; i < actionVariables.size(); i++) {
99 var variable = actionVariables.get(i);
100 var otherVariable = other.actionVariables.get(i);
101 if (!variable.equalsWithSubstitution(otherVariable)) {
102 return false;
103 }
97 } 104 }
98 return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap);
99 105
100 } 106 for (var i = 0; i < insertActions.size(); i++) {
107 var insertAction = insertActions.get(i);
108 var otherInsertAction = other.insertActions.get(i);
109 if (!insertAction.equalsWithSubstitution(otherInsertAction)) {
110 return false;
111 }
112 }
113
114 for (var i = 0; i < deleteActions.size(); i++) {
115 var deleteAction = deleteActions.get(i);
116 var otherDeleteAction = other.deleteActions.get(i);
117 if (!deleteAction.equalsWithSubstitution(otherDeleteAction)) {
118 return false;
119 }
120 }
121 return this.actionVariableUsageMap.equals(other.actionVariableUsageMap);
101 122
102 @Override
103 public int hashCode() {
104 var result = 17;
105 result = 31 * result + actionSymbols.hashCode();
106 result = 31 * result + insertActions.hashCode();
107 result = 31 * result + deleteActions.hashCode();
108 return result;
109 } 123 }
110} 124}