public class Digraph
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<DigraphEdge> |
digraphEdges |
protected java.util.ArrayList<DigraphNode> |
digraphNodes |
protected static java.lang.String |
EdgeClassName |
Constructor and Description |
---|
Digraph()
Initializes a new Digraph with empty lists of nodes and
edges.
|
Modifier and Type | Method and Description |
---|---|
DigraphEdge |
addEdgeFromNodeToNode(DigraphNode node1,
DigraphNode node2)
Adds a new edge of the appropriate DigraphEdge subclass
to connect two given nodes, provided the two nodes are
nodes of the receiver Digraph.
|
DigraphEdge |
addEdgeFromTo(int nodeIndex1,
int nodeIndex2)
Adds a new edge of the appropriate DigraphEdge subclass
to connect two given nodes indicated by their indices
(0, 1, 2, ... ) in the list of DigraphNodes for the Digraph.
|
DigraphNode |
addNode()
Adds a new node to the Digraph and returns it.
|
Digraph |
copyDigraph()
Returns a copy of the receiver Digraph,
without sharing of nodes or edges.
|
DigraphEdge |
edgeAt(int pos)
Returns the DigraphEdge at given position in the
list of edges; null if no such edge.
|
java.util.ArrayList<DigraphEdge> |
getEdges()
Returns the ArrayList of DigraphEdges in the Digraph
|
java.util.ArrayList<DigraphNode> |
getNodes()
Returns the ArrayList of DigraphNodes in the Digraph
|
boolean |
isCyclic()
Returns true of the Digraph has cycles; false if not
|
DigraphNode |
nodeAt(int pos)
Returns the DigraphNode at given position in the
list of nodes; null if no such node.
|
int |
numberOfEdges()
Returns the number of edges in the Digraph
|
int |
numberOfNodes()
Returns the number of nodes in the Digraph
|
DigraphEdge |
removeEdge(DigraphEdge aDigraphEdge)
Removes a given edge, provided it is in the Digraph.
|
DigraphNode |
removeNode(DigraphNode aDigraphNode)
Removes a given node, provided it is in the Digraph,
after first removing all edges in and out of it.
|
java.util.ArrayList<DigraphNode> |
sinks()
Returns an ArrayList containing the DigraphNodes in the Digraph
that have no outgoing edges.
|
java.util.ArrayList<DigraphNode> |
sources()
Returns an ArrayList containing the DigraphNodes in the Digraph
that have no incoming edges.
|
java.lang.String |
toString()
Returns a string that represents the Digraph in the following
form:
- the number of nodes in digraphNodes;
- a parenthesized list of edge representations,
each a parenthesized pair: (fromNodeNumber, toNodeNumber)
where fromNodeNumber and toNodeNumber are indices of nodes
in digraphNodes.
|
protected java.util.ArrayList<DigraphEdge> digraphEdges
protected java.util.ArrayList<DigraphNode> digraphNodes
protected static java.lang.String EdgeClassName
public Digraph()
public DigraphEdge addEdgeFromTo(int nodeIndex1, int nodeIndex2) throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
public DigraphEdge addEdgeFromNodeToNode(DigraphNode node1, DigraphNode node2) throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
node1
- the node that the edge is to go fromnode2
- the node that the edge is to go tojava.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
public DigraphNode addNode()
public Digraph copyDigraph() throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
public DigraphEdge edgeAt(int pos)
pos
- the index of the edge to be foundpublic java.util.ArrayList<DigraphEdge> getEdges()
public java.util.ArrayList<DigraphNode> getNodes()
public boolean isCyclic() throws java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
public DigraphNode nodeAt(int pos)
pos
- the index of the node to be foundpublic int numberOfEdges()
public int numberOfNodes()
public DigraphEdge removeEdge(DigraphEdge aDigraphEdge)
aDigraphEdge
- the edge to be removedpublic DigraphNode removeNode(DigraphNode aDigraphNode)
aDigraphNode
- the node to be removedpublic java.util.ArrayList<DigraphNode> sinks()
public java.util.ArrayList<DigraphNode> sources()
public java.lang.String toString()
toString
in class java.lang.Object