GraphViewDecorator implements DirectedSubgraph, UndirectedSubgraph { @Override public void intersection(Subgraph subGraph) { checkValidViewObject(subGraph.getView()); graphStore.autoWriteLock(); try { view.intersection((GraphViewImpl) subGraph.getView()); } finally { graphStore.autoWriteUnlock(); } } GraphViewDecorator(GraphStore graphStore, GraphViewImpl view, boolean undirected); @Override Edge getEdge(Node node1, Node node2); @Override EdgeIterable getEdges(Node node1, Node node2); @Override Edge getEdge(Node node1, Node node2, int type); @Override EdgeIterable getEdges(Node node1, Node node2, int type); @Override Edge getMutualEdge(Edge e); @Override NodeIterable getPredecessors(Node node); @Override NodeIterable getPredecessors(Node node, int type); @Override NodeIterable getSuccessors(Node node); @Override NodeIterable getSuccessors(Node node, int type); @Override EdgeIterable getInEdges(Node node); @Override EdgeIterable getInEdges(Node node, int type); @Override EdgeIterable getOutEdges(Node node); @Override EdgeIterable getOutEdges(Node node, int type); @Override boolean isAdjacent(Node source, Node target); @Override boolean isAdjacent(Node source, Node target, int type); @Override boolean addEdge(Edge edge); @Override boolean addNode(Node node); @Override boolean addAllEdges(Collection<? extends Edge> edges); @Override boolean addAllNodes(Collection<? extends Node> nodes); @Override boolean removeEdge(Edge edge); @Override boolean removeNode(Node node); @Override boolean removeAllEdges(Collection<? extends Edge> edges); @Override boolean removeAllNodes(Collection<? extends Node> nodes); @Override boolean contains(Node node); @Override boolean contains(Edge edge); @Override Node getNode(Object id); @Override boolean hasNode(final Object id); @Override Edge getEdge(Object id); @Override boolean hasEdge(final Object id); @Override NodeIterable getNodes(); @Override EdgeIterable getEdges(); @Override EdgeIterable getSelfLoops(); @Override NodeIterable getNeighbors(Node node); @Override NodeIterable getNeighbors(Node node, int type); @Override EdgeIterable getEdges(Node node); @Override EdgeIterable getEdges(Node node, int type); @Override int getNodeCount(); @Override int getEdgeCount(); @Override int getEdgeCount(int type); @Override Node getOpposite(Node node, Edge edge); @Override int getDegree(Node node); @Override int getInDegree(Node node); @Override int getOutDegree(Node node); @Override boolean isSelfLoop(Edge edge); @Override boolean isDirected(Edge edge); @Override boolean isIncident(Edge edge1, Edge edge2); @Override boolean isIncident(final Node node, final Edge edge); @Override void clearEdges(Node node); @Override void clearEdges(Node node, int type); @Override void clear(); @Override void clearEdges(); @Override Object getAttribute(String key); @Override Object getAttribute(String key, double timestamp); @Override Object getAttribute(String key, Interval interval); @Override Set<String> getAttributeKeys(); @Override void setAttribute(String key, Object value); @Override void setAttribute(String key, Object value, double timestamp); @Override void setAttribute(String key, Object value, Interval interval); @Override void removeAttribute(String key); @Override void removeAttribute(String key, double timestamp); @Override void removeAttribute(String key, Interval interval); @Override GraphModel getModel(); @Override boolean isDirected(); @Override boolean isUndirected(); @Override boolean isMixed(); @Override void readLock(); @Override void readUnlock(); @Override void readUnlockAll(); @Override void writeLock(); @Override void writeUnlock(); @Override GraphView getView(); @Override void fill(); @Override void union(Subgraph subGraph); @Override void intersection(Subgraph subGraph); @Override void not(); @Override Graph getRootGraph();  }
@Test public void testIntersection() { GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); GraphViewStore store = graphStore.viewStore; GraphViewImpl view1 = store.createView(); GraphViewImpl view2 = store.createView(); DirectedSubgraph graph1 = store.getDirectedGraph(view1); DirectedSubgraph graph2 = store.getDirectedGraph(view2); Node n1 = graphStore.getNode("1"); Node n2 = graphStore.getNode("2"); graph1.addNode(n1); graph1.addNode(n2); graph2.addNode(n2); graph1.intersection(graph2); Assert.assertFalse(graph1.contains(n1)); Assert.assertTrue(graph1.contains(n2)); }