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/08/04 16:49:21 UTC
tinkerpop git commit: self-edges are now two instance objects in
order to rectify a potential GraphFilter bug.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1397 [created] 9247a9a4e
self-edges are now two instance objects in order to rectify a potential GraphFilter bug.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9247a9a4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9247a9a4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9247a9a4
Branch: refs/heads/TINKERPOP-1397
Commit: 9247a9a4e6f0cb87558a60c013ec3327bd741cfd
Parents: 8f7218d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Aug 4 10:49:15 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Aug 4 10:49:15 2016 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 15 +++++-----
.../structure/util/star/StarGraphTest.java | 30 ++++++++++++++++++++
2 files changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9247a9a4/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 73c7ca7..a11251c 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
@@ -38,6 +38,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.HashSet;
@@ -319,14 +320,14 @@ 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())
+ this.addInEdge(label, this, keyValues);
+ else {
+ 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;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9247a9a4/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index 034afad..bd36061 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -23,6 +23,8 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.FeatureRequirement;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -224,6 +226,34 @@ public class StarGraphTest extends AbstractGremlinTest {
assertFalse(edgeIterator.hasNext());
assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next());
assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next());
+ /// test self loops and graph filter
+ GraphFilter graphFilter = new GraphFilter();
+ graphFilter.setEdgeFilter(__.bothE());
+ assertEquals(2l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().edges()));
+ graphFilter.setEdgeFilter(__.inE());
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().edges()));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.IN, "self")));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.OUT, "self")));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.IN)));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.OUT)));
+ graphFilter.setEdgeFilter(__.outE());
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().edges()));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.IN)));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.OUT)));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.IN, "self")));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.OUT, "self")));
+ graphFilter.setEdgeFilter(__.bothE("self"));
+ assertEquals(2l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.BOTH, "self")));
+ graphFilter.setEdgeFilter(__.inE("self"));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.IN, "self")));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.OUT, "self")));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.IN)));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.OUT)));
+ graphFilter.setEdgeFilter(__.outE("self"));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.IN)));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().edges(Direction.OUT)));
+ assertEquals(0l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.IN, "self")));
+ assertEquals(1l, IteratorUtils.count(StarGraph.of(vertex).applyGraphFilter(graphFilter).get().getStarVertex().vertices(Direction.OUT, "self")));
//
final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0();
TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);