/** * adds nodes to a group in function of a given pattern * * @param pattern * @param mode the way of using the pattern. */ public void addViaPattern(String pattern, PatternMode mode) { for (GraphVertex graphVertex : graph.getVertices()) { switch (mode) { case CONTAINS: if (graphVertex.getName().matches(".*" + pattern + ".*")) { addNode(graphVertex); } break; case ENDS: if (graphVertex.getName().endsWith(pattern)) { addNode(graphVertex); } break; case EQUALS: if (graphVertex.getName().equals(pattern)) { addNode(graphVertex); } break; case STARTS: if (graphVertex.getName().startsWith(pattern)) { addNode(graphVertex); } break; } } }
private static void DFS(GraphVertex cur, int time, List<GraphVertex> contacts) { for (GraphVertex next : cur.edges) { if (next.visitTime != time) { next.visitTime = time; contacts.add(next); DFS(next, time, contacts); } } }
public void setShape(Shape shape) { assert (shape != null); this.shape = shape; for (GraphVertex graphVertex : nodes) { graphVertex.setShape(shape); } }
public void filter(String pattern, PatternMode mode, boolean keep) { Iterator<GraphVertex> it = getNodes().iterator(); while (it.hasNext()) { GraphVertex vertex = it.next(); String vertexName = vertex.getName(); boolean match = (mode == PatternMode.EQUALS && vertexName.equals(pattern)) || (mode == PatternMode.CONTAINS && vertexName.matches(".*" + pattern + ".*")) || (mode == PatternMode.STARTS && vertexName.startsWith(pattern)) || (mode == PatternMode.ENDS && vertexName.endsWith(pattern)); boolean remove = (match && !keep) || (!match && keep); if (remove) { removeNode(vertex, true); } } }
private int addNode(int par) { GraphVertex p = verts.get(par); p.Marked = true; int unmarked = 0; // Update min Distance double t_min; GraphVertex gv; for (int i = 0; i < verts.size(); i++) { if (i == par) continue; gv = verts.get(i); if (!gv.Marked) { unmarked++; t_min = p.distanceTo(gv); if (t_min < Queue[i]) { // This path is shorter Parent[i] = par; Queue[i] = t_min; } } } // Now pick shortest path in Queue double minQ = Double.MAX_VALUE; int minI = -1; for (int i = 0; i < verts.size(); i++) { if (Queue[i] < minQ) { minI = i; minQ = Queue[i]; } } // Add it and mark it GraphVertex conn_par = verts.get(Parent[minI]); GraphVertex conn_child = verts.get(minI); Queue[minI] = Double.MAX_VALUE; conn_child.connectTo(conn_par); conn_child.Marked = true; unmarked--; if (unmarked > 0) { addNode(minI); } return unmarked; }
/** @param color color to define. */ public void setColor(Color color) { this.color = color; for (GraphVertex vertex : nodes) { vertex.setColor(color); } }
/** * add the given node to the group * * @param vertex */ public void addNode(GraphVertex vertex) { vertex.setColor(color); vertex.setShape(shape); addNode_WO_COLOR(vertex); }