next up previous contents
Next: Graph Class Up: GraphStuff Package Previous: SimpleUndirectedGraph Class

SimpleGraph Class

The SimpleGraph class extends the Graph class and provides a put() method which insures no (u,u) edges are inserted in the Graph. The SimpleGraph class also provides get(), delete() and isEdge() methods which take advantage of this property.

package GraphStuff;

public class SimpleGraph extends Graph {

   public SimpleGraph(Edge[] E, Vertex[] V) { super(E,V); }

   public SimpleGraph() {super();}

   public String toString() { return "SimpleGraph: "+ stringRep(); }

   public static Graph fromString(String str) {
      Vertex[] V;
      int i;
      if (-1==str.indexOf("SimpleGraph:")
          || null==(V = Vertex.arrayFromString(str)) )
         return null;
      return new SimpleGraph(Edge.arrayFromString(str),V);
   }

   public Graph put(int u,int v,Edge E) {
      if (u!=v)
         super.put(u,v,E);
      return this;
   }

   public Edge get(int u, int v){
      if (u!=v)
         return super.get(u,v);
      return null;
   }

   public Graph delete(int u,int v){
      if (u!=v)
         super.delete(u,v);
      return this;
   }

   public boolean isEdge(int u, int v) {
      return  (u!=v && super.isEdge(u,v) );
   }

}



Kelly Waters
Mon Oct 27 18:18:15 EST 1997