|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sofya.graphs.Graph
public abstract class Graph
Class to represent a basic graph, constructed of a set of nodes connected by directed edges. Any specialized graph should be built by deriving from this class.
Field Summary | |
---|---|
protected java.util.List |
edges
The collection of edges in the graph. |
static int |
MATCH_INCOMING
For use with getEdges(Node,int,Edge[]) , specifies that
incoming edges to the node will be matched. |
static int |
MATCH_OUTGOING
For use with getEdges(Node,int,Edge[]) , specifies that
outgoing edges from the node will be matched. |
protected java.util.List |
nodes
The collection of nodes in the graph. |
Constructor Summary | |
---|---|
Graph()
|
Method Summary | |
---|---|
protected void |
addEdge(Edge e)
Adds an edge to the graph. |
protected void |
addNode(Node n)
Inserts a node into the graph. |
protected void |
clear()
Clears the graph, such that it has no nodes or edges. |
Edge |
getEdge(Node sourceNode,
Node sinkNode)
Gets an edge in the graph. |
int |
getEdgeCount()
Gets the total number of edges contained in the graph. |
Edge[] |
getEdges(Edge[] a)
Gets all of the edges in the graph, in the order in which they were added to the graph. |
Edge[] |
getEdges(Node n,
int matchType,
Edge[] a)
Gets either all the edges which originate on a given node or which are incident on a node. |
Edge[] |
getEdges(Node sourceNode,
Node sinkNode,
Edge[] a)
Gets all edges which have the given source and sink nodes. |
Node |
getNode(int nodeID)
Gets a node by index. |
int |
getNodeCount()
Gets the total number of nodes contained in the graph. |
Node |
getRootNode()
Gets the 'root' node of the graph, which is defined to be the node with ID 1. |
protected void |
removeEdge(Edge e)
Removes an edge from the graph. |
protected void |
removeNode(Node n)
Removes a node from the graph. |
java.lang.String |
toString()
Returns string representation of the graph, which is a list of the edges that constitute the graph. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.List nodes
protected java.util.List edges
public static final int MATCH_OUTGOING
getEdges(Node,int,Edge[])
, specifies that
outgoing edges from the node will be matched.
public static final int MATCH_INCOMING
getEdges(Node,int,Edge[])
, specifies that
incoming edges to the node will be matched.
Constructor Detail |
---|
public Graph()
Method Detail |
---|
protected void addNode(Node n)
n
- Node
to be inserted into the graph.public Node getNode(int nodeID)
nodeID
- ID of the node to be retrieved, where the first node in
the graph is indexed as 1 (one).
public Node getRootNode()
protected void removeNode(Node n)
n
- Node
to be removed from the graph.protected void addEdge(Edge e)
e
- Edge
to be added to the graph.protected void removeEdge(Edge e)
e
- Edge
to be removed from the graph.public Edge getEdge(Node sourceNode, Node sinkNode)
sourceNode
- Source node of the edge to be matched.sinkNode
- Sink node of the edge to be matched.
java.util.NoSuchElementException
- If a matching edge cannot be found in
the graph.public Edge[] getEdges(Edge[] a)
a
- Array which will be used to determine the runtime type
of the array returned by this method.
public Edge[] getEdges(Node sourceNode, Node sinkNode, Edge[] a)
Special explanatory note regarding CFGs: Under some
circumstances, it is possible for switch statements and
finally-block returns to have multiple edges which point to the
same successor node (e.g. multiple cases point to the same block or
multiple exceptions return to the same location after handling).
The getEdge(Node,Node)
method will only return the first
matching edge, which may be insufficient.
sourceNode
- Source node of matching edges.sinkNode
- Sink node of matching edges.a
- Array which will be used to determine the runtime type
of the array returned by this method.
java.util.NoSuchElementException
- If no matching edges can be found in
the graph.public Edge[] getEdges(Node n, int matchType, Edge[] a)
n
- Node for which associated edges will be returned.matchType
- Constant indicating whether edges which start on the
node or which end on the node are to be returned. Acceptable values
are MATCH_OUTGOING
and MATCH_INCOMING
.a
- Array which will be used to determine the runtime type
of the array returned by this method.
java.util.NoSuchElementException
- If no matching edges can be found in
the graph.public int getNodeCount()
public int getEdgeCount()
protected void clear()
public java.lang.String toString()
toString
in class java.lang.Object
Edge.toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |