public class Graph
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<Node,java.util.List<Edge>> |
adjacency |
protected java.util.List<Edge> |
edges
Set of edges contained in this graph
|
protected boolean |
isDirected |
protected java.util.Set<Node> |
nodes |
protected java.util.Set<Node> |
sinks |
protected java.util.Set<Node> |
sources |
Constructor and Description |
---|
Graph()
Create an empty graph
|
Modifier and Type | Method and Description |
---|---|
void |
addSink(Node n) |
void |
addSource(Node n) |
protected void |
addToAdjacency(Node source,
Edge e)
Add target to the adjacency list of source
|
Edge |
createEdge(Node source,
Node target)
Add a new edge to the graph, connecting the given source and target
|
Node |
createNode(java.lang.String label) |
java.util.List<Edge> |
getAdjacency(Node n)
Get all nodes that are adjacent to n
|
java.util.Set<Node> |
getNodes()
Get all nodes of the graph
|
java.util.Set<Node> |
getSinks() |
java.util.Set<Node> |
getSources()
Get the source nodes of this graph
|
boolean |
isDirected() |
boolean |
isTwoTerminalGraph()
Determine if this graph has only a single source node and a single sink node.
|
void |
setDirected(boolean isDirected) |
java.lang.String |
toString() |
protected java.util.Set<Node> nodes
protected java.util.List<Edge> edges
protected java.util.Set<Node> sources
protected java.util.Set<Node> sinks
protected boolean isDirected
public Node createNode(java.lang.String label)
public Edge createEdge(Node source, Node target)
source
- the sourcetarget
- the targetpublic java.util.Set<Node> getNodes()
public void addSink(Node n)
public void addSource(Node n)
public java.util.Set<Node> getSources()
public java.util.Set<Node> getSinks()
public java.util.List<Edge> getAdjacency(Node n)
n
- the nodepublic boolean isDirected()
public void setDirected(boolean isDirected)
public boolean isTwoTerminalGraph()
protected void addToAdjacency(Node source, Edge e)
source
- the source nodetarget
- the target nodepublic java.lang.String toString()
toString
in class java.lang.Object