name.angoca.db2sa.core.graph.model
Class Graph

Package class diagram package Graph
java.lang.Object
  extended by name.angoca.db2sa.core.graph.model.Graph

public class Graph
extends Object

This class models the graph that represents the read grammar. The construction of the graph is done in two phases: add nodes, and associate node.

The first phase only permits to add nodes to the graph. This is done with the method addNode. Try to establish a relation between nodes is not permitted in this phase.

The second phase permits to establish relation between nodes, once they have been defined. In this phase is not possible to add more nodes.

In order to change the phase, the method 'firstPhaseFinished' has to be called. Once this method is called, is not possible to go back.

The method 'secondPhaseFinished' before to return the StartingNode, it checks the graph if it is stable and there are not inconsistencies. Also, at this phase, the extra nodes are added. The extra nodes include the help node and the about node.

This object is immutable, once it is created, their properties cannot be changed. This is the reason because there are not setter methods. The getters methods are for tests purposes and have a default visibility.

Control Version

Version:
1.4.2 2010-05-17
Author:
Andres Gomez Casanova (AngocA)

Constructor Summary
Graph(String graphName, boolean addExtraNodes)
          Creates a graph with a given name.
 
Method Summary
 void addNode(String nodeId, String nodeName, boolean reserved)
          Adds a new node in the graph.
 void addRelation(String parentId, String childId)
          Adds a relation between two nodes, giving the members of the relation, the parent and the child.
 void checkDuplicates()
          Checks the graph searching nodes that represents the same word for a common parent.
 boolean equals(Object obj)
           
 void firstPhaseFinished()
          This parameter change the state of the graph.
 String getName()
          Returns the name of the graph.
 StartingNode getStartingNode()
          Returns the StartingNode.
 int hashCode()
           
 void merge(Graph graph)
          Merge the current graph in the given graph.
 StartingNode secondPhaseFinished()
          Process the graph.
 void simplifyGraph()
          Simplify the graph, by merging nodes that represents the same tokens.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Graph

public Graph(String graphName,
             boolean addExtraNodes)
      throws ParameterNullException
Creates a graph with a given name. The name works as identifier when dealing with several graphs.

Parameters:
graphName - Name of this graph.
addExtraNodes - Determines if the graph has to include some extra predefined nodes.
Throws:
ParameterNullException - If the graph name is not given.
Method Detail

addNode

public void addNode(String nodeId,
                    String nodeName,
                    boolean reserved)
             throws AbstractGraphException
Adds a new node in the graph. The given parameters permit to build the node before to add it. This method does not include establishing the associations.

Parameters:
nodeId - Id of the node.
nodeName - Name of the node.
reserved - if the node represents a reserved word.
Throws:
AbstractGraphException - If the graph state is invalid, or if the graph name is invalid, or if the node id already exists in the graph.

addRelation

public void addRelation(String parentId,
                        String childId)
                 throws AbstractDB2SAException
Adds a relation between two nodes, giving the members of the relation, the parent and the child.

Parameters:
parentId - Id of the parent node.
childId - Id of the child node.
Throws:
AbstractDB2SAException - if the parent or the child do not exist in the set of nodes. Or if the state of the graph is invalid. Or when trying to make an invalid relation between two nodes. If a parameter is null.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

firstPhaseFinished

public void firstPhaseFinished()
                        throws AbstractDB2SAException
This parameter change the state of the graph. The first phase permits to add nodes but it does not permit to establish relation between them. The second phase permits to create associations between nodes when all the nodes are defined in the graph.

Throws:
AbstractDB2SAException - If there is a problem adding the extra associations.

getName

public String getName()
Returns the name of the graph.

Returns:
Graph's name.

getStartingNode

public StartingNode getStartingNode()
                             throws InvalidGraphStateException
Returns the StartingNode. This method can be executed only after the second phase has been finished (The graph has to be in Validated state.)

Returns:
StartingNode if the graph is validated..
Throws:
InvalidGraphStateException - If the graph is in an invalid state to call this method.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

merge

public void merge(Graph graph)
           throws AbstractDB2SAException
Merge the current graph in the given graph. The current one will be emptied.

Both graphs (this and the given one) has to be validated.

The given graph can't be the same.

Parameters:
graph - Graph that will have all the information of the current graph.
Throws:
AbstractDB2SAException - If there is a problem making the fusion between nodes.

secondPhaseFinished

public StartingNode secondPhaseFinished()
                                 throws AbstractDB2SAException
Process the graph. Checks the graph structure as part of the finalization of the second phase. Optionally, it adds the extra nodes, depending on the parameter when creating the graph, and finally it returns the startingNode.

Checks that there is not nodes that references to StartingNode. Also, that EndingNode does not reference any node.

Returns:
The startingNode of the graph.
Throws:
AbstractDB2SAException - When a node is detected that references the StartingNode. Or when a node is detected that if referenced by the EndingNode. Or if a node does not come from StartingNode. Or if a node does not go to EndingNode. Or if the first phase has not finished. Or if the graph is in an invalid state.

checkDuplicates

public void checkDuplicates()
                     throws DuplicatedNodeNameException
Checks the graph searching nodes that represents the same word for a common parent.

Throws:
DuplicatedNodeNameException - If a double node is found.

simplifyGraph

public void simplifyGraph()
                   throws AbstractDB2SAException
Simplify the graph, by merging nodes that represents the same tokens.

Throws:
AbstractDB2SAException - If there is a problem add when merging the nodes.

toString

public String toString()
Overrides:
toString in class Object


Andres Gomez Casanova (AngocA) 2009-2010 Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.