Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Edge.java

00001 package gov.nasa.arc.ase.util.graph;
00002 
00003 import java.io.PrintStream;
00004 
00005 public class Edge {
00006   private Node source;
00007   private Node next;
00008   private String guard;
00009   private String action;
00010   private Attributes attributes;
00011 
00012   public Edge(Edge e)                           { init(e.source, e.next, new String(e.guard), new String(e.action), new Attributes(e.attributes)); }  
00013   public Edge(Edge e, Node n)                       { init(e.source, n, new String(e.guard), new String(e.action), new Attributes(e.attributes)); }  
00014   public Edge(Node s, Edge e)                       { init(s, e.next, new String(e.guard), new String(e.action), new Attributes(e.attributes)); }  
00015   public Edge(Node s, Node n)                       { init(s, n, "-", "-", null); }  
00016   public Edge(Node s, Node n, String g)             { init(s, n, g, "-", null); }  
00017   public Edge(Node s, Node n, String g, String a)           { init(s, n, g, a, null); }  
00018   public Edge(Node s, Node n, String g, String a, Attributes as)    { init(s, n, g, a, as); }  
00019   public String getAction() { return action; }  
00020   public Attributes getAttributes() { return attributes; }  
00021   public boolean getBooleanAttribute(String name) { return attributes.getBoolean(name); }  
00022   public String getGuard() { return guard; }  
00023   public int getIntAttribute(String name) { return attributes.getInt(name); }  
00024   public Node getNext() { return next; }  
00025   public Node getSource() { return source; }  
00026   public String getStringAttribute(String name) { return attributes.getString(name); }  
00027   private void init(Node s, Node n, String g, String a, Attributes as) {
00028     source = s;
00029     next = n;
00030     guard = g;
00031     action = a;
00032     if(as == null)
00033       attributes = new Attributes();
00034     else
00035       attributes = as;
00036 
00037     s.addOutgoingEdge(this);
00038     n.addIncomingEdge(this);
00039   }  
00040   synchronized public void remove() {
00041     source.removeOutgoingEdge(this);
00042     next.removeIncomingEdge(this);
00043   }  
00044   void save(PrintStream out, int format) {
00045     switch(format) {
00046       case Graph.SM_FORMAT: save_sm(out); break;
00047       case Graph.FSP_FORMAT: save_fsp(out); break;
00048     }
00049   }  
00050   // Modified by ckong - Sept 7, 2001
00051   private void save_fsp(PrintStream out) {
00052     String g;
00053     String accs = "";
00054     
00055     if(guard.equals("-"))
00056       g = "TRUE";
00057     else
00058       g = guard;
00059 
00060     int nsets = source.getGraph().getIntAttribute("nsets");
00061     if(nsets == 0) {
00062       if(getBooleanAttribute("accepting"))
00063     accs = "@";
00064     } else {
00065       boolean first = true;
00066       StringBuffer sb = new StringBuffer();
00067 
00068       for(int i = 0; i < nsets; i++)
00069     if(getBooleanAttribute("acc"+i)) {
00070       if(first)
00071         first = false;
00072       else
00073         sb.append(",");
00074       sb.append(i);
00075     }
00076       if(!first)
00077     accs = "{" + sb.toString() + "}";
00078     }
00079     
00080     //System.out.print(g + " -" + accs + "-> S" + next.getId());
00081     out.print(g + " -" + accs + "-> S" + next.getId());
00082   }  
00083   private void save_sm(PrintStream out) {
00084     out.print("    "); out.println(next.getId());
00085     out.print("    "); out.println(guard);
00086     out.print("    "); out.println(action);
00087     out.print("    "); out.println(attributes);
00088   }  
00089   synchronized public void setAttributes(Attributes a) {
00090     attributes = new Attributes(a);
00091   }  
00092   public void setBooleanAttribute(String name, boolean value) { attributes.setBoolean(name, value); }  
00093   public void setIntAttribute(String name, int value) { attributes.setInt(name, value); }  
00094   public void setStringAttribute(String name, String value) { attributes.setString(name, value); }  
00095 }

Generated at Thu Feb 7 06:45:02 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001