/** * Return the parent of this node. * * @return parent the parent TreeNode or null */ public TreeNode getParent() { if (incompingEdge == null) return null; return incompingEdge.getSource(); }
/** * Returns the parent connected with specified type or null * * @param type * @return parent of given type or null */ public MultiNode getParent(EdgeType type) { Edge<MultiNode> e = getEdgeToParent(type); return e != null ? e.getSource() : null; }
/** * returns true if this node is connected to the given edge */ public boolean containsEdge(E e) { if (e == null) return false; return e.getSource().equals(this) || e.getTarget().equals(this); }
public boolean equals(Object o) { if (o == null) return false; if (o instanceof Edge) { //if both edges are of type 'undirected', it doesn't matter what is source and what target if (this.getType().equals(EdgeType.UNDIRECTED) && ((Edge) o).getType().equals(EdgeType.UNDIRECTED)) { return ((Edge) o).getSource().equals(source) && ((Edge) o).getTarget().equals(target) || ((Edge) o).getSource().equals(target) && ((Edge) o).getTarget().equals(source); } else { return ((Edge) o).getSource().equals(source) && ((Edge) o).getTarget().equals(target); } } return false; }
/** * Check the edges source/target for this node and returns true if this * node contains the given edge as incoming or outgoing edge. */ public boolean containsEdge(Edge<MultiNode> e) { if (e.getSource() == this) { Edge e1 = incomingEdges.get(e.getType()); return (e1 != null && e1 == e); } else { ArrayList<Edge<MultiNode>> l = outgoingEdges.get(e.getType()); if (l != null) { return l.contains(e); } } return false; }
/** * Clears all edges and esures that edges are also removed from source or target nodes. */ public void clear() { // remove incoming edges for (Edge<MultiNode> e : incomingEdges.values()) { e.getSource().removeOutgoingEdge(e); } // remove outgoing Edges for (List<Edge<MultiNode>> l : outgoingEdges.values()) { for (Edge<MultiNode> edge : l) { edge.getTarget().removeIncomingEdge(edge); } } incomingEdges.clear(); outgoingEdges.clear(); }
public E addEdge(E e) { if (e.getSource().getIndex() < 0 || e.getTarget().getIndex() < 0) { throw new RuntimeException("One of the nodes connected by the new edge has a negative index, which means it is not associated to a graph !!!"); } e.getSource().addEdge(e); e.getTarget().addEdge(e); return e; }
public void removeEdge(E e) { if ( getVertex(e.getSource().getIndex()) == e.getSource() && getVertex(e.getTarget().getIndex()) == e.getTarget()) { e.getSource().removeEdge(e); e.getTarget().removeEdge(e); } else { throw new RuntimeException("Edge connects Vertices that are not contained in this graph!"); } }
/** * Clears the node. Removes all edges and null references. */ @SuppressWarnings("unchecked") public void clear() { if (incompingEdge != null) { incompingEdge.getSource().removeEdge(incompingEdge); incompingEdge = null; } if (edges != null) { for (Edge out : edges) { out.getTarget().removeEdge(out); } edges.clear(); } }
/** * Adds the edge as outgoing edge to the edges source and as incoming edge * to the edges target vertex. * * @param e the edge * @return the edge */ public Edge<MultiNode> addEdge(Edge<MultiNode> e) { e.getSource().addOutgoingEdge(e); e.getTarget().addIncomingEdge(e); return e; }
/** * removes the edge by calling <code> getSource().removeEdge()</code> and * <code>getTarget().removeEdge()</code> on the given edge. * * @param e */ protected void removeEdge(Edge<MultiNode> e) { e.getSource().removeEdge(e); e.getTarget().removeEdge(e); }
/** * Add an edge to this node. */ @SuppressWarnings("unchecked") public void addEdge(Edge e) { if (e.getSource() == this) { if (getEdge(e.getTarget()) == null) { edges.add(e); /* Fix #145 - we have to reset the level of all nodes below this one */ for (TreeNode node : this.depthFirstIterator()) { node.level = -1; } } } else { incompingEdge = e; level = -1; } }
public void removeEdge(E e) { removeEdge(e.getSource(), e.getTarget(), e.getType()); }
/** * 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; }
public static void reorderingBootstrapLabelsForRooting(Edge<TreeNode> edgeToReroot) { TreeNode outGroup = edgeToReroot.getTarget(); String startingLabel; //reordering inner labels for bootstrap Values if (outGroup.isInnerNode()) { startingLabel = outGroup.getLabel(); } else { startingLabel = edgeToReroot.getSource().getLabel(); } if (startingLabel != null) { moveUP(edgeToReroot, startingLabel); } }
TreeNode source = edge.getSource(); TreeNode target = edge.getTarget();