Remove usage of the cartography. The state machine configuration usage
is completely done using recursive algorithms.
Change-Id: I09a3dcc76a5ba83ea5ea21cbf88744ee01de3ad5
Signed-off-by: jeremie.tatibouet <jeremie.tatibouet@cea.fr>
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateConfiguration.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateConfiguration.java
index bedd620..2145f07 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateConfiguration.java
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateConfiguration.java
@@ -34,4 +34,8 @@
public boolean add(IVertexActivation activation, List<IVertexActivation> context);
public boolean remove(IVertexActivation activation, List<IVertexActivation> context);
+
+ public boolean isConfigurationFor(IVertexActivation activation);
+
+ public boolean isConfigurationFor(IVertexActivation activation, List<IVertexActivation> context);
}
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateMachineConfiguration.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateMachineConfiguration.java
index 539a52f..bb597c2 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateMachineConfiguration.java
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines.interfaces/src/org/eclipse/papyrus/moka/fuml/statemachines/interfaces/Semantics/StateMachines/IStateMachineConfiguration.java
@@ -23,8 +23,4 @@
public IStateConfiguration getRoot();
- public void addToCartography(IStateConfiguration configuration);
-
- public void deleteFromCartography(IStateConfiguration configuration);
-
}
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateConfiguration.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateConfiguration.java
index 0518cca..b09b74f 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateConfiguration.java
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateConfiguration.java
@@ -38,7 +38,7 @@
// A reference to the complete state-machine configuration
private IStateMachineConfiguration completeConfiguration;
- public StateConfiguration(StateMachineConfiguration configuration){
+ public StateConfiguration(IStateMachineConfiguration configuration){
this.level = 0;
this.vertexActivation = null;
this.children = new ArrayList<IStateConfiguration>();
@@ -71,17 +71,72 @@
this.parent = configuration;
}
+ public boolean removeChild(IVertexActivation activation){
+ // Remove a vertex activation from the state machine configuration tree.
+ return this.remove(activation, this.getContext(activation));
+ }
+
+ public boolean addChild(IVertexActivation activation){
+ // Add a vertex activation in the state machine configuration tree.
+ return this.add(activation, this.getContext(activation));
+ }
+
+ public boolean isConfigurationFor(IVertexActivation activation){
+ // Check if the given vertex activation belongs to the
+ // state machine configuration.
+ return this.isConfigurationFor(activation, this.getContext(activation));
+ }
+
+ public boolean isConfigurationFor(IVertexActivation activation, List<IVertexActivation> context){
+ // A vertex activation belongs to the state machine configuration if it is referenced
+ // in the state configuration tree. True is returned if a state configuration
+ // in that tree references the vertex activation, false otherwise. In order to find the
+ // state configuration referencing the activation, a directed search is performed in the
+ // state configuration tree. This directed search relies on the path (ascending hierarchy
+ // of vertex activation) provided by the context.
+ boolean isConfiguration = false;
+ if(!context.isEmpty()){
+ int i = 0;
+ IStateConfiguration selectedStateConfiguration = null;
+ IVertexActivation current = context.get(context.size()-1);
+ while(selectedStateConfiguration == null && i < this.children.size()){
+ if(this.children.get(i).getVertexActivation() == current){
+ selectedStateConfiguration = this.children.get(i);
+ }
+ i++;
+ }
+ if(selectedStateConfiguration != null){
+ isConfiguration = selectedStateConfiguration.isConfigurationFor(activation, context.subList(0, context.size()-1));
+ }
+ }else{
+ int i = 0;
+ while(!isConfiguration && i < this.children.size()){
+ if(this.children.get(i).getVertexActivation() == activation){
+ isConfiguration = true;
+ }
+ i++;
+ }
+ }
+ return isConfiguration;
+ }
+
private List<IVertexActivation> getContext(IVertexActivation activation){
+ // Provide the path from this state configuration to the target state configuration.
+ // The path is presented as an ascending hierarchy (nested -> top) of vertex activations.
+ // This path is used to perform a directed search through the representation of
+ // state configuration tree.
List<IVertexActivation> context = new ArrayList<IVertexActivation>();
List<IVertexActivation> hierarchy = activation.getAscendingHierarchy();
int i = hierarchy.size();
int j = 0;
boolean found = false;
- while(i >= 1 && !found){
- while(j < this.children.size() && !found){
+ while(!found && i >= 1){
+ while(!found && j < this.children.size()){
if(this.children.get(j).getVertexActivation()==hierarchy.get(i-1)){
found = true;
- context = hierarchy.subList(1, i);
+ // The most nested element in the hierarchy is always discarded.
+ // This nested element is the activation
+ context = hierarchy.subList(1, i);
}
j++;
}
@@ -92,6 +147,10 @@
}
public boolean remove(IVertexActivation activation, List<IVertexActivation> context){
+ // Follows the path provided by the context (ascending hierarchy of vertex activations)
+ // until the state configuration being the parent of the one referencing the activation
+ // is found. When found, the chil state configuration referencing the activation gets
+ // removed from the state configuration tree.
boolean removed = false;
if(!context.isEmpty()){
IVertexActivation current = context.get(context.size()-1);
@@ -110,7 +169,6 @@
int i = 0;
while(i < this.children.size() && !removed){
if(this.children.get(i).getVertexActivation()==activation){
- this.completeConfiguration.deleteFromCartography(this.children.get(i));
this.children.remove(i);
removed = true;
}
@@ -121,13 +179,17 @@
}
public boolean add(IVertexActivation activation, List<IVertexActivation> context){
+ // Follows the path provided by the context (ascending hierarchy of vertex activations)
+ // until the state configuration referencing the parent vertex activation of the activation
+ // is found. When found, a new state configuration is added as a children of the current
+ // state configuration. This new state configuration references the activation.
boolean added = false;
if(!context.isEmpty()){
IVertexActivation current = context.get(context.size()-1);
IStateConfiguration selectedStateConfiguration = null;
int i = 0;
while(i < this.children.size() && selectedStateConfiguration==null){
- if(this.children.get(i).getVertexActivation() ==current){
+ if(this.children.get(i).getVertexActivation()==current){
selectedStateConfiguration = this.children.get(i);
}
i++;
@@ -148,21 +210,12 @@
StateConfiguration newConfiguration = new StateConfiguration(activation);
newConfiguration.level = this.level + 1;
newConfiguration.completeConfiguration = this.completeConfiguration;
- this.completeConfiguration.addToCartography(newConfiguration);
added = this.children.add(newConfiguration);
}
}
return added;
}
- public boolean removeChild(IVertexActivation activation){
- return this.remove(activation, this.getContext(activation));
- }
-
- public boolean addChild(IVertexActivation activation){
- return this.add(activation, this.getContext(activation));
- }
-
public String toString(){
// Return a string representing configuration taking this node as a the root.
// The string that is obtained is possibly a partial representation of the
diff --git a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineConfiguration.java b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineConfiguration.java
index a63817c..cd0ff90 100644
--- a/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineConfiguration.java
+++ b/bundles/core/engines/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/StateMachineConfiguration.java
@@ -15,12 +15,6 @@
import static org.eclipse.papyrus.moka.fuml.statemachines.Activator.logger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.eclipse.papyrus.moka.fuml.statemachines.interfaces.Semantics.StateMachines.IStateActivation;
import org.eclipse.papyrus.moka.fuml.statemachines.interfaces.Semantics.StateMachines.IStateConfiguration;
import org.eclipse.papyrus.moka.fuml.statemachines.interfaces.Semantics.StateMachines.IStateMachineConfiguration;
@@ -37,9 +31,6 @@
// the top level active state.
protected IStateConfiguration rootConfiguration;
- // Provides a flattened view of the hierarchy of active states.
- private Map<Integer, List<IVertexActivation>> cartorgraphy;
-
public IStateConfiguration getRoot(){
return this.rootConfiguration;
}
@@ -48,20 +39,17 @@
return this.execution;
}
- public Map<Integer, List<IVertexActivation>> getCartography(){
- return this.cartorgraphy;
- }
-
public StateMachineConfiguration(IStateMachineExecution execution){
this.rootConfiguration = new StateConfiguration(this);
this.execution = execution;
- this.cartorgraphy = new HashMap<Integer, List<IVertexActivation>>();
}
public boolean register(IStateActivation stateActivation){
// Register the given state activation in the state-machine configuration.
// This occurs when the state activation is entered.
- return this.add(stateActivation);
+ boolean added = this.rootConfiguration.addChild(stateActivation);
+ logger.info(this.toString());
+ return added;
}
public boolean unregister(IStateActivation stateActivation){
@@ -69,7 +57,8 @@
// This occurs when the state activation is exited. When the removal process
// is successful the last action is to release possibly deferred events related
// to that state activation.
- boolean removed = this.remove(stateActivation);
+ boolean removed = this.rootConfiguration.removeChild(stateActivation);
+ logger.info(this.toString());
if(removed){
stateActivation.releaseDeferredEvents();
}
@@ -78,44 +67,7 @@
public boolean isActive(IVertexActivation activation){
// A vertex that is currently active is part of the state-machine configuration
- boolean found = false;
- Iterator<Integer> levelsIterator = this.cartorgraphy.keySet().iterator();
- while(!found && levelsIterator.hasNext()){
- found = this.cartorgraphy.get(levelsIterator.next()).contains(activation);
- }
- return found;
- }
-
- protected boolean remove(IVertexActivation activation){
- boolean removed = this.rootConfiguration.removeChild(activation);
- logger.info(this.toString());
- return removed;
- }
-
- protected boolean add(IVertexActivation activation){
- boolean added = this.rootConfiguration.addChild(activation);
- logger.info(this.toString());
- return added;
- }
-
- public void addToCartography(IStateConfiguration configuration){
- // Add the given representation of state that is part to the state-machine
- // configuration to the flattened representation.
- if(this.cartorgraphy.containsKey(configuration.getLevel())){
- this.cartorgraphy.get(configuration.getLevel()).add(configuration.getVertexActivation());
- }else{
- List<IVertexActivation> activation = new ArrayList<IVertexActivation>();
- activation.add(configuration.getVertexActivation());
- this.cartorgraphy.put(configuration.getLevel(), activation);
- }
- }
-
- public void deleteFromCartography(IStateConfiguration configuration){
- // Remove the given representation of state that is part to the state-machine configuration
- // from the flattened representation.
- if(this.cartorgraphy.containsKey(configuration.getLevel())){
- this.cartorgraphy.get(configuration.getLevel()).remove(configuration.getVertexActivation());
- }
+ return this.rootConfiguration.isConfigurationFor(activation);
}
public String toString(){