salvo.jesus.graph
Class PathImpl

java.lang.Object
  extended by salvo.jesus.graph.GraphImpl
      extended by salvo.jesus.graph.PathImpl
All Implemented Interfaces:
java.io.Serializable, Graph, Path
Direct Known Subclasses:
CyclePathImpl, SimplePathImpl

public class PathImpl
extends GraphImpl
implements Path

An implementation of the Path interface that is a non-simple path. A non-simple path is a Path whereby vertices maybe repeated.

Author:
Jesus M. Salvo Jr.
See Also:
Serialized Form

Field Summary
(package private)  java.util.Stack vertexStack
          Stack of all the vertices in this Path.
 
Fields inherited from class salvo.jesus.graph.GraphImpl
addedgelistener, addvertexlistener, connectedSetS, edges, removeedgelistener, removevertexlistener, traversal, vertices
 
Constructor Summary
PathImpl()
          Createas an instance of PathImpl.
 
Method Summary
 void add(Vertex newVertex)
          Adds a Vertex into the Path.
 void addEdge(Edge edge)
          Adds an Edge into Path if and only if the vertexA property of the Edge being added is the last Vertex added to the path.
 Vertex getFirstVertex()
          Returns the first Vertex in the Path.
 Vertex getLastVertex()
          Returns the last Vertex in the Path.
 void remove()
          Removes the last Vertex that was added in the Path.
 void remove(Vertex v)
          Throws a NoSuchMethodException as this method is not directly supported by the Path.
 void removeEdge(Edge e)
          Throws a NoSuchMethodException as this method is not directly supported by the Path.
 void removeEdges(Vertex v)
          Throws a NoSuchMethodException as this method is not directly supported by the Path.
 java.lang.String toString()
          Returns a String representation of the Path.
 
Methods inherited from class salvo.jesus.graph.GraphImpl
addEdge, addGraphAddEdgeListener, addGraphAddVertexListener, addGraphRemoveEdgeListener, addGraphRemoveVertexListener, clone, cloneVertices, createEdge, getAdjacentVertices, getAdjacentVertices, getConnectedSet, getConnectedSet, getDegree, getDegree, getEdges, getTraversal, getVertices, getVerticesCount, getVerticesIterator, isConnected, mergeconnectedSet, removeGraphAddEdgeListener, removeGraphAddVertexListener, removeGraphRemoveEdgeListener, removeGraphRemoveVertexListener, setTraversal, traverse
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface salvo.jesus.graph.Graph
addEdge, addGraphAddEdgeListener, addGraphAddVertexListener, addGraphRemoveEdgeListener, addGraphRemoveVertexListener, cloneVertices, createEdge, getAdjacentVertices, getAdjacentVertices, getConnectedSet, getConnectedSet, getDegree, getDegree, getEdges, getTraversal, getVertices, getVerticesCount, getVerticesIterator, isConnected, mergeconnectedSet, removeGraphAddEdgeListener, removeGraphAddVertexListener, removeGraphRemoveEdgeListener, removeGraphRemoveVertexListener, setTraversal, traverse
 

Field Detail

vertexStack

java.util.Stack vertexStack
Stack of all the vertices in this Path.

Constructor Detail

PathImpl

public PathImpl()
Createas an instance of PathImpl. All this really does is call the ancestor's constructor GraphImpl, then initializes other internal variables.

Method Detail

getFirstVertex

public Vertex getFirstVertex()
Returns the first Vertex in the Path.

Specified by:
getFirstVertex in interface Path

getLastVertex

public Vertex getLastVertex()
Returns the last Vertex in the Path.

Specified by:
getLastVertex in interface Path

add

public void add(Vertex newVertex)
         throws java.lang.Exception
Adds a Vertex into the Path.

This will call Graph.add( Vertex ) only if the Vertex is not yet part of the Graph. Note that this will also automatically add an Edge from the last Vertex that was added to the this Vertex being added.

If adding this new Edge instance is not desired and you want to add an existing Edge instance instead ( i.e.: from an Edge in a Graph ), then you should call addEdge( Edge ) instead.

Specified by:
add in interface Graph
Overrides:
add in class GraphImpl
Parameters:
newvertex - Vertex to be added to the Path
Throws:
IllegalPathException
java.lang.Exception

remove

public void remove()
            throws java.lang.Exception
Removes the last Vertex that was added in the Path.

Specified by:
remove in interface Path
Throws:
java.lang.Exception

addEdge

public void addEdge(Edge edge)
             throws java.lang.Exception
Adds an Edge into Path if and only if the vertexA property of the Edge being added is the last Vertex added to the path.

Specified by:
addEdge in interface Graph
Overrides:
addEdge in class GraphImpl
Parameters:
edge - The edge to be added to the Graph.
Throws:
IllegalPathException - Thrown when the vertexA property of the Edge being added is not the last Vertex in the path.
java.lang.Exception

remove

public void remove(Vertex v)
            throws java.lang.Exception
Throws a NoSuchMethodException as this method is not directly supported by the Path. You should use the method remove() instead.

Specified by:
remove in interface Graph
Overrides:
remove in class GraphImpl
Throws:
java.lang.NoSuchMethodException
java.lang.Exception

removeEdge

public void removeEdge(Edge e)
                throws java.lang.Exception
Throws a NoSuchMethodException as this method is not directly supported by the Path. You are not allowed to directly remove an Edge of classes implementing the Path interface.

Specified by:
removeEdge in interface Graph
Overrides:
removeEdge in class GraphImpl
Parameters:
e - The Edge object to be removed.
Throws:
java.lang.NoSuchMethodException
java.lang.Exception

removeEdges

public void removeEdges(Vertex v)
                 throws java.lang.Exception
Throws a NoSuchMethodException as this method is not directly supported by the Path. You are not allowed to remove multiple Vertexs at once.

Specified by:
removeEdges in interface Graph
Overrides:
removeEdges in class GraphImpl
Parameters:
v - Vertex whose Edges are to be removed
Throws:
java.lang.NoSuchMethodException
java.lang.Exception

toString

public java.lang.String toString()
Returns a String representation of the Path.

Overrides:
toString in class GraphImpl
Returns:
String representation of the Graph