public final class Vertex
extends java.lang.Object
implements java.lang.Comparable
| Modifier and Type | Field and Description |
|---|---|
private java.util.List |
m_dependencies
List of all direct dependent Vertices.
|
private java.lang.String |
m_name |
private java.lang.Object |
m_node |
private int |
m_order |
private boolean |
m_seen
Flag used to keep track of whether or not a given vertex has been
seen by the resolveOrder methods.
|
| Constructor and Description |
|---|
Vertex(java.lang.Object node)
A vertex wraps a node, which can be anything.
|
Vertex(java.lang.String name,
java.lang.Object node)
A vertex wraps a node, which can be anything.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDependency(Vertex v)
Add a dependecy to this Vertex.
|
int |
compareTo(java.lang.Object o)
Used in the sort algorithm to sort all the Vertices so that they respect
the ordinal they were given during the topological sort.
|
java.util.List |
getDependencies()
Get the list of dependencies.
|
java.lang.String |
getName()
Returns the name of the Vertex.
|
java.lang.Object |
getNode()
Get the wrapped node that this Vertex represents.
|
int |
getOrder()
Get the ordinal for this vertex.
|
void |
reset()
Reset the Vertex so that all the flags and runtime states are set back
to the original values.
|
void |
resolveOrder()
Recurse through the tree from this vertex assigning an order to each
and at the same time checking for any cyclic dependencies.
|
private int |
resolveOrder(java.lang.String path)
Recursively searches for cycles by travelling down the dependency lists
of this vertex, looking for the start vertex.
|
private final java.lang.String m_name
private final java.lang.Object m_node
private int m_order
private boolean m_seen
private final java.util.List m_dependencies
public Vertex(java.lang.Object node)
node - The wrapped node.public Vertex(java.lang.String name,
java.lang.Object node)
name - A name for the node which will be used to produce useful errors.node - The wrapped node.public void reset()
public java.lang.String getName()
public java.lang.Object getNode()
public void addDependency(Vertex v)
v - The vertex we depend on.public void resolveOrder()
throws CyclicDependencyException
CyclicDependencyException - If a cyclic dependency is discovered.private int resolveOrder(java.lang.String path)
throws CyclicDependencyException
path - The path to the Vertex. It is worth the load as it makes a
descriptive error message possible.CyclicDependencyException - If a cyclic dependency is discovered.public java.util.List getDependencies()
public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparableo - The other Vertex to compare withpublic int getOrder()