@Override public boolean areNodesInGraph(Node[] nodes) { Graph graph = getCurrentGraph(); for (Node n : nodes) { if (!graph.contains(n)) { return false; } } return true; }
@Override public boolean areEdgesInGraph(Edge[] edges) { Graph graph = getCurrentGraph(); for (Edge e : edges) { if (!graph.contains(e)) { return false; } } return true; }
@Override public boolean isEdgeInGraph(Edge edge) { return getCurrentGraph().contains(edge); }
@Override public boolean isNodeInGraph(Node node) { return getCurrentGraph().contains(node); }
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Node n : mainGraph.getNodes().toArray()) { if (!graph.contains(n)) { //The node n is not in graph graph.addNode(n); } else { //The node n is in graph graph.removeNode(n); } } for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { graph.addEdge(e); } } } return graph; }
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { //The edge is not in graph graph.addEdge(e); } else { //The edge is in the graph graph.removeEdge(edgeInGraph); } } } return graph; }
System.out.println("Node 3 in the filtered graph: " + filteredGraph.contains(graph.getNode("3")));