TINKERPOP-1676 Got rid of stream() usage

Can't believe we still had stream() in here. Will it ever all be gone from 
these performance sensitive places?! Anyway, removed that and deprecated a 
constructor on DetachedEdge that was using Pair for no really good reason. No 
need to create extra Pair objects for that. They just sorta get thrown away 
after usage.


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

Branch: refs/heads/TINKERPOP-1681
Commit: 46e6e9767b6818f33b56366ee15d80cec5a908e0
Parents: 8812f85
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 23 16:03:17 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 25 14:52:30 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  2 ++
 .../structure/io/graphson/GraphSONReader.java   |  5 ++--
 .../structure/util/detached/DetachedEdge.java   | 26 +++++++++++++++++++-
 .../structure/util/detached/DetachedVertex.java | 12 ++++-----
 .../util/detached/DetachedEdgeTest.java         |  3 +--
 .../tinkergraph/structure/TinkerIoRegistry.java |  5 ++--
 .../structure/TinkerIoRegistryV1d0.java         |  5 ++--
 7 files changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 31a4064..77d612e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,8 @@ 
image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Removed use of `stream()` in `DetachedEdge` and `DetachedVertex`.
+* Deprecated a constructor in `DetachedEdge` that made use of `Pair` in favor 
of a new one that just uses the objects that were in the `Pair`.
 * Improved error messaging on the `g.addV(Object...)` when passing an invalid 
arguments.
 * Reduced memory usage for TinkerGraph deserialization in GraphSON by 
streaming vertices and edges.
 * Now using Groovy `[...]` map notation in `GroovyTranslator` instead of `new 
LinkedHashMap(){{ }}`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
index a1ccc5e..3f63b96 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
@@ -42,7 +42,6 @@ import 
org.apache.tinkerpop.shaded.jackson.core.type.TypeReference;
 import org.apache.tinkerpop.shaded.jackson.databind.JsonNode;
 import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
 import org.apache.tinkerpop.shaded.jackson.databind.node.JsonNodeType;
-import org.javatuples.Pair;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -205,8 +204,8 @@ public final class GraphSONReader implements GraphReader {
             final DetachedEdge edge = new 
DetachedEdge(edgeData.get(GraphSONTokens.ID),
                     edgeData.get(GraphSONTokens.LABEL).toString(),
                     edgeProperties,
-                    Pair.with(edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
-                    Pair.with(edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString()));
+                    edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString(),
+                    edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString());
 
             return edgeAttachMethod.apply(edge);
         } else {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
index ba05cca..1284ca7 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
@@ -74,6 +74,29 @@ public class DetachedEdge extends DetachedElement<Edge> 
implements Edge {
 
     public DetachedEdge(final Object id, final String label,
                         final Map<String, Object> properties,
+                        final Object outVId, final String outVLabel,
+                        final Object inVId, final String inVLabel) {
+        super(id, label);
+        this.outVertex = new DetachedVertex(outVId, outVLabel, 
Collections.emptyMap());
+        this.inVertex = new DetachedVertex(inVId, inVLabel, 
Collections.emptyMap());
+        if (properties != null && !properties.isEmpty()) {
+            this.properties = new HashMap<>();
+            properties.entrySet().iterator().forEachRemaining(entry -> {
+                if 
(Property.class.isAssignableFrom(entry.getValue().getClass())) {
+                    this.properties.put(entry.getKey(), 
Collections.singletonList((Property)entry.getValue()));
+                } else {
+                    this.properties.put(entry.getKey(), 
Collections.singletonList(new DetachedProperty<>(entry.getKey(), 
entry.getValue(), this)));
+                }
+            });
+        }
+    }
+
+    /**
+     * @deprecated As for release 3.2.5, replaced by {@link 
#DetachedEdge(Object, String, Map, Object, String, Object, String)}.
+     */
+    @Deprecated
+    public DetachedEdge(final Object id, final String label,
+                        final Map<String, Object> properties,
                         final Pair<Object, String> outV,
                         final Pair<Object, String> inV) {
         super(id, label);
@@ -81,7 +104,7 @@ public class DetachedEdge extends DetachedElement<Edge> 
implements Edge {
         this.inVertex = new DetachedVertex(inV.getValue0(), inV.getValue1(), 
Collections.emptyMap());
         if (properties != null && !properties.isEmpty()) {
             this.properties = new HashMap<>();
-            properties.entrySet().stream().forEach(entry -> {
+            properties.entrySet().iterator().forEachRemaining(entry -> {
                 if 
(Property.class.isAssignableFrom(entry.getValue().getClass())) {
                     this.properties.put(entry.getKey(), 
Collections.singletonList((Property)entry.getValue()));
                 } else {
@@ -90,6 +113,7 @@ public class DetachedEdge extends DetachedElement<Edge> 
implements Edge {
             });
         }
     }
+
     @Override
     public String toString() {
         return StringFactory.edgeString(this);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
index 70cce37..d3fbd8e 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -78,12 +79,11 @@ public class DetachedVertex extends DetachedElement<Vertex> 
implements Vertex {
         super(id, label);
         if (properties != null && !properties.isEmpty()) {
             this.properties = new HashMap<>();
-            properties.entrySet().stream().forEach(
-                    entry -> this.properties.put(entry.getKey(), 
(List<VertexProperty>) ((List) entry.getValue()).stream()
-                                .map(m -> 
VertexProperty.class.isAssignableFrom(m.getClass())
-                                                ? m
-                                                : new 
DetachedVertexProperty<>(((Map) m).get(ID), entry.getKey(), ((Map) 
m).get(VALUE), (Map<String, Object>) ((Map) m).getOrDefault(PROPERTIES, new 
HashMap<>()), this))
-                                .collect(Collectors.toList())));
+            properties.entrySet().iterator().forEachRemaining(entry ->
+                this.properties.put(entry.getKey(), 
IteratorUtils.<VertexProperty>list(IteratorUtils.map(((List<Object>) 
entry.getValue()).iterator(),
+                        m -> 
VertexProperty.class.isAssignableFrom(m.getClass())
+                                ? (VertexProperty) m
+                                : new DetachedVertexProperty<>(((Map) 
m).get(ID), entry.getKey(), ((Map) m).get(VALUE), (Map<String, Object>) ((Map) 
m).getOrDefault(PROPERTIES, new HashMap<>()), this)))));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
index 1090fe4..29c5764 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
@@ -28,7 +28,6 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.javatuples.Pair;
 import org.junit.Test;
 
 import java.util.HashMap;
@@ -160,7 +159,7 @@ public class DetachedEdgeTest extends AbstractGremlinTest {
         properties.put("x", "a");
         properties.put("y", "b");
 
-        final DetachedEdge de = new DetachedEdge(10, "bought", properties, 
Pair.with(1, "person"), Pair.with(2, "product"));
+        final DetachedEdge de = new DetachedEdge(10, "bought", properties, 1, 
"person", 2, "product");
 
         assertEquals(10, de.id());
         assertEquals("bought", de.label());

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistry.java
----------------------------------------------------------------------
diff --git 
a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistry.java
 
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistry.java
index 40720e5..5abb363 100644
--- 
a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistry.java
+++ 
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistry.java
@@ -48,7 +48,6 @@ import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
 import org.apache.tinkerpop.shaded.kryo.io.Input;
 import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.javatuples.Pair;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -262,8 +261,8 @@ public final class TinkerIoRegistry extends 
AbstractIoRegistry {
             for (Map<String, Object> edgeData : edges) {
                 final DetachedEdge detached = new 
DetachedEdge(edgeData.get(GraphSONTokens.ID),
                         edgeData.get(GraphSONTokens.LABEL).toString(), 
(Map<String,Object>) edgeData.get(GraphSONTokens.PROPERTIES),
-                        Pair.with(edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
-                        Pair.with(edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString()));
+                        edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString(),
+                        edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString());
                 detached.attach(Attachable.Method.getOrCreate(graph));
             }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46e6e976/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV1d0.java
----------------------------------------------------------------------
diff --git 
a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV1d0.java
 
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV1d0.java
index 277bedc..d15a4a7 100644
--- 
a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV1d0.java
+++ 
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV1d0.java
@@ -48,7 +48,6 @@ import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
 import org.apache.tinkerpop.shaded.kryo.io.Input;
 import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.javatuples.Pair;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -252,8 +251,8 @@ public final class TinkerIoRegistryV1d0 extends 
AbstractIoRegistry {
             for (Map<String, Object> edgeData : edges) {
                 final DetachedEdge detached = new 
DetachedEdge(edgeData.get(GraphSONTokens.ID),
                         edgeData.get(GraphSONTokens.LABEL).toString(), 
(Map<String,Object>) edgeData.get(GraphSONTokens.PROPERTIES),
-                        Pair.with(edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
-                        Pair.with(edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString()));
+                        edgeData.get(GraphSONTokens.OUT), 
edgeData.get(GraphSONTokens.OUT_LABEL).toString(),
+                        edgeData.get(GraphSONTokens.IN), 
edgeData.get(GraphSONTokens.IN_LABEL).toString());
                 detached.attach(Attachable.Method.getOrCreate(graph));
             }
 

Reply via email to