You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/02/02 20:53:54 UTC

incubator-tinkerpop git commit: added nice GraphFilter.legalVertex() and GraphFilter.legalEdges() methods so that the provider doesn't have to be smart about how to apply the underlying filter traversal.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-962 7ad48f205 -> 72e388c4a


added nice GraphFilter.legalVertex() and GraphFilter.legalEdges() methods so that the provider doesn't have to be smart about how to apply the underlying filter traversal.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/72e388c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/72e388c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/72e388c4

Branch: refs/heads/TINKERPOP-962
Commit: 72e388c4a1eadb6654a422988857006ed27b6158
Parents: 7ad48f2
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Feb 2 12:53:54 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Feb 2 12:53:54 2016 -0700

----------------------------------------------------------------------
 .../gremlin/process/computer/GraphFilter.java        | 15 +++++++++++++--
 .../process/computer/TinkerGraphComputerView.java    |  5 ++---
 2 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/72e388c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
index 54256aa..3813320 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -61,12 +62,22 @@ public final class GraphFilter implements Cloneable, Serializable {
         }
     }
 
+    public boolean legalVertex(final Vertex vertex) {
+        return null == this.vertexFilter || TraversalUtil.test(vertex, this.vertexFilter);
+    }
+
+    public Iterator<Edge> legalEdges(final Vertex vertex) {
+        return null == this.edgeFilter ?
+                vertex.edges(Direction.BOTH) :
+                TraversalUtil.applyAll(vertex, this.edgeFilter);
+    }
+
     public final Traversal.Admin<Vertex, Vertex> getVertexFilter() {
-        return this.vertexFilter.clone();
+        return this.vertexFilter;
     }
 
     public final Traversal.Admin<Vertex, Edge> getEdgeFilter() {
-        return this.edgeFilter.clone();
+        return this.edgeFilter;
     }
 
     public boolean hasFilter() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/72e388c4/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputerView.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputerView.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputerView.java
index 524d675..0854d3e 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputerView.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputerView.java
@@ -20,7 +20,6 @@ package org.apache.tinkerpop.gremlin.tinkergraph.process.computer;
 
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -66,14 +65,14 @@ public final class TinkerGraphComputerView {
         if (this.graphFilter.hasFilter()) {
             graph.vertices().forEachRemaining(vertex -> {
                 boolean legalVertex = false;
-                if (this.graphFilter.hasVertexFilter() && TraversalUtil.applyAll(vertex, this.graphFilter.getVertexFilter()).hasNext()) {
+                if (this.graphFilter.hasVertexFilter() && this.graphFilter.legalVertex(vertex)) {
                     this.legalVertices.add(vertex.id());
                     legalVertex = true;
                 }
                 if ((legalVertex || !this.graphFilter.hasVertexFilter()) && this.graphFilter.hasEdgeFilter()) {
                     final Set<Object> edges = new HashSet<>();
                     this.legalEdges.put(vertex.id(), edges);
-                    TraversalUtil.applyAll(vertex, this.graphFilter.getEdgeFilter()).forEachRemaining(edge -> edges.add(edge.id()));
+                    this.graphFilter.legalEdges(vertex).forEachRemaining(edge -> edges.add(edge.id()));
                 }
             });
         }