|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsalvo.jesus.graph.GraphImpl
public class GraphImpl
An implementation of the Graph interface. A Graph object represents a graph data structure, which are vertices connected by edges, where the edges are non-directional.
Field Summary | |
---|---|
protected java.util.Vector |
addedgelistener
Vector of GraphAddEdgeListeners that are interested in listening when new edges are added to the Graph. |
protected java.util.Vector |
addvertexlistener
Vector of GraphAddVertexListeners that are interested in listening when new vertices are added to the Graph. |
protected java.util.Collection |
connectedSetS
Collection of Collection (no, that was not a typo!) of vertices that are connected. |
protected java.util.Map |
edges
Map of edges in the graph. |
protected java.util.Vector |
removeedgelistener
Vector of GraphRemoveEdgeListeners that are interested in listening when edges are removed from the Graph. |
protected java.util.Vector |
removevertexlistener
Vector of GraphRemoveVertexListeners that are interested in listening when vertices are removed from the Graph. |
protected GraphTraversal |
traversal
Delegate object for implementing graph traversal. |
protected java.util.Collection |
vertices
Collection of vertices in the graph. |
Constructor Summary | |
---|---|
GraphImpl()
|
|
GraphImpl(GraphImpl toBeCloned)
Copy constructor |
Method Summary | |
---|---|
void |
add(Vertex newvertex)
Adds a Vertex into the Graph. |
void |
addEdge(Edge edge)
Adds an Edge into the Graph. |
Edge |
addEdge(Vertex v1,
Vertex v2)
Adds an Edge into the Graph. |
void |
addGraphAddEdgeListener(GraphAddEdgeListener listener)
Adds a GraphAddEdgeListener to the Graph's internal Vector of GraphAddEdgeListeners so that when a new Edge is added, all registered GraphAddEdgeListeners are notified of the event. |
void |
addGraphAddVertexListener(GraphAddVertexListener listener)
Adds a GraphAddVertexListener to the Graph's internal Vector of GraphAddVertexListeners so that when a new Vertex is added, all registered GraphAddVertedListeners are notified of the event. |
void |
addGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
Adds a GraphRemoveEdgeListener to the Graph's internal Vector of GraphRemoveEdgeListeners so that when an Edge is removed, all registered GraphRemoveEdgeListeners are notified of the event. |
void |
addGraphRemoveVertexListener(GraphRemoveVertexListener listener)
Adds a GraphRemoveVertexListener to the Graph's internal Vector of GraphRemoveVertexListeners so that when a Vertex is removed, all registered GraphRemoveVertexListeners are notified of the event. |
java.lang.Object |
clone()
|
java.util.Collection |
cloneVertices()
Returns a clone of the Collection of vertices. |
Edge |
createEdge(Vertex v1,
Vertex v2)
Method to create the proper type of Edge class. |
java.util.Collection |
getAdjacentVertices(java.util.Collection vertices)
Returns the vertices adjacent to all the vertices in the given collection. |
java.util.Collection |
getAdjacentVertices(Vertex v)
Returns the vertices adjacent to the specified vertex. |
java.util.Collection |
getConnectedSet()
Returns the connected sets in the Graph. |
java.util.Collection |
getConnectedSet(Vertex v)
Returns the connected set to which the specified vertex belongs. |
int |
getDegree()
Returns the degree of the graph, which is simply the highest degree of all the graph's vertices. |
int |
getDegree(Vertex v)
Returns the degree of the vertex, which is simply the number of edges of the vertex. |
java.util.Collection |
getEdges(Vertex v)
Returns a Collection of edges of the specified vertex. |
GraphTraversal |
getTraversal()
Gets the traversal algorithm used by the Graph. |
java.util.Set |
getVertices(int degree)
Returns all vertices with the specified degree. |
int |
getVerticesCount()
Returns the number of vertices in the graph |
java.util.Iterator |
getVerticesIterator()
Returns an iterator that iterates through the graph's vertices. |
boolean |
isConnected(Vertex v1,
Vertex v2)
Determines if two vertices are connected |
void |
mergeconnectedSet(Vertex v1,
Vertex v2)
Merges the connected sets to which Vertex v1 and Vertex v2 belongs, if they are not yet connected. |
void |
remove(Vertex v)
Removes the specified Edge from the Graph. |
void |
removeEdge(Edge edge)
Removes the specified Edge from the Graph. |
void |
removeEdges(Vertex v)
Removes incident Edges of a Vertex. |
void |
removeGraphAddEdgeListener(GraphAddEdgeListener listener)
Removes a GraphAddEdgeListener from the Graph's internal Vector of GraphAddEdgeListeners. |
void |
removeGraphAddVertexListener(GraphAddVertexListener listener)
Removes a GraphAddVertexListener from the Graph's internal Vector of GraphAddVertexListeners. |
void |
removeGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
Removes a GraphRemoveEdgeListener from the Graph's internal Vector of GraphRemoveEdgeListeners. |
void |
removeGraphRemoveVertexListener(GraphRemoveVertexListener listener)
Removes a GraphRemoveVertexListener from the Graph's internal Vector of GraphRemoveVertexListeners. |
void |
setTraversal(GraphTraversal traversal)
Sets the graph traversal algorithm to be used |
java.lang.String |
toString()
Returns a String representation of the Graph. |
java.util.Vector |
traverse(Vertex startat)
Traverses the Graph starting at startat Vertex. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Collection vertices
protected java.util.Map edges
protected java.util.Collection connectedSetS
protected java.util.Vector addvertexlistener
GraphAddVertexListener
protected java.util.Vector addedgelistener
GraphAddEdgeListener
protected java.util.Vector removevertexlistener
GraphRemoveVertexListener
protected java.util.Vector removeedgelistener
GraphRemoveEdgeListener
protected GraphTraversal traversal
Constructor Detail |
---|
public GraphImpl()
public GraphImpl(GraphImpl toBeCloned)
Method Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.Iterator getVerticesIterator()
getVerticesIterator
in interface Graph
public java.util.Collection cloneVertices()
cloneVertices
in interface Graph
public java.util.Collection getEdges(Vertex v)
getEdges
in interface Graph
v
- The vertex whose edges we want returned
public void add(Vertex newvertex) throws java.lang.Exception
add
in interface Graph
newvertex
- Vertex to be added to the Graph
java.lang.Exception
public Edge createEdge(Vertex v1, Vertex v2)
createEdge
in interface Graph
v1
- One endpoint of the edgev2
- Other endpoint of the edgepublic Edge addEdge(Vertex v1, Vertex v2) throws java.lang.Exception
addEdge
in interface Graph
v1
- One endpoint of the edgev2
- Other endpoint of the edge
java.lang.Exception
public void addEdge(Edge edge) throws java.lang.Exception
In the event that any one of the vertices are not existing in the Graph, they are added to the Graph.
Note: It is the caller's responsibility to make sure that the type of Edge being added is an EdgeImpl.
addEdge
in interface Graph
e
- The edge to be added to the Graph.
java.lang.Exception
public void remove(Vertex v) throws java.lang.Exception
Graph
remove
in interface Graph
java.lang.Exception
public void removeEdge(Edge edge) throws java.lang.Exception
removeEdge
in interface Graph
edge
- The Edge object to be removed.
java.lang.Exception
public void removeEdges(Vertex v) throws java.lang.Exception
removeEdges
in interface Graph
v
- Vertex whose Edges are to be removed
java.lang.Exception
public int getVerticesCount()
getVerticesCount
in interface Graph
public java.util.Set getVertices(int degree)
getVertices
in interface Graph
degree
- The degree of the vertex to be returned.
public java.util.Collection getAdjacentVertices(Vertex v)
getAdjacentVertices
in interface Graph
v
- The Vertex you want to determine its adjacent vertices.
public java.util.Collection getAdjacentVertices(java.util.Collection vertices)
getAdjacentVertices
in interface Graph
vertices
- Collection of Vertex where each vertex in the
returned Set must be adjacent to.
public java.util.Collection getConnectedSet()
getConnectedSet
in interface Graph
public java.util.Collection getConnectedSet(Vertex v)
getConnectedSet
in interface Graph
v
- Vertex to which you want the connected set returned.
public void mergeconnectedSet(Vertex v1, Vertex v2)
mergeconnectedSet
in interface Graph
v1
- Vertex whose connected set you want merged
with the connected set of Vertex v2.v2
- Vertex whose connected set you want merged
with the connected set of Vertex v1.public java.util.Vector traverse(Vertex startat)
traverse
in interface Graph
startat
- The Vertex to which you want to start the traversal.public GraphTraversal getTraversal()
getTraversal
in interface Graph
public void setTraversal(GraphTraversal traversal)
setTraversal
in interface Graph
traversal
- A concrete implementation of the GraphTraversal object.public boolean isConnected(Vertex v1, Vertex v2)
isConnected
in interface Graph
v1
- starting Vertex for the pathv2
- ending Vertex for the path
public int getDegree()
getDegree
in interface Graph
public int getDegree(Vertex v)
getDegree
in interface Graph
public void addGraphAddVertexListener(GraphAddVertexListener listener)
addGraphAddVertexListener
in interface Graph
listener
- GraphAddVertexListener you want registered
or be notified when a new Vertex is addedGraphAddVertexListener
,
removeGraphAddVertexListener( GraphAddVertexListener )
public void addGraphAddEdgeListener(GraphAddEdgeListener listener)
addGraphAddEdgeListener
in interface Graph
listener
- GraphAddEdgeListener you want registered
or be notified when a new Edge is addedGraphAddEdgeListener
,
removeGraphAddEdgeListener( GraphAddEdgeListener )
public void addGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
addGraphRemoveEdgeListener
in interface Graph
listener
- GraphRemoveEdgeListener you want registered
or be notified when an Edge is removedGraphRemoveEdgeListener
,
removeGraphRemoveEdgeListener( GraphRemoveEdgeListener )
public void addGraphRemoveVertexListener(GraphRemoveVertexListener listener)
addGraphRemoveVertexListener
in interface Graph
listener
- GraphRemoveVertexListener you want registered
or be notified when a Vertex is removedGraphRemoveVertexListener
,
removeGraphRemoveVertexListener( GraphRemoveVertexListener )
public void removeGraphAddVertexListener(GraphAddVertexListener listener)
removeGraphAddVertexListener
in interface Graph
listener
- GraphAddVertexListener you no longer want registered
or be notified when a Vertex is addedGraphAddVertexListener
,
addGraphAddVertexListener( GraphAddVertexListener )
public void removeGraphAddEdgeListener(GraphAddEdgeListener listener)
removeGraphAddEdgeListener
in interface Graph
listener
- GraphAddEdgeListener you no longer want registered
or be notified when an Edge is addedGraphAddEdgeListener
,
addGraphAddEdgeListener( GraphAddEdgeListener )
public void removeGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
removeGraphRemoveEdgeListener
in interface Graph
listener
- GraphRemoveEdgeListener you no longer want registered
or be notified when an Edge is removedGraphRemoveEdgeListener
,
addGraphRemoveEdgeListener( GraphRemoveEdgeListener )
public void removeGraphRemoveVertexListener(GraphRemoveVertexListener listener)
removeGraphRemoveVertexListener
in interface Graph
listener
- GraphRemoveVertexListener you no longer want registered
or be notified when a Vertex is removedGraphRemoveVertexListener
,
addGraphRemoveVertexListener( GraphRemoveVertexListener )
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |