public Map<Integer, BCNNode> getResult() { //compare(compareTree); HashMap<Integer, BCNNode> sscores = new HashMap<Integer, BCNNode>(); for (TreeNode n : sourceScrores.keySet()) { BCNScore score = sourceScrores.get(n); sscores.put(n.getIndex(), new BCNNode(score.getScore(), score.getTargetIndex())); } return sscores; }
/** * Adds a node to the tree. */ public int addVertex(TreeNode n) { n.setGraph(this); nodes.put(n); return n.getIndex(); }
/** * Create a new {@link Tree} that represents the subtree of this tree rooted at the given * node and removes this subtree from this tree. The returned tree is a new tree that contains the original {@link TreeNode}s of this tree. * <p> * If this tree does not contain the given node, null is returned. * * @param n the root node of the subtree * @return subtree rooted at the given node or null */ public List<TreeNode> removeSubtree(TreeNode n) { if (n == null) throw new NullPointerException(); if (nodes.get(n.getIndex()) != n) { return null; } LinkedList<TreeNode> nodes = new LinkedList<>(); for (TreeNode node : n.depthFirstIterator()) { nodes.push(node); this.nodes.remove(node.getIndex()); } if (n.incompingEdge != null) { n.incompingEdge.getSource().removeEdge(n.incompingEdge); n.incompingEdge = null; } nodes.push(n); this.nodes.remove(n.getIndex()); return nodes; }
/** * Clones this node. * * @return node the new node */ public TreeNode cloneNode() { TreeNode n = new TreeNode(); n.setLabel(getLabel()); n.setIndex(getIndex()); return n; }
s.setTargetIndex(bcnNode.getIndex());
/** * Create a new {@link Tree} that represents the subtree of this tree rooted at the given * node. The returned tree is a new tree that contains clones of the {@link TreeNode}s of this tree. * The node copies are created using {@link TreeNode#cloneNode()} and are * new instances, so you will not have object equality ( n != n.cloneNode() ). Node equality using * {@link TreeNode#equals(Object)} will work at least for labeled nodes (because the labels are compared), but * for performance reasons we do not do deep checks. * <p> * If this tree does not contain the given node, null is returned. * * @param n the root node of the subtree * @return subtree rooted at the given node or null */ public Tree getSubtree(TreeNode n) { if (n == null) throw new NullPointerException(); if (nodes.get(n.getIndex()) != n) { return null; } Tree r = new Tree(); r.setName(getName()); TreeNode root = n.cloneNode(); root.setIndex(-1); // reset index r.addVertex(root); r.setRoot(root); hangIn(root, n, r); return r; }
score.setScore(r.getIndex());