T - node typepublic class DAGMutableGraph<T extends TBase> extends java.lang.Object implements MutableGraph<T>
| Constructor and Description |
|---|
DAGMutableGraph() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addNode(T node)
Adds
node if it is not already present. |
boolean |
allowsSelfLoops()
Returns true if this graph allows self-loops (edges that connect a node to itself).
|
protected boolean |
checkCycle(T origin,
T target)
check if adding this edge to the graph creates an cycle
|
T |
getNodeById(java.lang.String id)
returns the node which has the given Id or null if no such node exsists
|
boolean |
isDirected()
Returns true if the edges in this graph are directed.
|
java.util.Set<T> |
nodes() |
java.util.Set<T> |
predecessors(T node)
Returns all nodes in this graph adjacent to
node which can be reached by traversing
node's incoming edges against the direction (if any) of the edge. |
boolean |
putEdge(T orgin,
T target)
Adds an edge connecting
nodeU to nodeV if one is not already present. |
boolean |
removeEdge(T origin,
T target)
Removes the edge connecting
nodeU to nodeV, if it is present. |
boolean |
removeNode(T node)
Removes
node if it is present; all edges incident to node will also be removed. |
java.util.Set<T> |
successors(T node)
Returns all nodes in this graph adjacent to
node which can be reached by traversing
node's outgoing edges in the direction (if any) of the edge. |
public boolean addNode(T node)
MutableGraphnode if it is not already present.
Nodes must be unique, just as Map keys must be. They must also be non-null.
addNode in interface MutableGraph<T extends TBase>true if the graph was modified as a result of this callpublic boolean putEdge(T orgin, T target)
MutableGraphnodeU to nodeV if one is not already present.
If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If nodeU and nodeV are not already present in this graph, this method will
silently add nodeU and nodeV to the graph.
putEdge in interface MutableGraph<T extends TBase>true if the graph was modified as a result of this callpublic java.util.Set<T> nodes()
nodes in interface MutableGraph<T extends TBase>public boolean removeNode(T node)
MutableGraphnode if it is present; all edges incident to node will also be removed.removeNode in interface MutableGraph<T extends TBase>true if the graph was modified as a result of this callpublic boolean removeEdge(T origin, T target)
MutableGraphnodeU to nodeV, if it is present.removeEdge in interface MutableGraph<T extends TBase>true if the graph was modified as a result of this callpublic java.util.Set<T> successors(T node)
MutableGraphnode which can be reached by traversing
node's outgoing edges in the direction (if any) of the edge.successors in interface MutableGraph<T extends TBase>public java.util.Set<T> predecessors(T node)
MutableGraphnode which can be reached by traversing
node's incoming edges against the direction (if any) of the edge.predecessors in interface MutableGraph<T extends TBase>public boolean isDirected()
MutableGraphisDirected in interface MutableGraph<T extends TBase>public T getNodeById(java.lang.String id)
MutableGraphgetNodeById in interface MutableGraph<T extends TBase>id - the id of the node to returnprotected boolean checkCycle(T origin, T target)
origin - origin of the edge being addedtarget - target of the edge being addedpublic boolean allowsSelfLoops()
MutableGraphIllegalArgumentException.allowsSelfLoops in interface MutableGraph<T extends TBase>