public List<ModelNode> topologicalSort() {
        DependencyMap dependencyMap = new DependencyMap(modelNodes);
        Queue<ModelNode> unprocessed = new LinkedList<>();
        unprocessed.addAll(roots);
        List<ModelNode> sortedList = new ArrayList<>();
        while (!unprocessed.isEmpty()) {
            ModelNode sortedNode = unprocessed.remove();
            sortedList.add(sortedNode);
            for (ModelNode node : modelNodes) {
                if (dependencyMap.dependsOn(node, sortedNode)) {
                    dependencyMap.removeDependency(node, sortedNode);
                    if (!dependencyMap.hasDependencies(node)) {
                        unprocessed.add(node);
                    }
                }
            }
        }
        for (ModelNode node : modelNodes) {
            if (dependencyMap.hasDependencies(node)) {
                throw new IllegalArgumentException("Unable to sort graph because it contains cycles");
            }
        }
        return sortedList;
    }
Performs a topological sort ot the models stored in this graph. The algorithm is based on Kahn topological sort.

@return a sorted list of {@link com.yahoo.config.model.graph.ModelNode} in dependency order.
config-model/src/main/java/com/yahoo/config/model/graph/ModelGraph.java