Source of BasicGraphInterface.java


  1: package GraphPackage;
  2: /**
  3:    An interface of methods providing basic operations for directed
  4:    and undirected graphs that are either weighted or unweighted.
  5:    
  6:    @author Frank M. Carrano
  7:    @author Timothy M. Henry
  8:    @version 5.0
  9: */
 10: public interface BasicGraphInterface<T>
 11: {
 12:    /** Adds a given vertex to this graph.
 13:        @param vertexLabel  An object that labels the new vertex and is
 14:                            distinct from the labels of current vertices.
 15:        @return  True if the vertex is added, or false if not. */
 16:    public boolean addVertex(T vertexLabel);

 18:    /** Adds a weighted edge between two given distinct vertices that 
 19:        are currently in this graph. The desired edge must not already 
 20:        be in the graph. In a directed graph, the edge points toward
 21:        the second vertex given.
 22:        @param begin  An object that labels the origin vertex of the edge.
 23:        @param end    An object, distinct from begin, that labels the end
 24:                      vertex of the edge.
 25:        @param edgeWeight  The real value of the edge's weight.
 26:        @return  True if the edge is added, or false if not. */
 27:    public boolean addEdge(T begin, T end, double edgeWeight);

 29:    /** Adds an unweighted edge between two given distinct vertices 
 30:        that are currently in this graph. The desired edge must not
 31:        already be in the graph. In a directed graph, the edge points 
 32:        toward the second vertex given.
 33:        @param begin  An object that labels the origin vertex of the edge.
 34:        @param end    An object, distinct from begin, that labels the end
 35:                      vertex of the edge.
 36:        @return  True if the edge is added, or false if not. */
 37:    public boolean addEdge(T begin, T end);

 39:    /** Sees whether an edge exists between two given vertices.
 40:        @param begin  An object that labels the origin vertex of the edge.
 41:        @param end    An object that labels the end vertex of the edge.
 42:        @return  True if an edge exists. */
 43:    public boolean hasEdge(T begin, T end);

 45:    /** Sees whether this graph is empty.
 46:        @return  True if the graph is empty. */
 47:    public boolean isEmpty();

 49:    /** Gets the number of vertices in this graph.
 50:        @return  The number of vertices in the graph. */
 51:    public int getNumberOfVertices();

 53:    /** Gets the number of edges in this graph.
 54:       @return  The number of edges in the graph. */
 55:    public int getNumberOfEdges();

 57:    /** Removes all vertices and edges from this graph resulting in an empty graph. */
 58:    public void clear();
 59: } // end BasicGraphInterface