/** * @see prefuse.data.Node#getParent() */ public Node getParent() { return m_graph.getSpanningTree().getParent(this); }
/** * @see prefuse.data.Node#getParent() */ public Node getParent() { return m_graph.getSpanningTree().getParent(this); }
/** * Get the child index (order number of the child) for the given parent * node id and child node id. * @param parent the parent node id (node table row number) * @param child the child node id (node table row number) * @return the index of the child, or -1 if the given child node is not * actually a child of the given parent node, or either node is * invalud. */ public int getChildIndex(int parent, int child) { if ( getParent(child) != parent ) return -1; return m_links.getInt(child, CHILDINDEX); }
/** * Get the depth of the given node id in the tree. * @param node a node id (node table row number) * @return the depth of the node in tree. The root node * is at a depth level of 0, with each child at a greater * depth level. -1 is returned if the input node id is not * in the tree. */ public int getDepth(int node) { if ( !getNodeTable().isValidRow(node) ) return -1; int depth = 0; if ( node!=m_root && getParent(node) < 0 ) return -1; for ( int i=node; i!=m_root && i>=0; ++depth, i=getParent(i) ); return depth; }
/** * Get a node's parent node * @param n the child node * @return the parent node, or null if there is no parent */ public Node getParent(Node n) { int p = getParent(n.getRow()); return ( p < 0 ? null : getNode(p) ); }
/** * Get the node id of the previous sibling of the given node id. * @param node a node id (node table row number) * @return the node id of the previous sibling, or -1 if there * is no previous sibling. */ public int getPreviousSiblingRow(int node) { int p = getParent(node); if ( p < 0 ) return -1; int[] links = (int[])m_links.get(p, OUTLINKS); int idx = m_links.getInt(node, CHILDINDEX); return ( idx<=0 ? -1 : getTargetNode(links[idx-1])); }
/** * Get the node id of the next sibling of the given node id. * @param node a node id (node table row number) * @return the node id of the next sibling, or -1 if there * is no next sibling. */ public int getNextSiblingRow(int node) { int p = getParent(node); if ( p < 0 ) return -1; int[] links = (int[])m_links.get(p, OUTLINKS); int idx = m_links.getInt(node, CHILDINDEX); int max = getChildCount(p)-1; return ( idx<0 || idx>=max ? -1 : getTargetNode(links[idx+1])); }
/** * Create a new Tree. * @param nodes the backing table to use for node data. * Node instances of this graph will get their data from this table. * @param edges the backing table to use for edge data. * Edge instances of this graph will get their data from this table. * @param nodeKey data field used to uniquely identify a node. If this * field is null, the node table row numbers will be used * @param sourceKey data field used to denote the source node in an edge * table * @param targetKey data field used to denote the target node in an edge * table */ public Tree(Table nodes, Table edges, String nodeKey, String sourceKey, String targetKey) { super(nodes, edges, false, nodeKey, sourceKey, targetKey); for ( IntIterator rows = nodes.rows(); rows.hasNext(); ) { int n = rows.nextInt(); if ( getParent(n) < 0 ) { m_root = n; break; } } }
/** * Gets the parent node. * @param node a node of the tree * @return parent node */ public Node getParentNode(Node node) { if (node.equals(this.getRoot())) { return null; } else { prefuse.data.Node prefNode = this.getPrefuseGraph().getNodeFromKey( this.getPrefuseGraph().getKey(node.getRow())); prefuse.data.Node parentNode = ((prefuse.data.Tree) this.getPrefuseGraph()).getParent(prefNode); return new PrefuseObviousNode(parentNode); } }
/** * Get the root node. * @return the root Node */ public Node getRoot() { try { prefuse.data.Node n = ((prefuse.data.Tree) getPrefuseGraph()).getRoot(); return new PrefuseObviousNode(n); } catch (IllegalArgumentException e) { for (Node node : this.getNodes()) { int nodeRow = node.getRow(); if (((prefuse.data.Tree) getPrefuseGraph()).getParent(nodeRow) < 0) { return new PrefuseObviousNode( ((prefuse.data.Tree) getPrefuseGraph()).getNode(nodeRow)); } } return null; } }