net.ggtools.grand.graph
Class GraphImpl

java.lang.Object
  extended by net.ggtools.grand.graph.GraphImpl
All Implemented Interfaces:
Graph, NodeContainer
Direct Known Subclasses:
AntGraph

public class GraphImpl
extends java.lang.Object
implements Graph

Simple GraphImpl implementation.

Author:
Christophe Labouisse

Constructor Summary
GraphImpl(java.lang.String graphName)
          Creates a new named graph.
 
Method Summary
 Link createLink(java.lang.String linkName, Node startNode, Node endNode)
          Creates a new link between two nodes.
 Node createNode(java.lang.String nodeName)
          Creates a new Node.
 Node createNode(SubGraph subGraph, java.lang.String nodeName)
          Creates a new Node in a specific graph.
 SubGraph createSubGraph(java.lang.String subGraphName)
          Creates a new subgraph in the graph.
protected  GraphElementFactory getFactory()
          Returns the current element factory creating one if none exists yet.
 java.lang.String getName()
          Returns the graph's name.
 Node getNode(java.lang.String nodeName)
          Find a node from its name.
 java.util.Iterator getNodes()
          Get the nodes contained in the graph.
 Node getStartNode()
          Returns the start node of the graph.
 SubGraph getSubGraph(java.lang.String subGraphName)
          Find a subgraph from its name.
 java.util.Iterator getSubgraphs()
          Get the nodes contained in the graph.
 boolean hasNode(java.lang.String nodeName)
          Checks if the graph has a node with a specific name.
 boolean hasSubGraph(java.lang.String subGraphName)
          Checks if the graph has a subgraph with a specific name.
 void setStartNode(Node node)
          Sets the graph starting node.
protected  void unlinkNode(Node node)
          Remove all links starting from or ending to the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphImpl

public GraphImpl(java.lang.String graphName)
Creates a new named graph.

Parameters:
graphName - name for the new graph.
Method Detail

createLink

public Link createLink(java.lang.String linkName,
                       Node startNode,
                       Node endNode)
Creates a new link between two nodes. Unlike createNode(String), this method do not require the link's name to be unique or not null. Both nodes should be not null.

Specified by:
createLink in interface Graph
Parameters:
linkName - the new link name, can be null
graphStartNode - start node
endNode - end node
Returns:
new link

createNode

public Node createNode(java.lang.String nodeName)
                throws DuplicateElementException
Creates a new Node. The object's name must not be null and must be unique within the graph.

Specified by:
createNode in interface Graph
Parameters:
nodeName - new node's name
Returns:
a new Node.
Throws:
DuplicateElementException - if there is already a node with the same name.

createNode

public Node createNode(SubGraph subGraph,
                       java.lang.String nodeName)
                throws DuplicateElementException
Description copied from interface: Graph
Creates a new Node in a specific graph. The object's name must not be null and must be unique within the subgraph.

Specified by:
createNode in interface Graph
Parameters:
subGraph - the subgraph to place the node in.
nodeName - new node's name
Returns:
a new Node.
Throws:
DuplicateElementException - if there is already a node with the same name.

createSubGraph

public SubGraph createSubGraph(java.lang.String subGraphName)
                        throws DuplicateElementException
Description copied from interface: Graph
Creates a new subgraph in the graph. The subgraph name must not be null and must be unique within the graph.

Specified by:
createSubGraph in interface Graph
Parameters:
subGraphName - new subgraph name.
Returns:
a new SubGraph.
Throws:
DuplicateElementException - if a sub graph with the same name already exists in the graph.

getName

public final java.lang.String getName()
Returns the graph's name.

Specified by:
getName in interface Graph
Returns:
graph's name.

getNode

public Node getNode(java.lang.String nodeName)
Description copied from interface: NodeContainer
Find a node from its name.

Specified by:
getNode in interface NodeContainer
Parameters:
nodeName - name of the node to find.
Returns:
the node or null if not found.

getNodes

public java.util.Iterator getNodes()
Description copied from interface: NodeContainer
Get the nodes contained in the graph. The implementing class should garantee that the Iterator will only returns object implementing the Node interface. The returned iterator should implement the optional Iterator.remove()method in order to allow the filters to remove nodes.

Specified by:
getNodes in interface NodeContainer
Returns:
an iterator to the graph's nodes.

getStartNode

public Node getStartNode()
Returns the start node of the graph. If no such node is defined, null will be returned.

Specified by:
getStartNode in interface Graph
Returns:
start node

getSubGraph

public SubGraph getSubGraph(java.lang.String subGraphName)
Description copied from interface: Graph
Find a subgraph from its name.

Specified by:
getSubGraph in interface Graph
Parameters:
subGraphName - name of the subgraph to find.
Returns:
the subgraph or null if not found.

getSubgraphs

public java.util.Iterator getSubgraphs()
Description copied from interface: Graph
Get the nodes contained in the graph. The implementing class should garantee that the Iterator will only returns object implementing the Node interface. The returned iterator should implement the optional Iterator.remove()method in order to allow the filters to remove nodes.

Specified by:
getSubgraphs in interface Graph
Returns:
an iterator to the graph's nodes.

hasNode

public boolean hasNode(java.lang.String nodeName)
Description copied from interface: NodeContainer
Checks if the graph has a node with a specific name.

Specified by:
hasNode in interface NodeContainer
Parameters:
nodeName - node to search.
Returns:
true if the graph contains a node called nodeName.

hasSubGraph

public boolean hasSubGraph(java.lang.String subGraphName)
Description copied from interface: Graph
Checks if the graph has a subgraph with a specific name.

Specified by:
hasSubGraph in interface Graph
Parameters:
subGraphName - subgraph to search.
Returns:
true if the graph contains a subgraph called nodeName.

setStartNode

public void setStartNode(Node node)
Sets the graph starting node.

Specified by:
setStartNode in interface Graph
Parameters:
node - to be marked as the starting node of the graph.

getFactory

protected GraphElementFactory getFactory()
Returns the current element factory creating one if none exists yet. This method can be overriden to use a custom factory.

Returns:
the element factory.

unlinkNode

protected void unlinkNode(Node node)
Remove all links starting from or ending to the node. This method do not remove the node from nodeList.

Parameters:
node - node to remove from the links.


Copyright © 2004-2005 ggTools. All Rights Reserved.