dk.brics.xact.analysis.flowgraph
Class Graph<Nodetype,Edgetype>

java.lang.Object
  extended by dk.brics.xact.analysis.flowgraph.Graph<Nodetype,Edgetype>
Direct Known Subclasses:
FlowGraph

public class Graph<Nodetype,Edgetype>
extends Object

Generic directed multigraph.


Constructor Summary
Graph()
          Constructs an empty graph.
 
Method Summary
 void addAll(Graph<Nodetype,Edgetype> other)
          Adds all nodes and edges from another graph to this one.
 void addEdge(Nodetype from, Nodetype to, Edgetype data)
          Adds an edge between two nodes in the graph.
 void addEntry(Nodetype node)
          Marks an existing node as an entry node of the graph.
 void addNode(Nodetype node)
          Adds the given node to the graph.
 void clearEdges()
          Removes all edges.
 boolean containsNode(Nodetype node)
          Checks whether the graph contains the given node.
 Set<Nodetype> getEntries()
          Returns the set of entry points in the graph.
 Set<Edge<Nodetype,Edgetype>> getInEdges(Nodetype node)
          Returns the set of ingoing edges to the specified node.
 Set<Nodetype> getNodes()
          Returns the set of all nodes in the graph.
 int getNumberOfEdges()
          Returns the total number of edges.
 Set<Edge<Nodetype,Edgetype>> getOutEdges(Nodetype node)
          Returns the set of outgoing edges from the specified node.
 void removeEdge(Edge<Nodetype,Edgetype> edge)
          Removes an existing edge between two nodes in the graph.
 void removeEntry(Nodetype node)
          Removes an entry node of the graph.
 void removeInEdges(Nodetype node)
          Removes all ingoing edges from the given node.
 void removeNode(Nodetype node)
          Removes the given node from the graph.
 void removeOutEdges(Nodetype node)
          Removes all outgoing edges from the given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()
Constructs an empty graph.

Method Detail

addAll

public void addAll(Graph<Nodetype,Edgetype> other)
Adds all nodes and edges from another graph to this one.


addEdge

public void addEdge(Nodetype from,
                    Nodetype to,
                    Edgetype data)
Adds an edge between two nodes in the graph.

Throws:
NoSuchElementException - if either of the nodes does not exist in the graph

addEntry

public void addEntry(Nodetype node)
Marks an existing node as an entry node of the graph.

Throws:
NoSuchElementException - if the node does not exist

addNode

public void addNode(Nodetype node)
Adds the given node to the graph. If the node was already in the graph then nothing happens.


clearEdges

public void clearEdges()
Removes all edges.


containsNode

public boolean containsNode(Nodetype node)
Checks whether the graph contains the given node.


getEntries

public Set<Nodetype> getEntries()
Returns the set of entry points in the graph. It is preferrable to use addEntry(Object) and removeEntry(Object) instead of modifying the set directly.

Returns:
mutable reference to the set of entities

getInEdges

public Set<Edge<Nodetype,Edgetype>> getInEdges(Nodetype node)
Returns the set of ingoing edges to the specified node.

Parameters:
node - a node in the graph
Returns:
a set of edges. Should not be modified.

getNodes

public Set<Nodetype> getNodes()
Returns the set of all nodes in the graph.

Returns:
reference to the set of nodes. Should not be modified.

getNumberOfEdges

public int getNumberOfEdges()
Returns the total number of edges.


getOutEdges

public Set<Edge<Nodetype,Edgetype>> getOutEdges(Nodetype node)
Returns the set of outgoing edges from the specified node.

Parameters:
node - a node in the graph
Returns:
a set of edges. Should not be modified.

removeEdge

public void removeEdge(Edge<Nodetype,Edgetype> edge)
Removes an existing edge between two nodes in the graph.

Throws:
NoSuchElementException - if the edge does not exist

removeEntry

public void removeEntry(Nodetype node)
Removes an entry node of the graph.

Throws:
NoSuchElementException - if the node does not exist

removeInEdges

public void removeInEdges(Nodetype node)
Removes all ingoing edges from the given node.


removeNode

public void removeNode(Nodetype node)
Removes the given node from the graph. All edges to or from this node are also removed.

Throws:
NoSuchElementException - if the node does not exist in the graph

removeOutEdges

public void removeOutEdges(Nodetype node)
Removes all outgoing edges from the given node.



Copyright © 2005-2011 Aarhus University.