private int getMaxLevelOfParent(EntityNode node) { int max = -1; for (EntityNode parent : node.getParent()) { if (max < parent.getLevel()) { max = parent.getLevel(); } } return max; }
private void computeNodeLevel(ActionGraph actionGraph) { int max = actionGraph.getAllNodes().size(); int count = 0; while (true && count++ < max) { boolean noChange = true; for (EntityNode node : actionGraph.getAllNodes()) { int maxParentLevel = getMaxLevelOfParent(node); int toBeNodeLevel = maxParentLevel + 1; if (toBeNodeLevel > node.getLevel()) { node.setLevel(toBeNodeLevel); noChange = false; } } if (noChange) { break; } } }
@Override public int compare(EntityNode o1, EntityNode o2) { return o1.getLevel() - o2.getLevel(); }