You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/08/22 20:39:47 UTC

[02/48] tinkerpop git commit: TINKERPOP-1397 Fix StarGraph.addEdge

TINKERPOP-1397 Fix StarGraph.addEdge

For self-loops, StarGraph.addEdge used to put a single StarOutEdge
into both its inEdges and outEdges maps, potentially causing problems
in applyGraphFilter.

This change makes StarGraph.addEdge put the appropriate type of edge
(Star(Out/In)Edge) in the associated map.  The IDs for each edge
instance are kept in agreement.

This change is @okram's, who suggested it in PR #372.  I merely
reviewed it and added a couple of comments.


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

Branch: refs/heads/TINKERPOP-1278
Commit: 0022b7f6be25eb7d3c778b137beb6e8a7d2784ca
Parents: 4571061
Author: Dan LaRocque <da...@hopcount.org>
Authored: Wed Aug 10 18:52:13 2016 -0400
Committer: Dan LaRocque <da...@hopcount.org>
Committed: Wed Aug 10 19:10:39 2016 -0400

----------------------------------------------------------------------
 .../gremlin/structure/util/star/StarGraph.java     | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0022b7f6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index f516630..2089c42 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -37,6 +37,7 @@ import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -290,14 +291,16 @@ public final class StarGraph implements Graph, Serializable {
         public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
             final Edge edge = this.addOutEdge(label, inVertex, keyValues);
             if (inVertex.equals(this)) {
-                if(null == this.inEdges)
-                    this.inEdges = new HashMap<>();
-                List<Edge> inE = this.inEdges.get(label);
-                if (null == inE) {
-                    inE = new ArrayList<>();
-                    this.inEdges.put(label, inE);
+                if (ElementHelper.getIdValue(keyValues).isPresent()) {
+                    // reuse edge ID from method params
+                    this.addInEdge(label, this, keyValues);
+                } else {
+                    // copy edge ID that we just allocated with addOutEdge
+                    final Object[] keyValuesWithId = Arrays.copyOf(keyValues, keyValues.length + 2);
+                    keyValuesWithId[keyValuesWithId.length - 2] = T.id;
+                    keyValuesWithId[keyValuesWithId.length - 1] = edge.id();
+                    this.addInEdge(label, this, keyValuesWithId);
                 }
-                inE.add(edge);
             }
             return edge;
         }