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); } } } } }
public NodeLevelMap apply(ValueStreamMap valueStreamMap) { Node rootNode = valueStreamMap.getCurrentPipeline() != null ? valueStreamMap.getCurrentPipeline() : valueStreamMap.getCurrentMaterial(); rootNode.setLevel(0); if (!rootNode.getParents().isEmpty()) { assignLevelsToDependencies(rootNode, new Upstream()); } if (!rootNode.getChildren().isEmpty()) { assignLevelsToDependencies(rootNode, new Downstream()); } return levelToNodesMap(valueStreamMap); }
@Override public boolean canResetLevel(Node node, int nextLevel) { return nextLevel > node.getLevel(); }
@Override public int getNextLevel(Node node) { return node.getLevel() + 1; }
@Override public List<Node> getRelatedNodes(Node node) { return node.getChildren(); }
@Override public List<Node> getRelatedNodes(Node node) { return node.getParents(); }