jdsl.core.ref
Class SILGraph

java.lang.Object
  |
  +--jdsl.core.ref.SILGraph

public class SILGraph
extends java.lang.Object
implements Graph

This is the teach simplification/modification of the advanced Simple Incidence List Graph.

Author:
Benoit Hudson (bh),Ryan Shaun Baker (rsb),Mike Boilen (mgb)

Constructor Summary
SILGraph()
          Constructs a new, empty Graph.
 
Method Summary
 java.util.Enumeration adjacentVertices(Vertex v)
          Gets the adjacent vertices to a particular vertex.
 int degree(Vertex v)
          Gets the number of incident edges of a vertex.
 Vertex destination(Edge e)
          Gets the destination of an edge.
 java.util.Enumeration directedEdges()
          Gets all the directedEdges in this graph.
 java.util.Enumeration edges()
          Gets all the edges in this graph.
 java.util.Enumeration elements()
          Gets the elements in this graph.
 Vertex[] endVertices(Edge e)
          Gets the endpoints of an edge.
 java.util.Enumeration inAdjacentVertices(Vertex v)
          Gets all the vertices that are the source of an incoming incident edge to a vertex.
 java.util.Enumeration incidentEdges(Vertex v)
          Returns all edges incident to a particular vertex.
 int inDegree(Vertex v)
          Gets the number of incoming incident edges of a vertex.
 java.util.Enumeration inIncidentEdges(Vertex v)
          Returns all edges incident to a particular vertex.
 Edge insertDirectedEdge(Vertex v1, Vertex v2, java.lang.Object elt)
          Inserts a directed edge into this graph.
 Edge insertEdge(Vertex v1, Vertex v2, java.lang.Object elt)
          Inserts an edge into this graph.
 Vertex insertVertex(java.lang.Object info)
          Inserts a vertex into this graph.
 boolean isDirected(Edge e)
          Tests if an edge is directed.
 boolean isEmpty()
          Tests if this container is empty.
 void makeUndirected(Edge e)
          Makes a directed edge undirected.
 Container newContainer()
          Constructs a new, empty Graph.
 int numEdges()
          Gets the number of edges in this graph.
 int numVertices()
          Gets the number of vertices in this graph.
 Vertex opposite(Vertex v, Edge e)
          Gets the end vertex of Edge e that is different from Vertex v.
 Vertex origin(Edge e)
          Gets the origin of an edge.
 java.util.Enumeration outAdjacentVertices(Vertex v)
          Gets all the vertices that are the destination of an outgoing incident edge to a vertex.
 int outDegree(Vertex v)
          Gets the number of outgoing incident edges of a vertex.
 java.util.Enumeration outIncidentEdges(Vertex v)
          Gets all edges incident from a particular vertex.
 java.util.Enumeration positions()
          Gets all the positions in this graph.
 java.lang.Object removeEdge(Edge e)
          Removes an edge from this graph.
 java.lang.Object removeVertex(Vertex v)
          Removes a vertex from this graph.
 java.lang.Object replace(Position p, java.lang.Object newElement)
          Replaces the object associated with a position.
 void reverseDirection(Edge e)
          Reverses the direction of an edge.
 void setDirectionFrom(Edge e, Vertex newOrigin)
          Sets the direction of an edge away from a vertex.
 void setDirectionTo(Edge e, Vertex newDestination)
          Sets the direction of an edge to a vertex.
 int size()
          Gets the size of this graph.
 void swap(Position a, Position b)
          Swaps the elements of two positions.
 java.util.Enumeration undirectedEdges()
          Gets all the undirected edges in this graph.
 java.util.Enumeration vertices()
          Gets all the vertices in this graph.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SILGraph

public SILGraph()
Constructs a new, empty Graph.
Method Detail

newContainer

public Container newContainer()
Constructs a new, empty Graph.

size

public int size()
Gets the size of this graph.
Returns:
the size, which is the number of edges plus the number of vertices.

isEmpty

public boolean isEmpty()
Tests if this container is empty.
Returns:
true if this container contains no vertices or edges, false otherwise.

elements

public java.util.Enumeration elements()
Gets the elements in this graph.
Returns:
The objects associated with the vertices in this graph.
See Also:
insertVertex, insertEdge

positions

public java.util.Enumeration positions()
Gets all the positions in this graph.
Returns:
All of the edges and vertices in this graph.

replace

public java.lang.Object replace(Position p,
                                java.lang.Object newElement)
                         throws InvalidPositionException
Replaces the object associated with a position.
Parameters:
p - Any position in the graph.
newElement - The new element to associate with the Position
Returns:
The old object associated with p
Throws:
InvalidPositionException - if p is not compatible with this container.

swap

public void swap(Position a,
                 Position b)
          throws InvalidPositionException
Swaps the elements of two positions. The Positions stay in place.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

numVertices

public int numVertices()
Gets the number of vertices in this graph.

numEdges

public int numEdges()
Gets the number of edges in this graph.

vertices

public java.util.Enumeration vertices()
Gets all the vertices in this graph.

edges

public java.util.Enumeration edges()
Gets all the edges in this graph.

directedEdges

public java.util.Enumeration directedEdges()
Gets all the directedEdges in this graph.

undirectedEdges

public java.util.Enumeration undirectedEdges()
Gets all the undirected edges in this graph.

degree

public int degree(Vertex v)
Gets the number of incident edges of a vertex.

inDegree

public int inDegree(Vertex v)
Gets the number of incoming incident edges of a vertex.

outDegree

public int outDegree(Vertex v)
Gets the number of outgoing incident edges of a vertex.

adjacentVertices

public java.util.Enumeration adjacentVertices(Vertex v)
                                       throws InvalidPositionException
Gets the adjacent vertices to a particular vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

inAdjacentVertices

public java.util.Enumeration inAdjacentVertices(Vertex v)
                                         throws InvalidPositionException
Gets all the vertices that are the source of an incoming incident edge to a vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

outAdjacentVertices

public java.util.Enumeration outAdjacentVertices(Vertex v)
                                          throws InvalidPositionException
Gets all the vertices that are the destination of an outgoing incident edge to a vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

incidentEdges

public java.util.Enumeration incidentEdges(Vertex v)
                                    throws InvalidPositionException
Returns all edges incident to a particular vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

inIncidentEdges

public java.util.Enumeration inIncidentEdges(Vertex v)
                                      throws InvalidPositionException
Returns all edges incident to a particular vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

outIncidentEdges

public java.util.Enumeration outIncidentEdges(Vertex v)
                                       throws InvalidPositionException
Gets all edges incident from a particular vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

endVertices

public Vertex[] endVertices(Edge e)
                     throws InvalidPositionException
Gets the endpoints of an edge.
Throws:
InvalidPositionException - if the edge is invalid or incompatible with this Graph

opposite

public Vertex opposite(Vertex v,
                       Edge e)
                throws InvalidEdgeException,
                       InvalidPositionException
Gets the end vertex of Edge e that is different from Vertex v. If Edge e is a self loop (both oritin and destination are the same vertex), then v will be returned.
Parameters:
e - Any edge in the graph.
v - A vertex of e
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

origin

public Vertex origin(Edge e)
              throws InvalidEdgeException,
                     InvalidPositionException
Gets the origin of an edge.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

destination

public Vertex destination(Edge e)
                   throws InvalidEdgeException,
                          InvalidPositionException
Gets the destination of an edge.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

isDirected

public boolean isDirected(Edge e)
                   throws InvalidEdgeException
Tests if an edge is directed.
Returns:
true if the edge is directed, false otherwise.

insertVertex

public Vertex insertVertex(java.lang.Object info)
                    throws InvalidPositionException
Inserts a vertex into this graph.
Specified by:
insertVertex in interface Graph
Parameters:
info - Any Object to be associated with this vertex.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

insertEdge

public Edge insertEdge(Vertex v1,
                       Vertex v2,
                       java.lang.Object elt)
                throws InvalidPositionException
Inserts an edge into this graph.
Specified by:
insertEdge in interface Graph
Parameters:
v1 - An endpoint of the edge.
v2 - An endpoint of the edge.
elt - Any Object to be associated with this edge.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

insertDirectedEdge

public Edge insertDirectedEdge(Vertex v1,
                               Vertex v2,
                               java.lang.Object elt)
                        throws InvalidPositionException
Inserts a directed edge into this graph.
Specified by:
insertDirectedEdge in interface Graph
Parameters:
v1 - The source of edge
v2 - The destination of the ege
elt - Any Object to be associated with this edge.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

removeVertex

public java.lang.Object removeVertex(Vertex v)
                              throws InvalidPositionException
Removes a vertex from this graph. Removes all edges incident on and incident from v.
Specified by:
removeVertex in interface Graph
Parameters:
v - The vertex to remove.
Returns:
The Object associated with v.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

removeEdge

public java.lang.Object removeEdge(Edge e)
                            throws InvalidPositionException
Removes an edge from this graph.
Specified by:
removeEdge in interface Graph
Parameters:
e - The edge to remove.
Returns:
the Object associated with the edge.
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

setDirectionFrom

public void setDirectionFrom(Edge e,
                             Vertex newOrigin)
                      throws InvalidEdgeException,
                             InvalidPositionException
Sets the direction of an edge away from a vertex.
Specified by:
setDirectionFrom in interface Graph
Parameters:
e - The edge to change.
newOrigin - a vertex of e, now the new origion of e
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

setDirectionTo

public void setDirectionTo(Edge e,
                           Vertex newDestination)
                    throws InvalidEdgeException,
                           InvalidPositionException
Sets the direction of an edge to a vertex.
Specified by:
setDirectionTo in interface Graph
Parameters:
e - The edge to change.
newDestination - a vertex of e, now the new destination of e
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph

makeUndirected

public void makeUndirected(Edge e)
                    throws InvalidEdgeException
Makes a directed edge undirected.
Specified by:
makeUndirected in interface Graph

reverseDirection

public void reverseDirection(Edge e)
                      throws InvalidEdgeException,
                             InvalidPositionException
Reverses the direction of an edge.
Specified by:
reverseDirection in interface Graph
Throws:
InvalidPositionException - if the vertex is invalid or incompatible with this Graph
InvalidEdgeException - if e is not directed