/** * Remove an edge from the graph. * @param e the Edge to remove from the graph * @return true if the edge was successfully removed, false if the * edge was not found in this graph */ public boolean removeEdge(Edge e) { edgeCheck(e, true); return removeEdge(e.getRow()); }
/** * Gets incident edges for a spotted node. * @param edge edge spotted * @return collection of incident nodes */ public Collection<Node> getIncidentNodes(Edge edge) { Collection<Node> node = new ArrayList<Node>(); prefuse.data.Edge prefEdge = this.graph.getEdge(edge.getRow()); node.add(new PrefuseObviousNode(prefEdge.getSourceNode())); node.add(new PrefuseObviousNode(prefEdge.getTargetNode())); return node; }
/** * Returns an obvious edge corresponding to a prefuse edge. * @param edge prefuse edge * @return an obvious edge */ private obvious.data.Edge getObviousEdge(Edge edge) { Object[] values = new Object[edge.getSchema().getColumnCount()]; for (int i = 0; i < edge.getSchema().getColumnCount(); i++) { values[i] = edge.get(edge.getSchema().getColumnName(i)); } return new EdgeImpl(edgeSchema, values); } }
/** * Internal method for checking the validity of an edge. * @param e the Edge to check for validity * @param throwException true if this method should throw an Exception * when an invalid node is encountered * @return true is the edge is valid, false if invalid */ protected boolean edgeCheck(Edge e, boolean throwException) { if ( !e.isValid() ) { if ( throwException ) { throw new IllegalArgumentException( "Edge must be valid."); } return false; } if ( e.getGraph() != this ) { if ( throwException ) { throw new IllegalArgumentException( "Edge must be part of this Graph."); } return false; } return true; }
while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); vals[0] = String.valueOf(e.getRow()); vals[1] = String.valueOf(e.getSourceNode().getRow()); vals[2] = String.valueOf(e.getTargetNode().getRow()); e.getString(field));
for (int i = 0; i < prefEdge.getColumnCount(); i++) { String colName = prefEdge.getColumnName(i); Boolean graphCol = colName.equals(sourceKey) || colName.equals( targetKey); prefEdge.set(colName, source.get(nodeKey)); } else if (graphCol && edge.get(colName).equals(targetKey) && nodeKey != null) { prefEdge.set(colName, target.get(nodeKey)); } else if (graphCol && edge.get(colName).equals(sourceKey) && nodeKey == null) { prefEdge.set(colName, source.getRow()); } else if (graphCol && edge.get(colName).equals(targetKey) && nodeKey == null) { prefEdge.set(colName, target.getRow()); } else { prefEdge.set(colName, edge.get(colName)); fireNetworkEvent(prefEdge.getRow(), prefEdge.getRow(), 0, NetworkListener.INSERT_EDGE); return true;
while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); Node v = e.getAdjacentNode(n); while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); Node v = e.getAdjacentNode(n); int dv = m_queue.getDepth(v); if ( dv > 0 && m_queue.getDepth(e) < 0 ) { Node u = e.getSourceNode(); Node v = e.getTargetNode(); int du = m_queue.getDepth(u); int dv = m_queue.getDepth(v); continue; // already visited Node nn = ee.getAdjacentNode(n); m_queue.visit(nn, dd); m_queue.add(ee, dd);
/** * Build the spanning tree, starting at the given root. Uses an * unweighted breadth first traversal to build the spanning tree. * @param root the root node of the spanning tree */ public void buildSpanningTree(Node root) { // re-use a previously allocated tree if possible super.clearEdges(); super.setRoot(root); // build unweighted spanning tree by BFS LinkedList q = new LinkedList(); BitSet visit = new BitSet(); q.add(root); visit.set(root.getRow()); Table edges = getEdgeTable(); while ( !q.isEmpty() ) { Node p = (Node)q.removeFirst(); for ( Iterator iter = p.edges(); iter.hasNext(); ) { Edge e = (Edge)iter.next(); Node n = e.getAdjacentNode(p); if ( !visit.get(n.getRow()) ) { q.add(n); visit.set(n.getRow()); int er = super.addChildEdge(p.getRow(), n.getRow()); edges.setInt(er, SOURCE_EDGE, e.getRow()); } } } }
public void addRelationship(GraphRelationship graphRelationship) { if (graphRelationship.hasStartAndEndNode()) { String start = graphRelationship.getStartNode().getId(); String end = graphRelationship.getEndNode().getId(); Edge edge = graph.addEdge(nodeMap.get(start), nodeMap.get(end)); edge.set(ID, graphRelationship.getId()); edge.set(TITLE, graphRelationship.getId()); graphRelationshipMap.put(graphRelationship.getId(), graphRelationship); } }
n = g.getNode(row); else n = g.getEdge(row).getTargetNode(); Object[] path = new Object[n.getDepth()+1]; for ( int i=path.length; --i>=0; n=n.getParent() ) {
/** * @see java.util.Iterator#next() */ public Object next() { Edge e = (Edge)m_edges.next(); return e.getAdjacentNode(m_node); }
while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); Node nn = e.getAdjacentNode(n); m_queue.visit(nn, 1); if ( m_queue.getDepth(e) < 0 ) while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); Node nn = e.getAdjacentNode(n); m_queue.visit(nn, 1); if ( m_queue.getDepth(e) < 0 )
/** * Remove a child edge from the Tree. The child node and its subtree * will also be removed from the Tree. * @param e the edge to remove * @return true if the edge and attached subtree is successfully removed, * false otherwise */ public boolean removeChildEdge(Edge e) { edgeCheck(e, true); return removeChild(getTargetNode(e.getRow())); }
/** * Get the target Node for the given Edge instance. * @param e an Edge instance * @return the target Node of the edge */ public Node getTargetNode(Edge e) { edgeCheck(e, true); return getNode(getTargetNode(e.getRow())); }
/** * Get the source Node for the given Edge instance. * @param e an Edge instance * @return the source Node of the edge */ public Node getSourceNode(Edge e) { edgeCheck(e, true); return getNode(getSourceNode(e.getRow())); }
/** * Given an Edge and an incident Node, return the other Node * connected to the edge. * @param e an Edge instance * @param n a Node instance. This node must * be connected to the edge * @return the adjacent Node */ public Node getAdjacentNode(Edge e, Node n) { edgeCheck(e, true); nodeCheck(n, true); return getNode(getAdjacentNode(e.getRow(), n.getRow())); }