Example #1
0
 private void assignLevels(List<Node> topologicalOrder, LevelAssignmentDirection direction) {
   for (Node currentNode : topologicalOrder) {
     int nextLevel = direction.getNextLevel(currentNode);
     List<Node> relatedNodes = direction.getRelatedNodes(currentNode);
     if (!relatedNodes.isEmpty()) {
       for (Node relatedNode : relatedNodes) {
         if (direction.canResetLevel(relatedNode, nextLevel)) {
           relatedNode.setLevel(nextLevel);
         }
       }
     }
   }
 }
Example #2
0
 private void getTopologicalOrder(
     Node rootNode,
     LevelAssignmentDirection direction,
     Set<Node> visitedNodes,
     List<Node> topologicalOrder) {
   if (visitedNodes.contains(rootNode)) {
     return;
   }
   visitedNodes.add(rootNode);
   List<Node> relatedNodes = direction.getRelatedNodes(rootNode);
   if (!relatedNodes.isEmpty()) {
     for (Node relatedNode : relatedNodes) {
       getTopologicalOrder(relatedNode, direction, visitedNodes, topologicalOrder);
     }
   }
   topologicalOrder.add(rootNode);
 }