ls
Class Graph

java.lang.Object
  |
  +--ls.Graph
Direct Known Subclasses:
DirectedGraph

public class Graph
extends java.lang.Object

This class creates an undirected graph that will contain a list of vertices and edges for the graph. It is a base class for most types of graphs.


Field Summary
protected  java.util.Vector edges
           
protected  java.util.Vector vertices
           
 
Constructor Summary
Graph()
          Creates a new graph with no verctices or edges.
Graph(java.util.Vector vertices, java.util.Vector edges)
          Creates a graph with the give set of vertices and edges
 
Method Summary
 void addEdge(Edge e)
          Adds a new edge to the graph.
 void addEdge(java.lang.Object o1, java.lang.Object o2)
          Adds a new edge to the graph.
 void addEdge(Vertex v1, Vertex v2)
          Adds a new edge to the graph.
 void addVertex(java.lang.Object o)
          Adds a new vertex to the graph.
 void addVertex(Vertex v)
          Adds a new vertex to the graph.
 boolean existsEdge(Edge e)
          Tests to see if the given edge already exists in the graph.
 java.util.Vector findEdges(java.lang.Object v)
          Finds all of the edges that contain a particular vertex
 Edge getEdge(int index)
          Returns the edge at the specific location in the graph.
 java.util.Vector getEdges()
          Returns a list of all the edges in the graph
 Vertex getVertex(int index)
          Returns the vertex at the specified location.
 java.util.Vector getVertices()
          Returns all of the vertices in the graph.
 int numEdges()
          Retuns the number of edges that are in the graph.
 int numVertices()
          Returns the number of vertices that are in the graph.
 void print()
          Prints out the entire graph structure.
 void printAddress()
           
 void setEdges(java.util.Vector edges)
          Sets all of the edges in the graph to be the one in this particular list.
 void setVertices(java.util.Vector vertices)
          Sets all of the vertices in the graph to be of a certian set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vertices

protected java.util.Vector vertices

edges

protected java.util.Vector edges
Constructor Detail

Graph

public Graph()
Creates a new graph with no verctices or edges.

Graph

public Graph(java.util.Vector vertices,
             java.util.Vector edges)
Creates a graph with the give set of vertices and edges
Parameters:
vertices - the set of vertices
edges - the set of edges
Method Detail

addVertex

public void addVertex(java.lang.Object o)
Adds a new vertex to the graph.
Parameters:
o - the vertex to be added

addVertex

public void addVertex(Vertex v)
Adds a new vertex to the graph. If the vertex already exists then it will not be added again.
Parameters:
v - the vertex to be added

addEdge

public void addEdge(java.lang.Object o1,
                    java.lang.Object o2)
Adds a new edge to the graph.
Parameters:
o1 - one end of the edge
o2 - the other end of the edge

addEdge

public void addEdge(Vertex v1,
                    Vertex v2)
Adds a new edge to the graph.
Parameters:
v1 - one end of the edge
v2 - the other end of the edge

addEdge

public void addEdge(Edge e)
Adds a new edge to the graph. If the edge already exists it will not be added again.
Parameters:
e - the edge to be added

existsEdge

public boolean existsEdge(Edge e)
Tests to see if the given edge already exists in the graph.
Parameters:
e - - the edge that is being looked for

numVertices

public int numVertices()
Returns the number of vertices that are in the graph.
Returns:
the number of vertices in the graph

numEdges

public int numEdges()
Retuns the number of edges that are in the graph.
Returns:
the number of edges in the graph

getVertices

public java.util.Vector getVertices()
Returns all of the vertices in the graph.
Returns:
a list of the vertices in the graph

setVertices

public void setVertices(java.util.Vector vertices)
Sets all of the vertices in the graph to be of a certian set
Parameters:
vertices - - the list of vertices

getEdges

public java.util.Vector getEdges()
Returns a list of all the edges in the graph
Returns:
a list of edges in the graph

setEdges

public void setEdges(java.util.Vector edges)
Sets all of the edges in the graph to be the one in this particular list.
Parameters:
edges - the list of edges

getVertex

public Vertex getVertex(int index)
Returns the vertex at the specified location.
Parameters:
index - the vertex at this location
Returns:
the vertex at the specified location

getEdge

public Edge getEdge(int index)
Returns the edge at the specific location in the graph.
Parameters:
index - the edge at this location
Returns:
the edge at the specified location

findEdges

public java.util.Vector findEdges(java.lang.Object v)
Finds all of the edges that contain a particular vertex
Parameters:
v - the vertex who's edges we are looking for
Returns:
a list of edges this vertex is a part of

print

public void print()
Prints out the entire graph structure.

printAddress

public void printAddress()