@Override public List<Node> getAdjacencies(Node node) { // special case when syntetic root if (topLeft != null) { if (node == root) { Node[] d = {topLeft, topRight}; return Arrays.asList(d); } if (node == topLeft || node == topRight) { List<Node> s = new ArrayList<>(source.getAdjacencies(node)); s.remove(node == topLeft ? topRight : topLeft); s.add(root); return s; } } return source.getAdjacencies(node); }
/** * Set <arg>parent</arg> as parent of <arg>node</arg>, and recursivly set parents for node subtree * (whose root is parent) * * @param node * @param parent */ private void setParent(Node node, Node parent) { parents.put(node, parent); for (Node adj : source.getAdjacencies(node)) { if (adj != parent && !(node == topLeft && adj == topRight) && !(node == topRight && adj == topLeft)) { setParent(adj, node); } } }
/** * Root tree at some internal node. * * @param source tree to root * @param root internal node to root at * @param intentUnrooted */ public RootedFromUnrooted( @Param(name = "source", description = "auto converted jebl2 parameter") Tree source, @Param(name = "root", description = "auto converted jebl2 parameter") Node root, @Param(name = "intentUnrooted", description = "auto converted jebl2 parameter") Boolean intentUnrooted) { this.source = source; this.root = root; this.intentUnrooted = intentUnrooted; topLeft = topRight = null; rootToLeft = rootToRight = 0.0; parents = new LinkedHashMap<>(); for (Node adj : source.getAdjacencies(root)) { setParent(adj, root); } }