salvo.jesus.graph
Class CyclePathImpl

java.lang.Object
  extended by salvo.jesus.graph.GraphImpl
      extended by salvo.jesus.graph.PathImpl
          extended by salvo.jesus.graph.CyclePathImpl
All Implemented Interfaces:
java.io.Serializable, CyclePath, Graph, Path, SimplePath

public class CyclePathImpl
extends PathImpl
implements CyclePath

Implementation of CyclePath that ensures that the first and last vertices in the Path forms a cycle.

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

Field Summary
private static java.lang.String CYCLE_PATH_ALREADY_CLOSED
           
(package private)  boolean isPathClosed
          Reference to whether we have
(package private)  boolean lastVertexFormedCycle
          Reference if the last Vertex added to the Path formed a cycle.
(package private)  boolean lastVertexFormedNonSimplePath
          Reference if the last Vertex added to the Path made the path non-simple.
 
Fields inherited from class salvo.jesus.graph.PathImpl
vertexStack
 
Fields inherited from class salvo.jesus.graph.GraphImpl
addedgelistener, addvertexlistener, connectedSetS, edges, removeedgelistener, removevertexlistener, traversal, vertices
 
Constructor Summary
CyclePathImpl()
          Creates an instance of CyclePathImpl.
 
Method Summary
 void add(Vertex newVertex)
          Adds a Vertex into the Path.
 void addEdge(Edge edge)
          Adds an Edge into Path.
 void closeCycle()
          Method to be called indicating that the Path has been fully specified.
 void remove()
          Removes the last Vertex that was added in the Path.
private  void setFlags(Vertex newVertex)
          Sets the stastus of the flags depending on what will be the effect should a specified Vertex is added to the CyclePath.
private  void validatePath()
          Checks the status of the flags and raise an error if required.
 
Methods inherited from class salvo.jesus.graph.PathImpl
getFirstVertex, getLastVertex, remove, removeEdge, removeEdges, toString
 
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.Path
getFirstVertex, getLastVertex
 
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, remove, removeEdge, removeEdges, removeGraphAddEdgeListener, removeGraphAddVertexListener, removeGraphRemoveEdgeListener, removeGraphRemoveVertexListener, setTraversal, traverse
 

Field Detail

isPathClosed

boolean isPathClosed
Reference to whether we have


lastVertexFormedNonSimplePath

boolean lastVertexFormedNonSimplePath
Reference if the last Vertex added to the Path made the path non-simple.


lastVertexFormedCycle

boolean lastVertexFormedCycle
Reference if the last Vertex added to the Path formed a cycle.


CYCLE_PATH_ALREADY_CLOSED

private static final java.lang.String CYCLE_PATH_ALREADY_CLOSED
See Also:
Constant Field Values
Constructor Detail

CyclePathImpl

public CyclePathImpl()
Creates an instance of CyclePathImpl.

Method Detail

add

public void add(Vertex newVertex)
         throws java.lang.Exception
Adds a Vertex into the Path. The check whether or not the resulting Path is still simple and non-cycle is done on subsequent calls to add( Vertex ) or when closeCycle() is called.

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 PathImpl
Parameters:
newvertex - Vertex to be added to the Path
Throws:
IllegalPathException - See the error message that comes with the Exception generated.
java.lang.Exception

addEdge

public void addEdge(Edge edge)
             throws java.lang.Exception
Adds an Edge into Path. The check whether or not the resulting Path is still simple and non-cycle is done on subsequent calls to add( Vertex ) or when closeCycle() is called.

Specified by:
addEdge in interface Graph
Overrides:
addEdge in class PathImpl
Parameters:
edge - The edge to be added to the Graph.
Throws:
IllegalPathException - See the error message that comes with the Exception generated.
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
Overrides:
remove in class PathImpl
Throws:
java.lang.Exception

closeCycle

public void closeCycle()
                throws IllegalPathException
Method to be called indicating that the Path has been fully specified. Implementations of this method should therefore check that the Path is indeed a Cycle.

Specified by:
closeCycle in interface CyclePath
Throws:
IllegalPathException - Thrown when the CyclePath is already closed or is being closed but is not a cycle.

validatePath

private void validatePath()
                   throws IllegalPathException
Checks the status of the flags and raise an error if required. This method should only be called when the CyclePath is not yet closed or not being closed.

Throws:
IllegalPathException

setFlags

private void setFlags(Vertex newVertex)
Sets the stastus of the flags depending on what will be the effect should a specified Vertex is added to the CyclePath.

Parameters:
newVertex - The Vertex that is intended to be added to the CyclePath.