com.alexmerz.graphviz.objects
Class Graph

java.lang.Object
  extended by com.alexmerz.graphviz.objects.Graph

public class Graph
extends java.lang.Object

This class represents a graph. A Graph contains Nodes, Edges and Subgraphs

Version:
$Id: Graph.java,v 1.4 2006/03/27 01:54:17 Alexander Exp $
Author:
Alexander

Field Summary
static int DIRECTED
          Constant for an directed graph
static int UNDIRECTED
          Constant for an undirected graph
 
Constructor Summary
Graph()
           
 
Method Summary
 void addAttribute(java.lang.String key, java.lang.String value)
          Adds a graph attribute.
 void addEdge(Edge e)
          Adds an Edge object to the graph
 void addGenericEdgeAttribute(java.lang.String key, java.lang.String value)
          Sets a generic attribute for all edges of this graph.
 void addGenericGraphAttribute(java.lang.String key, java.lang.String value)
          Sets a generic attribute for clusters of this graph.
 void addGenericNodeAttribute(java.lang.String key, java.lang.String value)
          Sets a generic attribute for all nodes of this graph This attributes are NOT additionally stored in the Node objects.
 void addNode(Node n)
          Adds a Node object to the graph
 void addSubgraph(Graph graph)
          Adds a sub graph to a graph
 Node findNode(Id id)
          Tries to find a node of a Graph depending on the given Id object.
 java.lang.String getAttribute(java.lang.String key)
          Returns an attribute of the Graph or null if not found.
 java.util.Hashtable<java.lang.String,java.lang.String> getAttributes()
          Returns all attributes of the graph.
 java.util.ArrayList<Edge> getEdges()
          Returns all edges of this graph.
 java.lang.String getGenericEdgeAttribute(java.lang.String key)
          Returns a generic attribute of an edge
 java.lang.String getGenericGraphAttribute(java.lang.String key)
          Returns a generic attribute of the clusters in the graph
 java.lang.String getGenericNodeAttribute(java.lang.String key)
          Returns a generic attribute of a node
 Id getId()
          Returns the Id object to the Graph
 java.util.ArrayList<Node> getNodes(boolean thisOnly)
          Returns all Nodes of the graph.
 java.util.ArrayList<Graph> getSubgraphs()
          Returns a list of all sub graphs.
 int getType()
          Returns the type of the graph
 boolean isStrict()
          Returns wether the graph is strict or not
 void setId(Id id)
          Sets the Id object for this graph
 void setStrict(boolean isStrict)
          Sets if the graph is strict or not.
 void setType(int type)
          Sets the type of the graph
 java.lang.String toString()
          Returns a String representation of the graph
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNDIRECTED

public static final int UNDIRECTED
Constant for an undirected graph

See Also:
Constant Field Values

DIRECTED

public static final int DIRECTED
Constant for an directed graph

See Also:
Constant Field Values
Constructor Detail

Graph

public Graph()
Method Detail

addGenericEdgeAttribute

public void addGenericEdgeAttribute(java.lang.String key,
                                    java.lang.String value)
Sets a generic attribute for all edges of this graph. This attributes are NOT additionally stored in the Edge objects.

Parameters:
key - the attribute name
value - the attribute value

getGenericEdgeAttribute

public java.lang.String getGenericEdgeAttribute(java.lang.String key)
Returns a generic attribute of an edge

Parameters:
key - the attribute name
Returns:
the value of the attribute or null, if the attribute does not exist.

addGenericGraphAttribute

public void addGenericGraphAttribute(java.lang.String key,
                                     java.lang.String value)
Sets a generic attribute for clusters of this graph. This attributes are NOT additionally stored in the Edge objects.

Parameters:
key - the attribute name
value - the attribute value

getGenericGraphAttribute

public java.lang.String getGenericGraphAttribute(java.lang.String key)
Returns a generic attribute of the clusters in the graph

Parameters:
key - the attribute name
Returns:
the value of the attribute or null, if the attribute does not exist.

addGenericNodeAttribute

public void addGenericNodeAttribute(java.lang.String key,
                                    java.lang.String value)
Sets a generic attribute for all nodes of this graph This attributes are NOT additionally stored in the Node objects.

Parameters:
key - the attribute name
value - the attribute value

getGenericNodeAttribute

public java.lang.String getGenericNodeAttribute(java.lang.String key)
Returns a generic attribute of a node

Parameters:
key - the attribute name
Returns:
the value of the attribute or null, if the attribute does not exist.

addAttribute

public void addAttribute(java.lang.String key,
                         java.lang.String value)
Adds a graph attribute. This attributes are NOT inherited to the attributes of sub graphs.

Parameters:
key - the name of the attribute
value - the value of the attribute

getAttribute

public java.lang.String getAttribute(java.lang.String key)
Returns an attribute of the Graph or null if not found.

Parameters:
key - the name of the attribute
Returns:
the value of the attribute

addNode

public void addNode(Node n)
Adds a Node object to the graph

Parameters:
n - the Node Object to add

addEdge

public void addEdge(Edge e)
Adds an Edge object to the graph

Parameters:
e - the Edge object to add

getId

public Id getId()
Returns the Id object to the Graph

Returns:
the Id object

setId

public void setId(Id id)
Sets the Id object for this graph

Parameters:
id -

getType

public int getType()
Returns the type of the graph

Returns:
the type of the graph
See Also:
DIRECTED, UNDIRECTED

setType

public void setType(int type)
Sets the type of the graph

Parameters:
type - the type of the graph
See Also:
DIRECTED, UNDIRECTED

isStrict

public boolean isStrict()
Returns wether the graph is strict or not

Returns:
the static state

setStrict

public void setStrict(boolean isStrict)
Sets if the graph is strict or not.

Parameters:
isStrict -

toString

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

Overrides:
toString in class java.lang.Object
Returns:
the string representation

getSubgraphs

public java.util.ArrayList<Graph> getSubgraphs()
Returns a list of all sub graphs.

Returns:
the subgraphs

addSubgraph

public void addSubgraph(Graph graph)
Adds a sub graph to a graph

Parameters:
graph -

findNode

public Node findNode(Id id)
Tries to find a node of a Graph depending on the given Id object.

Parameters:
id - the id object to identify the node
Returns:
the node or nulll if not found

getNodes

public java.util.ArrayList<Node> getNodes(boolean thisOnly)
Returns all Nodes of the graph. If the graph contains subgraphs, you can use the thisOnly parameter to decide if nodes defined in subgraphs should be added to the list also.

Parameters:
thisOnly - if true, also include nodes in subgraphs also, else exclude them
Returns:
the nodes of the graph

getAttributes

public java.util.Hashtable<java.lang.String,java.lang.String> getAttributes()
Returns all attributes of the graph.

Returns:
the attributes

getEdges

public java.util.ArrayList<Edge> getEdges()
Returns all edges of this graph.

Returns:
a list of Edge objects