get rid of map
[IRC.git] / Robust / src / Analysis / TaskStateAnalysis / FlagState.java
index 3de49a19c4f16242dcea966f16c297d9858dd5ea..b7921443d9188b35c452d9082c0010c34ac99f51 100644 (file)
@@ -27,9 +27,11 @@ public class FlagState {
     Vector edges = new Vector();
     Vector inedges = new Vector();
     NodeStatus status = UNVISITED;
-    String dotnodeparams = new String();
+    protected String dotnodeparams = new String();
     boolean merge=false;
     String nodeoption="";
+    private int uid;
+    private static int nodeid=0;
 
     private final HashSet flagstate;
     private final ClassDescriptor cd;
@@ -41,12 +43,19 @@ public class FlagState {
     public void setMerge() {
        merge=true;
     }
+    
+    public FlagState(ClassDescriptor cd) {
+       this.flagstate=new HashSet();
+       this.cd=cd;
+       this.uid=FlagState.nodeid++;
+    }
 
-    public FlagState(HashSet flagstate, ClassDescriptor cd) {
+    private FlagState(HashSet flagstate, ClassDescriptor cd) {
        this.flagstate=flagstate;
        this.cd=cd;
+       this.uid=FlagState.nodeid++;
     }
-
+    
     public boolean get(FlagDescriptor fd) {
        return flagstate.contains(fd);
     }
@@ -58,13 +67,33 @@ public class FlagState {
     public Iterator getFlags() {
        return flagstate.iterator();
     }
+    
+       public String toString(FlagDescriptor[] flags)
+       {
+               StringBuffer sb = new StringBuffer(flagstate.size());
+               for(int i=0;i < flags.length; i++)
+               {
+                       if (get(flags[i]))
+                               sb.append(1);
+                       else
+                               sb.append(0);
+               }
+                       
+               return new String(sb);
+       }
+
+       
+       public ClassDescriptor getClassDescriptor(){
+       return cd;
+       }
 
     public FlagState setFlag(FlagDescriptor fd, boolean status) {
        HashSet newset=(HashSet) flagstate.clone();
        if (status)
            newset.add(fd);
-       else
+       else if (newset.contains(fd)){
            newset.remove(fd);
+       }
        return new FlagState(newset, cd);
     }
     
@@ -144,17 +173,17 @@ public class FlagState {
     }
 
     public String getLabel() {
-        return getTextLabel();
+       return "N"+uid;
     }
 
     public String getTextLabel() {
        String label=null;
        for(Iterator it=getFlags();it.hasNext();) {
-           FlagState fs=(FlagState) it.next();
+           FlagDescriptor fd=(FlagDescriptor) it.next();
            if (label==null)
-               label=fs.toString();
+               label=fd.toString();
            else
-               label+=", "+fs.toString();
+               label+=", "+fd.toString();
        }
        return label;
     }
@@ -251,9 +280,7 @@ public class FlagState {
             output.println("}\n");
         }
 
-        private void traverse() {
-           Set cycleset=FlagState.findcycles(nodes);
-
+       private void traverse() {
             Iterator i = nodes.iterator();
             while (i.hasNext()) {
                 FlagState gn = (FlagState) i.next();
@@ -272,13 +299,14 @@ public class FlagState {
                    if (nodes.contains(node)) {
                        for(Iterator nodeit=nonmerge(node).iterator();nodeit.hasNext();) {
                            FlagState node2=(FlagState)nodeit.next();
-                           String edgelabel = Compiler.DEBUGGRAPH ? "label=\"" + edge.getLabel() + "\"" : "label=\"\"";
+                           String edgelabel = "label=\"" + edge.getLabel() + "\"";
                            output.println("\t" + gn.getLabel() + " -> " + node2.getLabel() + " [" + edgelabel + edge.dotnodeparams + "];");
                        }
                    }
                 }
             }
         }
+        
 
        Set nonmerge(FlagState gn) {
            HashSet newset=new HashSet();