refactor GraphViz into Node
authoradam <adam@megacz.com>
Mon, 5 Nov 2007 02:43:13 +0000 (21:43 -0500)
committeradam <adam@megacz.com>
Mon, 5 Nov 2007 02:43:13 +0000 (21:43 -0500)
darcs-hash:20071105024313-5007d-bdd556a24a61601198854e4aa18c401ec44acecf.gz

src/edu/berkeley/sbp/Node.java
src/edu/berkeley/sbp/ResultNode.java
src/edu/berkeley/sbp/StateNode.java

index 7a5c38d..872e377 100644 (file)
@@ -10,6 +10,30 @@ import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 
 import java.util.*;
 import java.lang.reflect.*;
 
-class Node {
+class Node
+    implements GraphViz.ToGraphViz {
 
 
+    // GraphViz //////////////////////////////////////////////////////////////////////////////
+
+    public GraphViz.StateNode toGraphViz(GraphViz gv) {
+        if (gv.hasNode(this)) return gv.createNode(this);
+        GraphViz.StateNode n = gv.createNode(this);
+        /*
+        n.label = ""+f;
+        n.shape = "rectangle";
+        //if (pred()!=null) n.edge(pred, "");
+        n.color = "blue";
+        if (phase() != null)
+            ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
+        n.label = "state["+state.toInt()+"]";
+        n.shape = "rectangle";
+        boolean haspreds = false;
+        for(ResultNode r : results) n.edge(r, "");
+        n.color = state.doomed ? "red" : "green";
+        ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
+        */
+        return n;
+    }
+    public boolean isTransparent() { return false; }
+    public boolean isHidden() { return false; }
 }
\ No newline at end of file
 }
\ No newline at end of file
index e8e3b57..d61b06b 100644 (file)
@@ -6,9 +6,7 @@ import edu.berkeley.sbp.Sequence.Pos;
 import edu.berkeley.sbp.Sequence.Pos;
 import java.util.*;
 
 import edu.berkeley.sbp.Sequence.Pos;
 import java.util.*;
 
-final class ResultNode
-    extends Node
-    implements GraphViz.ToGraphViz {
+final class ResultNode extends Node {
 
     private Forest.Many f = new Forest.Many();
     //private HashSet<StateNode> predecessors = new HashSet<StateNode>();
 
     private Forest.Many f = new Forest.Many();
     //private HashSet<StateNode> predecessors = new HashSet<StateNode>();
@@ -106,20 +104,5 @@ final class ResultNode
         if (pred != null) addPred(pred);
     }
 
         if (pred != null) addPred(pred);
     }
 
-    // GraphViz //////////////////////////////////////////////////////////////////////////////
-
-    public GraphViz.StateNode toGraphViz(GraphViz gv) {
-        if (gv.hasNode(this)) return gv.createNode(this);
-        GraphViz.StateNode n = gv.createNode(this);
-        n.label = ""+f;
-        n.shape = "rectangle";
-        //if (pred()!=null) n.edge(pred, "");
-        n.color = "blue";
-        if (phase() != null)
-            ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
-        return n;
-    }
-    public boolean isTransparent() { return false; }
-    public boolean isHidden() { return false; }
 
 }
\ No newline at end of file
 
 }
\ No newline at end of file
index 35f727d..acd0134 100644 (file)
@@ -15,7 +15,6 @@ final class StateNode
     extends Node
     implements Invokable<Pos, ResultNode, Object>,
                IntegerMappable,
     extends Node
     implements Invokable<Pos, ResultNode, Object>,
                IntegerMappable,
-               GraphViz.ToGraphViz,
                Iterable<ResultNode> {
 
     /** which GSS.Phase this StateNode belongs to */
                Iterable<ResultNode> {
 
     /** which GSS.Phase this StateNode belongs to */
@@ -145,22 +144,4 @@ final class StateNode
         result.addSucc(this);
         if (!this.fromEmptyReduction) state.invokeReductions(phase().getToken(), this, result);
     }
         result.addSucc(this);
         if (!this.fromEmptyReduction) state.invokeReductions(phase().getToken(), this, result);
     }
-
-    // GraphViz //////////////////////////////////////////////////////////////////////////////
-
-    public GraphViz.StateNode toGraphViz(GraphViz gv) {
-        if (results.size()==0) return null;
-        if (gv.hasNode(this)) return gv.createNode(this);
-        GraphViz.StateNode n = gv.createNode(this);
-        n.label = "state["+state.toInt()+"]";
-        n.shape = "rectangle";
-        boolean haspreds = false;
-        for(ResultNode r : results) n.edge(r, "");
-        n.color = state.doomed ? "red" : "green";
-        ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
-        return n;
-    }
-    public boolean isTransparent() { return false; }
-    public boolean isHidden() { return false; }
-
 }
 }