Compacting the methods
[jpf-core.git] / src / main / gov / nasa / jpf / listener / ConflictTracker.java
index af9147b3eabd80c87b7c2b0f8f7432a8bcb04f41..82a71147943f905265e4113ee6b204a8b3f38d29 100644 (file)
@@ -112,33 +112,29 @@ public class ConflictTracker extends ListenerAdapter {
        isChanged |= updateTheOutSet(node, nodeToProcess);
       }
 
-      // Check for a conflict if the outSet of nodeToProcess is changed
-      if (isChanged) {
-        for (Node node : nodeToProcess.getSuccessors()) {
-         HashMap<Transition, ArrayList<NameValuePair>> setSets = nodeToProcess.getOutgoingEdges().get(node).getSetSetMap();
-         for (Map.Entry mapElement : setSets.entrySet()) {
-           Transition transition = (Transition)mapElement.getKey();
-           if (checkForConflict(nodeToProcess, node, transition))
-             return true;
-         }
-        }
-      }
+      // All the changes in current parents are propagated
+      parentQueueMap.get(nodeToProcess).clear();
 
-      // Update the parents list for the successors of the current node
-      parents.clear();
-      parents.add(nodeToProcess);
-
-      // Checking if the out set has changed or not(Add its successors to the change list!)
+      // Check if the node has changed or not
       if (isChanged) {
-        for (Node i : nodeToProcess.getSuccessors()) {
+       // Check for a conflict in all the transition out of this node
+       if (checkAllSuccForConflict(nodeToProcess))
+         return true;
+        
+       // Update the parents list for the successors of the current node
+       parents.clear();
+       parents.add(nodeToProcess);
+
+       // For all the successors of the current node
+       for (Node i : nodeToProcess.getSuccessors()) {
           if (!changed.contains(i))
             changed.add(i);
 
-         // Update the list of updated parents for the current node
-         if (parentQueueMap.containsKey(i))
+          // Update the list of updated parents for the current node
+          if (parentQueueMap.containsKey(i))
             parentQueueMap.get(i).add(nodeToProcess);
-         else
-           parentQueueMap.put(i, parents);
+          else
+            parentQueueMap.put(i, parents);
         }
       }
     }
@@ -155,6 +151,18 @@ public class ConflictTracker extends ListenerAdapter {
     return message;
   }
 
+  boolean checkAllSuccForConflict(Node currentNode) {
+    for (Node node : currentNode.getSuccessors()) {
+      HashMap<Transition, ArrayList<NameValuePair>> setSets = currentNode.getOutgoingEdges().get(node).getSetSetMap();
+      for (Map.Entry mapElement : setSets.entrySet()) {
+        Transition transition = (Transition)mapElement.getKey();
+       if (checkForConflict(currentNode, node, transition))
+         return true;
+      }
+    }
+    return false;
+  }
+
   boolean checkForConflict(Node parentNode, Node currentNode, Transition currentTransition) {
     ArrayList<NameValuePair> setSet = parentNode.getOutgoingEdges().get(currentNode).getSetSetMap().get(currentTransition);
     HashMap<String, String> valueMap = new HashMap<String, String>(); // HashMap from varName to value
@@ -193,7 +201,7 @@ public class ConflictTracker extends ListenerAdapter {
 
     // Check for conflict between outSet and this transition setSet
     for (NameValuePair i : parentNode.getOutSet()) {
-      if (valueMap.containsKey(i.getVarName())) {
+      if (firstValueMap.containsKey(i.getVarName())) {
         String value = firstValueMap.get(i.getVarName());
         Integer writer = firstWriterMap.get(i.getVarName());
         if ((value != null)&&(writer != null)) {
@@ -482,16 +490,9 @@ public class ConflictTracker extends ListenerAdapter {
     boolean isChanged = updateTheOutSet(parentNode, currentNode);
 
     // Check if the outSet of this state has changed, update all of its successors' sets if any
-    if (isChanged) {
-      for (Node node : currentNode.getSuccessors()) {
-        HashMap<Transition, ArrayList<NameValuePair>> setSets = currentNode.getOutgoingEdges().get(node).getSetSetMap();
-       for (Map.Entry mapElement : setSets.entrySet()) {
-         Transition currentTransition = (Transition)mapElement.getKey();
-         conflictFound = conflictFound || checkForConflict(currentNode, node, currentTransition);
-       }
-      }
-      conflictFound = conflictFound || propagateTheChange(currentNode);
-    }
+    if (isChanged)
+      conflictFound = conflictFound || checkAllSuccForConflict(currentNode) || propagateTheChange(currentNode);
+    
     // Update the parent node
     if (nodes.containsKey(id)) {
       parentNode = nodes.get(id);