Class 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.
    • Field Detail

      • nodeps

        protected java.util.Set<T> nodeps
        The set of empty nodes.
    • Constructor Detail

      • DependencyResolver

        public DependencyResolver()
        Create a new dependency resolver.
    • 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.
      • 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.