@SuppressWarnings("unchecked") public Edge<TreeNode> getEdge(Vertex oppositNode) { if (edges == null) { return null; } for (Edge<TreeNode> e : edges) { if (e.getOpposit(this) == oppositNode) return e; } return null; }
@SuppressWarnings("unchecked") public E getEdge(Vertex oppositNode, EdgeType type) { List<E> edges = adjList.get(type); if (edges != null) { for (E e : edges) { if (e.getOpposit((N) this) == oppositNode) { return e; } } } return null; }
public N next() { return e.next().getOpposit(n); }
@SuppressWarnings("unchecked") public Edge<MultiNode> getEdge(Vertex oppositNode, EdgeType type) { ArrayList<Edge<MultiNode>> l = outgoingEdges.get(type); if (l != null) { for (Edge edge : l) { if (edge.getOpposit(this) == oppositNode) return edge; } } // check for incoming edge Edge in = incomingEdges.get(type); if (in != null && in.getOpposit(oppositNode) == this) return in; // no edge found return null; }
public E getEdge(Vertex oppositNode) { for (E e : edges()) { if (e.getOpposit((N) this) == oppositNode) { return e; } } return null; }
/** * @return previous sibling of this node */ public TreeNode getPreviousSibling() { TreeNode p = getParent(); if (p == null) return null; TreeNode prev = null; for (Edge<TreeNode> oe : p.edges()) { if (oe.getOpposit(p) == this) { return prev; } prev = oe.getOpposit(p); } return null; }
/** * @return next sibling of this node */ public TreeNode getNextSibling() { TreeNode p = getParent(); if (p == null) return null; boolean returnNext = false; for (Edge<TreeNode> oe : p.edges()) { if (returnNext) return oe.getOpposit(p); if (oe.getOpposit(p) == this) { returnNext = true; } } return null; }
/** * clears edge lists. nothing done here */ public void clear() { for (E e : edges()) { e.getOpposit((N) this).removeEdge(e); } adjList.clear(); }
/** * Returns true if the given node is sibling of this node. * * @param node the other node * @return true if the other node is sibling of this node */ public boolean isNodeSibling(TreeNode node) { TreeNode p = getParent(); if (p == null) return false; for (Edge<TreeNode> oe : p.edges()) { if (oe.getOpposit(p) == this) return true; } return false; }
private N nextTovisit(N n) { if (n == null) { return null; } colors[n.getIndex()] = Color.GRAY; for (E e : n.edges()) { N v = e.getOpposit(n); if (colors[v.getIndex()] == Color.WHITE) { pis[v.getIndex()] = n; return v; } } colors[n.getIndex()] = Color.BLACK; return n; }
public MultiTree copy() { // System.out.println(" in copy " + this.edgeCount()); MultiTree copy = new MultiTree(); // do real array copy copy.edgeTypes = new EdgeType[edgeTypes.length]; System.arraycopy(edgeTypes, 0, copy.edgeTypes, 0, edgeTypes.length); copy.treeWeights = new double[treeWeights.length]; System.arraycopy(treeWeights, 0, copy.treeWeights, 0, treeWeights.length); // add all vertices to the copy Iterator<MultiNode> nodeIter = this.vertices().iterator(); while (nodeIter.hasNext()) { MultiNode node = nodeIter.next(); MultiNode copy_n = new MultiNode(); copy_n.setIndex(node.getIndex()); copy_n.setLabel(node.getLabel()); copy.addVertex(copy_n); } // add edges for (EdgeType type : edgeTypes) { Iterator<MultiNode> nodeIter2 = this.vertices().iterator(); while (nodeIter2.hasNext()) { MultiNode curr = nodeIter2.next(); // ArrayList<Edge> edges = new ArrayList<Edge>(); for (Edge<MultiNode> edge : curr.edges(type)) { copy.addEdge(curr.getIndex(), edge.getOpposit(curr).getIndex(), type).setWeight(edge.getWeight()); } } } return copy; }