/** * Returns a collection of all edges of the tree. * @return all edges of the tree */ public Collection<Edge> getEdges() { Collection<Edge> edges = new ArrayList<Edge>(); for (int i = 0; i < edgeTable.getRowCount(); i++) { if (edgeTable.isValidRow(i)) { edges.add(new EdgeImpl(edgeTable, i)); } } return edges; }
/** * Returns a collection of all edges of the graph. * @return all edges of the graph */ public Collection<Edge> getEdges() { Collection<Edge> edges = new ArrayList<Edge>(); DynamicTable baseTable = graph.getEdgeTable(); Table edgeTable = new IvtkObviousTable(baseTable); for (int i = 0; i < edgeTable.getRowCount(); i++) { edges.add(new EdgeImpl(edgeTable, i)); } return edges; }
/** * Gets a collection of child Edges of a node in the tree. * @param node a node of the tree * @return child edges of the tree */ public Collection<Edge> getChildEdges(Node node) { Collection<Edge> children = new ArrayList<Edge>(); for (int i = 0; i < edgeTable.getRowCount(); i++) { if (getNodeId(node) == edgeTable.getValue(i, "parent")) { children.add(new EdgeImpl(edgeTable, i)); } } return children; }
/** * Gets the parent edge. * @param node a node of the tree * @return parent edge */ public Edge getParentEdge(Node node) { Edge parent = null; for (int i = 0; i < edgeTable.getRowCount(); i++) { if (getNodeId(node) == edgeTable.getValue(i, "child")) { parent = new EdgeImpl(edgeTable, i); } } return parent; }
Edge currentEdge = (Edge) new EdgeImpl(edgeSchema , edgeAttr); edges.add(currentEdge);
/** * Gets for two nodes the connecting edge. * @param v1 first node * @param v2 second node * @return connecting edge */ public Edge getConnectingEdge(Node v1, Node v2) { Edge connecting = null; int v1Id = getNodeId(v1); int v2Id = getNodeId(v2); for (int i = 0; i < edgeTable.getRowCount(); i++) { int parentId = (Integer) edgeTable.getValue(i, "parent"); int childId = (Integer) edgeTable.getValue(i, "child"); if ((v1Id == parentId && v2Id == childId) || (v2Id == parentId && v1Id == childId)) { connecting = new EdgeImpl(edgeTable, i); } } return connecting; }
@Override public int addEdge(int s, int t) { obvious.data.Node source = getObviousNode(s); obvious.data.Node target = getObviousNode(t); Object[] values = new Object[nodeSchema.getColumnCount()]; for (int i = 0; i < edgeSchema.getColumnCount(); i++) { values[i] = edgeSchema.getColumnDefault(i); } EdgeImpl edge = new EdgeImpl(edgeSchema, values); network.addEdge(edge, source, target, Graph.EdgeType.DIRECTED); return getEdgeCount(); }
/** * 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); } }
/** * Loads the table with the data of external CSV files. * @return an obvious network * @throws ObviousxException when exception occurs */ public Network loadGraph() throws ObviousxException { CSVTableImport nodeImport = new CSVTableImport(nodeFile, new TableImpl(nodeSchema), separator); CSVTableImport edgeImport = new CSVTableImport(edgeFile, new TableImpl(edgeSchema), separator); Table nodeTable = nodeImport.loadTable(); Table edgeTable = edgeImport.loadTable(); for (int i = 0; i < nodeTable.getRowCount(); i++) { Node node = new NodeImpl(nodeTable, i); network.addNode(node); if (nodeId == null) { idToNode.put(node.getRow(), node); } else { idToNode.put(node.get(nodeId), node); } } for (int i = 0; i < edgeTable.getRowCount(); i++) { Edge edge = new EdgeImpl(edgeTable, i); network.addEdge(edge, idToNode.get(edge.get(sourceCol)), idToNode.get(edge.get(targetCol)), network.getEdgeType(edge)); } return this.network; }