Package com.alexmerz.graphviz.objects
Class Graph
- java.lang.Object
-
- com.alexmerz.graphviz.objects.Graph
-
public class Graph extends Object
This class represents a graph. A Graph contains Nodes, Edges and Subgraphs
-
-
Field Summary
Fields Modifier and Type Field Description static intDIRECTEDConstant for an directed graphstatic intUNDIRECTEDConstant for an undirected graph
-
Constructor Summary
Constructors Constructor Description Graph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(String key, String value)Adds a graph attribute.voidaddEdge(Edge e)Adds an Edge object to the graphvoidaddGenericEdgeAttribute(String key, String value)Sets a generic attribute for all edges of this graph.voidaddGenericGraphAttribute(String key, String value)Sets a generic attribute for clusters of this graph.voidaddGenericNodeAttribute(String key, String value)Sets a generic attribute for all nodes of this graph This attributes are NOT additionally stored in the Node objects.voidaddNode(Node n)Adds a Node object to the graphvoidaddSubgraph(Graph graph)Adds a sub graph to a graphNodefindNode(Id id)Tries to find a node of a Graph depending on the given Id object.StringgetAttribute(String key)Returns an attribute of the Graph or null if not found.Hashtable<String,String>getAttributes()Returns all attributes of the graph.ArrayList<Edge>getEdges()Returns all edges of this graph.StringgetGenericEdgeAttribute(String key)Returns a generic attribute of an edgeStringgetGenericGraphAttribute(String key)Returns a generic attribute of the clusters in the graphStringgetGenericNodeAttribute(String key)Returns a generic attribute of a nodeIdgetId()Returns the Id object to the GraphArrayList<Node>getNodes(boolean thisOnly)Returns all Nodes of the graph.ArrayList<Graph>getSubgraphs()Returns a list of all sub graphs.intgetType()Returns the type of the graphbooleanisStrict()Returns wether the graph is strict or notvoidsetId(Id id)Sets the Id object for this graphvoidsetStrict(boolean isStrict)Sets if the graph is strict or not.voidsetType(int type)Sets the type of the graphStringtoString()Returns a String representation of the graph
-
-
-
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
-
-
Method Detail
-
addGenericEdgeAttribute
public void addGenericEdgeAttribute(String key, 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 namevalue- the attribute value
-
getGenericEdgeAttribute
public String getGenericEdgeAttribute(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(String key, 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 namevalue- the attribute value
-
getGenericGraphAttribute
public String getGenericGraphAttribute(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(String key, 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 namevalue- the attribute value
-
getGenericNodeAttribute
public String getGenericNodeAttribute(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(String key, String value)
Adds a graph attribute. This attributes are NOT inherited to the attributes of sub graphs.- Parameters:
key- the name of the attributevalue- the value of the attribute
-
getAttribute
public String getAttribute(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 String toString()
Returns a String representation of the graph
-
getSubgraphs
public 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 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 Hashtable<String,String> getAttributes()
Returns all attributes of the graph.- Returns:
- the attributes
-
-