Package jadex.bridge.component
Class DependencyResolver<T>
- java.lang.Object
-
- jadex.bridge.component.DependencyResolver<T>
-
public class DependencyResolver<T> extends java.lang.Object
The dependency resolver can be used to find a valid execution order of elements with dependencies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DependencyResolver.NodeInfo<T>
Info object for a node.
-
Constructor Summary
Constructors Constructor Description DependencyResolver()
Create a new dependency resolver.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDependency(T a, T b)
Add a dependency that a depends on b.void
addNode(T node)
Add a node (without dependency).void
clear()
Clear the resolver.protected DependencyResolver.NodeInfo<T>
getNodeInfo(T node)
Get the node info for the node id.java.util.Set<T>
getNodeps()
Get the nodeps.java.util.Map<T,DependencyResolver.NodeInfo<T>>
getNodes()
Get the nodes.protected boolean
hasDependencies(T node)
Test if a node has dependencies.static void
main(java.lang.String[] args)
The main for testing.void
removeDependency(T a, T b)
Remove a dependency that a depends on b.java.util.List<T>
resolveDependencies(boolean keep)
Resolve the DAG and deliver a valid order of nodes.java.util.List<java.util.Set<T>>
resolveDependenciesWithLevel()
Resolve the DAG and deliver a valid order of nodes with sets of nodes for same levels.void
setNodeps(java.util.Set<T> nodeps)
The nodeps to set.void
setNodes(java.util.Map<T,DependencyResolver.NodeInfo<T>> nodes)
The nodes to set.
-
-
-
Field Detail
-
nodes
protected java.util.Map<T,DependencyResolver.NodeInfo<T>> nodes
The nodes with dependencies.
-
nodeps
protected java.util.Set<T> nodeps
The set of empty nodes.
-
-
Method Detail
-
addDependency
public void addDependency(T a, T b)
Add a dependency that a depends on b.- Parameters:
a
- Then source node.b
- The node the source depends on.
-
removeDependency
public void removeDependency(T a, T b)
Remove a dependency that a depends on b.- Parameters:
a
- Then source node.b
- The node the source depends on.
-
resolveDependencies
public java.util.List<T> resolveDependencies(boolean keep)
Resolve the DAG and deliver a valid order of nodes.- Returns:
- A valid list of nodes.
-
resolveDependenciesWithLevel
public java.util.List<java.util.Set<T>> resolveDependenciesWithLevel()
Resolve the DAG and deliver a valid order of nodes with sets of nodes for same levels.- Returns:
- A valid list of set of nodes.
-
addNode
public void addNode(T node)
Add a node (without dependency).- Parameters:
node
- The node id.
-
clear
public void clear()
Clear the resolver.
-
getNodeInfo
protected DependencyResolver.NodeInfo<T> getNodeInfo(T node)
Get the node info for the node id.- Parameters:
node
- The node id.- Returns:
- The node info.
-
hasDependencies
protected boolean hasDependencies(T node)
Test if a node has dependencies.- Returns:
- True, if dependencies exist.
-
getNodes
public java.util.Map<T,DependencyResolver.NodeInfo<T>> getNodes()
Get the nodes.- Returns:
- The nodes
-
setNodes
public void setNodes(java.util.Map<T,DependencyResolver.NodeInfo<T>> nodes)
The nodes to set.- Parameters:
nodes
- The nodes to set
-
getNodeps
public java.util.Set<T> getNodeps()
Get the nodeps.- Returns:
- The nodeps
-
setNodeps
public void setNodeps(java.util.Set<T> nodeps)
The nodeps to set.- Parameters:
nodeps
- The nodeps to set
-
main
public static void main(java.lang.String[] args)
The main for testing.
-
-