tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m.@apache.org
Subject [1/7] tinkerpop git commit: move implementation of clone to GraphHelper
Date Thu, 21 Sep 2017 02:15:35 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/master fc48b046c -> c60cb9e74


move implementation of clone to GraphHelper


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

Branch: refs/heads/master
Commit: 9bf5f636eb46f2ae3a8869b3373134ffd94ebb70
Parents: a44e881
Author: Michael Pollmeier <michael@michaelpollmeier.com>
Authored: Mon Sep 11 10:53:40 2017 +1200
Committer: Michael Pollmeier <michael@michaelpollmeier.com>
Committed: Thu Sep 21 14:08:27 2017 +1200

----------------------------------------------------------------------
 gremlin-core/pom.xml                            |  6 ++
 .../gremlin/structure/util/GraphHelper.java     | 39 +++++++++++++
 .../gremlin/structure/util/GraphHelperTest.java | 59 ++++++++++++++++++++
 .../tinkergraph/structure/TinkerGraph.java      | 17 +-----
 .../tinkergraph/structure/TinkerGraphTest.java  | 30 ----------
 5 files changed, 105 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9bf5f636/gremlin-core/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-core/pom.xml b/gremlin-core/pom.xml
index bab7b65..e690c5d 100644
--- a/gremlin-core/pom.xml
+++ b/gremlin-core/pom.xml
@@ -95,6 +95,12 @@ limitations under the License.
             <artifactId>hamcrest-all</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tinkerpop</groupId>
+            <artifactId>tinkergraph-gremlin</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <!-- needed to test GraphFactory and xml based config via optional dependency
in apache configurations -->
         <dependency>
             <groupId>commons-collections</groupId>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9bf5f636/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelper.java
new file mode 100644
index 0000000..5d4809c
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelper.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.util;
+
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+
+/**
+ * Utility class supporting common functions for {@link org.apache.tinkerpop.gremlin.structure.Graph}.
+ */
+public final class GraphHelper {
+
+  private GraphHelper() {
+  }
+
+  /**
+   * make a deep clone of the graph elements that preserves ids
+   */
+  public static void cloneElements(final Graph original, final Graph clone) {
+    original.vertices().forEachRemaining(v -> DetachedFactory.detach(v, true).attach(Attachable.Method.create(clone)));
+    original.edges().forEachRemaining(e -> DetachedFactory.detach(e, true).attach(Attachable.Method.create(clone)));
+  }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9bf5f636/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelperTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelperTest.java
new file mode 100644
index 0000000..c186caf
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphHelperTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.util;
+
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class GraphHelperTest {
+
+  @Test
+  public void shouldCloneTinkergraph() {
+    final TinkerGraph original = TinkerGraph.open();
+    final TinkerGraph clone = TinkerGraph.open();
+
+    final Vertex marko = original.addVertex("name", "marko", "age", 29);
+    final Vertex stephen = original.addVertex("name", "stephen", "age", 35);
+    marko.addEdge("knows", stephen);
+    GraphHelper.cloneElements(original, clone);
+
+    final Vertex michael = clone.addVertex("name", "michael");
+    michael.addEdge("likes", marko);
+    michael.addEdge("likes", stephen);
+    clone.traversal().V().property("newProperty", "someValue").toList();
+    clone.traversal().E().property("newProperty", "someValue").toList();
+
+    assertEquals("original graph should be unchanged", new Long(2), original.traversal().V().count().next());
+    assertEquals("original graph should be unchanged", new Long(1), original.traversal().E().count().next());
+    assertEquals("original graph should be unchanged", new Long(0), original.traversal().V().has("newProperty").count().next());
+
+    assertEquals("cloned graph should contain new elements", new Long(3), clone.traversal().V().count().next());
+    assertEquals("cloned graph should contain new elements", new Long(3), clone.traversal().E().count().next());
+    assertEquals("cloned graph should contain new property", new Long(3), clone.traversal().V().has("newProperty").count().next());
+    assertEquals("cloned graph should contain new property", new Long(3), clone.traversal().E().has("newProperty").count().next());
+
+    assertNotSame("cloned elements should reference to different objects",
+        original.traversal().V().has("name", "stephen").next(),
+        clone.traversal().V().has("name", "stephen").next());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9bf5f636/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index 6501663..5563665 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -30,13 +30,9 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.Io;
 import org.apache.tinkerpop.gremlin.structure.io.IoCore;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoVersion;
-import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputerView;
 import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.optimization.TinkerGraphCountStrategy;
@@ -74,7 +70,7 @@ import java.util.stream.Stream;
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
 @Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
-public final class TinkerGraph implements Graph, Cloneable {
+public final class TinkerGraph implements Graph {
 
     static {
         TraversalStrategies.GlobalCache.registerStrategies(TinkerGraph.class, TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone().addStrategies(
@@ -382,17 +378,6 @@ public final class TinkerGraph implements Graph, Cloneable {
         }
     }
 
-    /**
-     * make a deep clone of the graph/vertices/edges that preserves ids
-     */
-    @Override
-    public TinkerGraph clone() {
-        final TinkerGraph cloned = new TinkerGraph(configuration);
-        vertices().forEachRemaining(v -> DetachedFactory.detach(v, true).attach(Attachable.Method.create(cloned)));
-        edges().forEachRemaining(e -> DetachedFactory.detach(e, true).attach(Attachable.Method.create(cloned)));
-        return cloned;
-    }
-
     public class TinkerGraphFeatures implements Features {
 
         private final TinkerGraphGraphFeatures graphFeatures = new TinkerGraphGraphFeatures();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9bf5f636/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index cb4f4d7..a85b0ee 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -68,7 +68,6 @@ import java.util.function.Consumer;
 import java.util.function.Supplier;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
@@ -594,35 +593,6 @@ public class TinkerGraphTest {
         }
     }
 
-    @Test
-    public void shouldClone() {
-        final TinkerGraph g = TinkerGraph.open();
-
-        final Vertex marko = g.addVertex("name", "marko", "age", 29);
-        final Vertex stephen = g.addVertex("name", "stephen", "age", 35);
-        marko.addEdge("knows", stephen);
-
-        final TinkerGraph g2 = g.clone();
-        final Vertex michael = g2.addVertex("name", "michael");
-        michael.addEdge("likes", marko);
-        michael.addEdge("likes", stephen);
-        g2.traversal().V().property("newProperty", "someValue").toList();
-        g2.traversal().E().property("newProperty", "someValue").toList();
-
-        assertEquals("original graph should be unchanged", new Long(2), g.traversal().V().count().next());
-        assertEquals("original graph should be unchanged", new Long(1), g.traversal().E().count().next());
-        assertEquals("original graph should be unchanged", new Long(0), g.traversal().V().has("newProperty").count().next());
-
-        assertEquals("cloned graph should contain new elements", new Long(3), g2.traversal().V().count().next());
-        assertEquals("cloned graph should contain new elements", new Long(3), g2.traversal().E().count().next());
-        assertEquals("cloned graph should contain new property", new Long(3), g2.traversal().V().has("newProperty").count().next());
-        assertEquals("cloned graph should contain new property", new Long(3), g2.traversal().E().has("newProperty").count().next());
-
-        assertNotSame("cloned elements should reference to different objects",
-            g.traversal().V().has("name", "stephen").next(),
-            g2.traversal().V().has("name", "stephen").next());
-    }
-
     /**
      * Coerces a {@code Color} to a {@link TinkerGraph} during serialization.  Demonstrates
how custom serializers
      * can be developed that can coerce one value to another during serialization.


Mime
View raw message