@Test public void testFilter() { setupSimpleGraph(); Node n4 = graph.getOrCreateNodeByName("v4"); Node n5 = graph.getOrCreateNodeByName("v5"); graph.addDependency(n2, n4, DependencyType.READ_WRITE); graph.addDependency(n2, n5, DependencyType.READ_WRITE); DependencyGraph filteredGraph = graph.filter(new NotFilter(new NodeNameInFilter("v2", "v5"))); assertThat(graph.getNode("v1"), is(new Node("v1"))); assertThat(graph.getNode("v2"), is(new Node("v2"))); assertThat(graph.getNode("v3"), is(new Node("v3"))); assertThat(graph.getNode("v4"), is(n4)); assertThat(graph.getNode("v5"), is(n5)); assertThat(graph.getNode("v6"), nullValue()); assertThat(filteredGraph.getNode("v1"), is(new Node("v1"))); assertThat(filteredGraph.getNode("v2"), nullValue()); assertThat(filteredGraph.getNode("v3"), is(new Node("v3"))); assertThat(filteredGraph.getNode("v4"), is(new Node("v4"))); assertThat(filteredGraph.getNode("v5"), nullValue()); assertThat(filteredGraph.getEdge(n1, n3), notNullValue()); assertThat(graph.getEdge(n1, n2), notNullValue()); assertThat(filteredGraph.getEdge(n1, n2), nullValue()); assertThat(graph.getEdge(n2, n4), notNullValue()); assertThat(filteredGraph.getEdge(n2, n4), nullValue()); assertThat(graph.getEdge(n2, n5), notNullValue()); assertThat(filteredGraph.getEdge(n2, n5), nullValue()); try { filteredGraph.getOrCreateNodeByName("v6"); fail("filtered graph is unmodifiable."); } catch (UnsupportedOperationException e) { assertThat(e.getMessage(), is("this graph is unmodifiable")); } assertThat(graph, is(not(filteredGraph))); assertThat(graph.getBaseGraph(), is(graph)); assertThat(filteredGraph.getBaseGraph(), is(graph)); }
@Override public DependencyGraph filter(final NodeFilter filter) { DependencyGraphSimpleImpl clone = new DependencyGraphSimpleImpl(this.baseGraph); clone.setGraph( new MaskSubgraph<>(graph, node -> !filter.isAccepted(node), edge -> false)); return clone; }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public DependencyGraph filter(final NodeFilter filter) { DependencyGraphSimpleImpl clone = new DependencyGraphSimpleImpl(this.baseGraph); clone.setGraph( new MaskSubgraph<>(graph, node -> !filter.isAccepted(node), edge -> false)); return clone; } }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public DependencyGraph filter(final NodeFilter filter) { DependencyGraphSimpleImpl clone = new DependencyGraphSimpleImpl(this.baseGraph); clone.setGraph( new MaskSubgraph<>(graph, node -> !filter.isAccepted(node), edge -> false)); return clone; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public DependencyGraph filter(final NodeFilter filter) { DependencyGraphSimpleImpl clone = new DependencyGraphSimpleImpl(this.baseGraph); clone.setGraph( new MaskSubgraph<>(graph, node -> !filter.isAccepted(node), edge -> false)); return clone; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); @Override DependencyGraph getBaseGraph(); @Override Node getOrCreateNodeByName(String name); @Override Node getNode(String name); @Override boolean hasNode(String name); @Override Dependency addDependency(Node from, Node to, DependencyType type); @Override Dependency getEdge(Node from, Node to); @Override Set<Dependency> getOutgoingEdges(Node node); @Override Set<Dependency> getOutgoingEdges(Node node, DependencyType dependencyType); @Override Set<Dependency> getIncomingEdges(Node node); @Override Set<Dependency> getIncomingEdges(Node node, DependencyType dependencyType); @Override DependencyGraph filter(final NodeFilter filter); @Override DependencyGraph filter(final EdgeFilter filter); @Override Collection<Node> getAllNodes(); @Override Collection<Dependency> getAllEdges(); AbstractGraph<Node, Dependency> getGraph(); @Override String toString(); }
DependencyGraphSimpleImpl implements DependencyGraph { @Override public DependencyGraph filter(final NodeFilter filter) { DependencyGraphSimpleImpl clone = new DependencyGraphSimpleImpl(this.baseGraph); clone.setGraph( new MaskSubgraph<>(graph, node -> !filter.isAccepted(node), edge -> false)); return clone; } @SuppressWarnings("squid:S3366") // Sonar warns that "this" may be used by another thread before the object is completely created. In this setting // here, there won't be a problem.  DependencyGraphSimpleImpl();  DependencyGraphSimpleImpl(DependencyGraph baseGraph); @Override DependencyGraph getBaseGraph(); @Override Node getOrCreateNodeByName(String name); @Override Node getNode(String name); @Override boolean hasNode(String name); @Override Dependency addDependency(Node from, Node to, DependencyType type); @Override Dependency getEdge(Node from, Node to); @Override Set<Dependency> getOutgoingEdges(Node node); @Override Set<Dependency> getOutgoingEdges(Node node, DependencyType dependencyType); @Override Set<Dependency> getIncomingEdges(Node node); @Override Set<Dependency> getIncomingEdges(Node node, DependencyType dependencyType); @Override DependencyGraph filter(final NodeFilter filter); @Override DependencyGraph filter(final EdgeFilter filter); @Override Collection<Node> getAllNodes(); @Override Collection<Dependency> getAllEdges(); AbstractGraph<Node, Dependency> getGraph(); @Override String toString();  }