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 2015/04/08 22:25:17 UTC

[1/7] incubator-tinkerpop git commit: Change the serialization model for custom identifiers given TINKERPOP3-581

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-581 [created] 0a2274514


Change the serialization model for custom identifiers given TINKERPOP3-581

Using a Map to represent an custom element in GraphSON doesn't work so well for non-JVM languages and doesn't enable the default serialization pattern for GraphSON to be set with embedTypes as false.  This commit sets up for greater support for non-JVM language bindings which must conform to the JSON type system.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 339f6ce855245f7677ac099d80d027d61929b74d
Parents: 22f1752
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 08:36:27 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 08:36:27 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/IoTest.java     | 62 +++++++-------------
 1 file changed, 20 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/339f6ce8/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index 4af8db5..c3041f7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -20,13 +20,10 @@ package org.apache.tinkerpop.gremlin.structure;
 
 import com.fasterxml.jackson.core.JsonGenerationException;
 import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
 import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
 import com.fasterxml.jackson.databind.module.SimpleModule;
 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@@ -81,7 +78,6 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Optional;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -273,13 +269,12 @@ public class IoTest extends AbstractGremlinTest {
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ANY_IDS)
-    public void shouldProperlySerializeDeserializeCustomIdWithGraphSON() throws Exception {
+    public void shouldProperlySerializeCustomIdWithGraphSON() throws Exception {
         final UUID id = UUID.fromString("AF4B5965-B176-4552-B3C1-FBBE2F52C305");
         graph.addVertex(T.id, new CustomId("vertex", id));
 
         final SimpleModule module = new SimpleModule();
         module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializer());
-        module.addDeserializer(CustomId.class, new CustomId.CustomIdJacksonDeserializer());
         final GraphWriter writer = graph.io().graphSONWriter().mapper(
                 graph.io().graphSONMapper().addCustomModule(module).embedTypes(true).create()).create();
 
@@ -2559,6 +2554,11 @@ public class IoTest extends AbstractGremlinTest {
             return elementId;
         }
 
+        @Override
+        public String toString() {
+            return cluster + ":" + elementId;
+        }
+
         static class CustomIdJacksonSerializer extends StdSerializer<CustomId> {
             public CustomIdJacksonSerializer() {
                 super(CustomId.class);
@@ -2577,44 +2577,22 @@ public class IoTest extends AbstractGremlinTest {
             }
 
             private void ser(final CustomId customId, final JsonGenerator jsonGenerator, final boolean includeType) throws IOException {
-                jsonGenerator.writeStartObject();
-
-                if (includeType)
+                if (includeType) {
+                    // when the type is included add "class" as a key and then try to utilize as much of the
+                    // default serialization provided by jackson data-bind as possible.  for example, write
+                    // the uuid as an object so that when jackson serializes it, it uses the uuid serializer
+                    // to write it out with the type.  in this way, data-bind should be able to deserialize
+                    // it back when types are embedded.
+                    jsonGenerator.writeStartObject();
                     jsonGenerator.writeStringField(GraphSONTokens.CLASS, CustomId.class.getName());
-
-                jsonGenerator.writeObjectField("cluster", customId.getCluster());
-                jsonGenerator.writeObjectField("elementId", customId.getElementId().toString());
-                jsonGenerator.writeEndObject();
-            }
-        }
-
-        static class CustomIdJacksonDeserializer extends StdDeserializer<CustomId> {
-            public CustomIdJacksonDeserializer() {
-                super(CustomId.class);
-            }
-
-            @Override
-            public CustomId deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-                String cluster = null;
-                UUID id = null;
-
-                while (!jsonParser.getCurrentToken().isStructEnd()) {
-                    if (jsonParser.getText().equals("cluster")) {
-                        jsonParser.nextToken();
-                        cluster = jsonParser.getText();
-                    } else if (jsonParser.getText().equals("elementId")) {
-                        jsonParser.nextToken();
-                        id = UUID.fromString(jsonParser.getText());
-                    } else
-                        jsonParser.nextToken();
+                    jsonGenerator.writeStringField("cluster", customId.getCluster());
+                    jsonGenerator.writeObjectField("elementId", customId.getElementId());
+                    jsonGenerator.writeEndObject();
+                } else {
+                    // when types are not embedded, stringify or resort to JSON primitive representations of the
+                    // type so that non-jvm languages can better interoperate with the TinkerPop stack.
+                    jsonGenerator.writeString(customId.toString());
                 }
-
-                if (!Optional.ofNullable(cluster).isPresent())
-                    throw deserializationContext.mappingException("Could not deserialze CustomId: 'cluster' is required");
-                if (!Optional.ofNullable(id).isPresent())
-                    throw deserializationContext.mappingException("Could not deserialze CustomId: 'id' is required");
-
-                return new CustomId(cluster, id);
             }
         }
     }


[5/7] incubator-tinkerpop git commit: Correct previous commit - had some bad mis-types.

Posted by sp...@apache.org.
Correct previous commit - had some bad mis-types.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 4b7990c8c208fe19a3b2283f8407c1387291dca9
Parents: 66d981c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 09:29:13 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 09:29:13 2015 -0400

----------------------------------------------------------------------
 .../org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4b7990c8/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
index 8efa620..5d84c56 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
@@ -254,7 +254,7 @@ public class FeatureSupportTest {
         public void shouldSupportStringIdsIfStringIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             if (v.id() instanceof String)
-                fail(String.format(INVALID_git FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
+                fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
         }
 
         @Test


[3/7] incubator-tinkerpop git commit: Correct test names.

Posted by sp...@apache.org.
Correct test names.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 9886d7749dd161406ad45fe61461cf35b4b00687
Parents: 021fa74
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 09:27:05 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 09:27:05 2015 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/structure/FeatureSupportTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9886d774/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
index 706c363..f4969ba 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
@@ -707,7 +707,7 @@ public class FeatureSupportTest {
         @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
-        public void shouldSupportStringIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             final VertexProperty p = v.property("name", "stephen");
             if (p.id() instanceof UUID)
@@ -718,7 +718,7 @@ public class FeatureSupportTest {
         @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false)
-        public void shouldSupportStringIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             final VertexProperty p = v.property("name", "stephen");
             if (p.id() instanceof Number)


[4/7] incubator-tinkerpop git commit: Correct test names.

Posted by sp...@apache.org.
Correct test names.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 66d981c1f4f465e90ad092ccca3b696a9badc842
Parents: 9886d77
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 09:28:46 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 09:28:46 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/FeatureSupportTest.java   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66d981c1/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
index f4969ba..8efa620 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/FeatureSupportTest.java
@@ -254,14 +254,14 @@ public class FeatureSupportTest {
         public void shouldSupportStringIdsIfStringIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             if (v.id() instanceof String)
-                fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
+                fail(String.format(INVALID_git FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_STRING_IDS));
         }
 
         @Test
         @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
-        public void shouldSupportStringIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             if (v.id() instanceof UUID)
                 fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_UUID_IDS));
@@ -271,7 +271,7 @@ public class FeatureSupportTest {
         @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false)
-        public void shouldSupportStringIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             if (v.id() instanceof Number)
                 fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_NUMERIC_IDS));
@@ -378,7 +378,7 @@ public class FeatureSupportTest {
         @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
         @FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
-        public void shouldSupportStringIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             final Edge e = v.addEdge("knows", v);
             if (e.id() instanceof UUID)
@@ -390,7 +390,7 @@ public class FeatureSupportTest {
         @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
         @FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
         @FeatureRequirement(featureClass = EdgeFeatures.class, feature = FEATURE_NUMERIC_IDS, supported = false)
-        public void shouldSupportStringIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
+        public void shouldSupportNumericIdsIfNumericIdsAreGeneratedFromTheGraph() throws Exception {
             final Vertex v = graph.addVertex();
             final Edge e = v.addEdge("knows", v);
             if (e.id() instanceof Number)


[6/7] incubator-tinkerpop git commit: Add some javadoc around Graph.edge/vertices.

Posted by sp...@apache.org.
Add some javadoc around Graph.edge/vertices.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 54f9bce562d920004e88c905df42f6253a8ddc7d
Parents: 4b7990c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 10:00:09 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 10:00:09 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/Graph.java      | 85 +++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/54f9bce5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 376ab45..5066c06 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -158,7 +158,53 @@ public interface Graph extends AutoCloseable {
     }
 
     /**
-     * Get the {@link Vertex} objects in this graph with the provided vertex ids. If no ids are provided, get all vertices.
+     * Get the {@link Vertex} objects in this graph with the provided vertex ids. If no ids are provided, get all
+     * vertices.  Note that a vertex identifier does not need to correspond to the actual id used in the graph.  It
+     * needs to be a bit more flexible than that in that given the {@link Graph.Features} around id support, multiple
+     * arguments might be applicable here.
+     * <br/>
+     * If the graph return {@code true} for {@link Features.VertexFeatures#supportsNumericIds()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.V(v)</li>
+     *     <li>g.V(v.id())</li>
+     *     <li>g.V(1)</li>
+     *     <li>g.V(1L)</li>
+     *     <li>g.V(1.0d)</li>
+     *     <li>g.V(1.0f)</li>
+     *     <li>g.V("1")</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.VertexFeatures#supportsCustomIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.V(v)</li>
+     *     <li>g.V(v.id())</li>
+     *     <li>g.V(v.id().toString())</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.VertexFeatures#supportsAnyIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.V(v)</li>
+     *     <li>g.V(v.id())</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.VertexFeatures#supportsStringIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.V(v)</li>
+     *     <li>g.V(v.id().toString())</li>
+     *     <li>g.V("id")</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsStringIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.V(v)</li>
+     *     <li>g.V(v.id().toString())</li>
+     *     <li>g.V("id")</li>
+     * </ul>
      *
      * @param vertexIds the ids of the vertices to get
      * @return an {@link Iterator} of vertices that match the provided vertex ids
@@ -167,6 +213,43 @@ public interface Graph extends AutoCloseable {
 
     /**
      * Get the {@link Edge} objects in this graph with the provided edge ids. If no ids are provided, get all edges.
+     * Note that an edge identifier does not need to correspond to the actual id used in the graph.  It
+     * needs to be a bit more flexible than that in that given the {@link Graph.Features} around id support, multiple
+     * arguments might be applicable here.
+     * <br/>
+     * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsNumericIds()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.E(e)</li>
+     *     <li>g.E(1)</li>
+     *     <li>g.E(1L)</li>
+     *     <li>g.E(1.0d)</li>
+     *     <li>g.E(1.0f)</li>
+     *     <li>g.E("1")</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsCustomIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.E(e)</li>
+     *     <li>g.E(e.id())</li>
+     *     <li>g.E(e.id().toString())</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsAnyIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.E(e)</li>
+     *     <li>g.E(e.id())</li>
+     * </ul>
+     * <br/>
+     * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsStringIds()} ()} then it should support
+     * filters as with:
+     * <ul>
+     *     <li>g.E(e)</li>
+     *     <li>g.E(e.id().toString())</li>
+     *     <li>g.E("id")</li>
+     * </ul>
      *
      * @param edgeIds the ids of the edges to get
      * @return an {@link Iterator} of edges that match the provided edge ids


[7/7] incubator-tinkerpop git commit: Add tests to enforce proper filtering of vertices during iteration TINKERPOP3-581

Posted by sp...@apache.org.
Add tests to enforce proper filtering of vertices during iteration TINKERPOP3-581

Updated TinkerGraph.vertices() implementation a bit.  Pushed some of the checking performed in GraphStep for non-uniform id arguments into the Graph.vertices() implementation so that it is handled at that level.  Still need to clean up in GraphStep a bit as that validation code probably doesn't need to be there anymore.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 0a22745146c79988a67dc8870970d7a8c70420e9
Parents: 54f9bce
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 16:22:35 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 16:22:35 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/Graph.java      |  84 ++--
 .../tinkerpop/gremlin/structure/GraphTest.java  | 426 ++++++++++++++++++-
 .../tinkergraph/structure/TinkerGraph.java      |  84 +++-
 3 files changed, 543 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0a227451/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 5066c06..1303ac1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -166,44 +166,40 @@ public interface Graph extends AutoCloseable {
      * If the graph return {@code true} for {@link Features.VertexFeatures#supportsNumericIds()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.V(v)</li>
-     *     <li>g.V(v.id())</li>
-     *     <li>g.V(1)</li>
-     *     <li>g.V(1L)</li>
-     *     <li>g.V(1.0d)</li>
-     *     <li>g.V(1.0f)</li>
-     *     <li>g.V("1")</li>
+     *     <li>g.vertices(v.id())</li>
+     *     <li>g.vertices(1)</li>
+     *     <li>g.vertices(1L)</li>
+     *     <li>g.vertices(1.0d)</li>
+     *     <li>g.vertices(1.0f)</li>
+     *     <li>g.vertices("1")</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.VertexFeatures#supportsCustomIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.V(v)</li>
-     *     <li>g.V(v.id())</li>
-     *     <li>g.V(v.id().toString())</li>
+     *     <li>g.vertices(v.id())</li>
+     *     <li>g.vertices(v.id().toString())</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.VertexFeatures#supportsAnyIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.V(v)</li>
-     *     <li>g.V(v.id())</li>
+     *     <li>g.vertices(v.id())</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.VertexFeatures#supportsStringIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.V(v)</li>
-     *     <li>g.V(v.id().toString())</li>
-     *     <li>g.V("id")</li>
+     *     <li>g.vertices(v)</li>
+     *     <li>g.vertices(v.id().toString())</li>
+     *     <li>g.vertices("id")</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsStringIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.V(v)</li>
-     *     <li>g.V(v.id().toString())</li>
-     *     <li>g.V("id")</li>
+     *     <li>g.vertices(v.id().toString())</li>
+     *     <li>g.vertices("id")</li>
      * </ul>
      *
      * @param vertexIds the ids of the vertices to get
@@ -220,35 +216,32 @@ public interface Graph extends AutoCloseable {
      * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsNumericIds()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.E(e)</li>
-     *     <li>g.E(1)</li>
-     *     <li>g.E(1L)</li>
-     *     <li>g.E(1.0d)</li>
-     *     <li>g.E(1.0f)</li>
-     *     <li>g.E("1")</li>
+     *     <li>g.edges(e.id())</li>
+     *     <li>g.edges(1)</li>
+     *     <li>g.edges(1L)</li>
+     *     <li>g.edges(1.0d)</li>
+     *     <li>g.edges(1.0f)</li>
+     *     <li>g.edges("1")</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsCustomIds()} ()} then it should support
      * filters as with:
-     * <ul>
-     *     <li>g.E(e)</li>
-     *     <li>g.E(e.id())</li>
-     *     <li>g.E(e.id().toString())</li>
+     * <ul>\
+     *     <li>g.edges(e.id())</li>
+     *     <li>g.edges(e.id().toString())</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsAnyIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.E(e)</li>
-     *     <li>g.E(e.id())</li>
+     *     <li>g.edges(e.id())</li>
      * </ul>
      * <br/>
      * If the graph return {@code true} for {@link Features.EdgeFeatures#supportsStringIds()} ()} then it should support
      * filters as with:
      * <ul>
-     *     <li>g.E(e)</li>
-     *     <li>g.E(e.id().toString())</li>
-     *     <li>g.E("id")</li>
+     *     <li>g.edges(e.id().toString())</li>
+     *     <li>g.edges("id")</li>
      * </ul>
      *
      * @param edgeIds the ids of the edges to get
@@ -705,7 +698,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link Element} has numeric identifiers.
+             * Determines if an {@link Element} has numeric identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_NUMERIC_IDS)
             public default boolean supportsNumericIds() {
@@ -713,7 +706,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link Element} has string identifiers.
+             * Determines if an {@link Element} has string identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_STRING_IDS)
             public default boolean supportsStringIds() {
@@ -721,7 +714,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link Element} has UUID identifiers.
+             * Determines if an {@link Element} has UUID identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_UUID_IDS)
             public default boolean supportsUuidIds() {
@@ -729,16 +722,17 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link Element} has mapper identifiers where "mapper" refers to an implementation
-             * defined object.
+             * Determines if an {@link Element} has a specific custom object as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_CUSTOM_IDS)
             public default boolean supportsCustomIds() {
                 return true;
             }
 
+            // todo: need a test to enforce this condition
             /**
-             * Determines if an {@link Element} any Java object is a suitable identifier.
+             * Determines if an {@link Element} any Java object is a suitable identifier.  Note that this
+             * setting can only return true if {@link #supportsUserSuppliedIds()} is true.
              */
             @FeatureDescriptor(name = FEATURE_ANY_IDS)
             public default boolean supportsAnyIds() {
@@ -784,7 +778,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link VertexProperty} has numeric identifiers.
+             * Determines if an {@link VertexProperty} has numeric identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_NUMERIC_IDS)
             public default boolean supportsNumericIds() {
@@ -792,7 +786,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link VertexProperty} has string identifiers.
+             * Determines if an {@link VertexProperty} has string identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_STRING_IDS)
             public default boolean supportsStringIds() {
@@ -800,7 +794,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link VertexProperty} has UUID identifiers.
+             * Determines if an {@link VertexProperty} has UUID identifiers as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_UUID_IDS)
             public default boolean supportsUuidIds() {
@@ -808,8 +802,7 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link VertexProperty} has mapper identifiers where "mapper" refers to an implementation
-             * defined object.
+             * Determines if an {@link VertexProperty} has a specific custom object as their internal representation.
              */
             @FeatureDescriptor(name = FEATURE_CUSTOM_IDS)
             public default boolean supportsCustomIds() {
@@ -817,7 +810,8 @@ public interface Graph extends AutoCloseable {
             }
 
             /**
-             * Determines if an {@link VertexProperty} any Java object is a suitable identifier.
+             * Determines if an {@link VertexProperty} any Java object is a suitable identifier.  Note that this
+             * setting can only return true if {@link #supportsUserSuppliedIds()} is true.
              */
             @FeatureDescriptor(name = FEATURE_ANY_IDS)
             public default boolean supportsAnyIds() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0a227451/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
index 996c116..d5c63e8 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
@@ -51,7 +51,8 @@ import static org.junit.Assert.*;
  */
 @ExceptionCoverage(exceptionClass = Graph.Exceptions.class, methods = {
         "vertexWithIdAlreadyExists",
-        "elementNotFound"
+        "elementNotFound",
+        "idArgsMustBeEitherIdOrElement"
 })
 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 public class GraphTest extends AbstractGremlinTest {
@@ -166,19 +167,34 @@ public class GraphTest extends AbstractGremlinTest {
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
-    public void shouldAddVertexWithUserSuppliedAnyId() {
+    public void shouldAddVertexWithUserSuppliedAnyIdUsingUuid() {
         final UUID uuid = UUID.randomUUID();
         graph.addVertex(T.id, uuid);
         tryCommit(graph, graph -> {
             final Vertex v = graph.vertices(uuid).next();
             assertEquals(uuid, v.id());
         });
+    }
 
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
+    public void shouldAddVertexWithUserSuppliedAnyIdUsingString() {
+        final UUID uuid = UUID.randomUUID();
         graph.addVertex(T.id, uuid.toString());
         tryCommit(graph, graph -> {
             final Vertex v = graph.vertices(uuid.toString()).next();
             assertEquals(uuid.toString(), v.id());
         });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS)
+    public void shouldAddVertexWithUserSuppliedAnyIdUsingAnyObject() {
+        final UUID uuid = UUID.randomUUID();
 
         // this is different from "FEATURE_CUSTOM_IDS" as TinkerGraph does not define a specific id class
         // (i.e. TinkerId) for the identifier.
@@ -192,6 +208,412 @@ public class GraphTest extends AbstractGremlinTest {
 
     @Test
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingVertex() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingVertexId() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingStringRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id().toString()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingVertices() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingVertexIds() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id(), v2.id())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
+    public void shouldIterateVerticesWithUuidIdSupportUsingStringRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingVertex() {
+        final Vertex v1 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingVertexId() {
+        final Vertex v1 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingStringRepresentation() {
+        final Vertex v1 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id().toString()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingVertices() {
+        final Vertex v1 = graph.addVertex();
+        final Vertex v2 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingVertexIds() {
+        final Vertex v1 = graph.addVertex();
+        final Vertex v2 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id(), v2.id())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void shouldIterateVerticesWithCustomIdSupportUsingStringRepresentations() {
+        final Vertex v1 = graph.addVertex();
+        final Vertex v2 = graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingVertex() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingVertexId() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingLongRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(Long.parseLong(v1.id().toString())).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(Integer.parseInt(v1.id().toString())).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(Float.parseFloat(v1.id().toString())).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(Double.parseDouble(v1.id().toString())).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingStringRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id().toString()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingVertices() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingVertexIds() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id(), v2.id())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingLongRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(Long.parseLong(v1.id().toString()), Long.parseLong(v2.id().toString()))));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(Integer.parseInt(v1.id().toString()), Integer.parseInt(v2.id().toString()))));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(Float.parseFloat(v1.id().toString()), Float.parseFloat(v2.id().toString()))));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(Double.parseDouble(v1.id().toString()), Double.parseDouble(v2.id().toString()))));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
+    public void shouldIterateVerticesWithNumericIdSupportUsingStringRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 1l) : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, 2l) : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    public void shouldNotMixTypesForGettingSpecificVerticesWithVertexFirst() {
+        final Vertex v1 = graph.addVertex();
+        try {
+            graph.vertices(v1, graphProvider.convertId("1"));
+            fail("Should have thrown an exception because id arguments were mixed.");
+        } catch (Exception ex) {
+            final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+            assertEquals(expected.getClass(), ex.getClass());
+            assertEquals(expected.getMessage(), ex.getMessage());
+        }
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    public void shouldNotMixTypesForGettingSpecificVerticesWithStringFirst() {
+        final Vertex v1 = graph.addVertex();
+        try {
+            graph.vertices(graphProvider.convertId("1"), v1);
+            fail("Should have thrown an exception because id arguments were mixed.");
+        } catch (Exception ex) {
+            final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+            assertEquals(expected.getClass(), ex.getClass());
+            assertEquals(expected.getMessage(), ex.getMessage());
+        }
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingVertex() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingVertexId() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingStringRepresentation() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            final Vertex v = graph.vertices(v1.id().toString()).next();
+            assertEquals(v1.id(), v.id());
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingVertices() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "2") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1, v2)));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingVertexIds() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "2") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id(), v2.id())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS)
+    public void shouldIterateVerticesWithStringIdSupportUsingStringRepresentations() {
+        // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
+        final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "1") : graph.addVertex();
+        final Vertex v2 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, "2") : graph.addVertex();
+        tryCommit(graph, graph -> {
+            assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
+        });
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES, supported = false)
     public void shouldOverwriteEarlierKeyValuesWithLaterKeyValuesOnAddVertexIfNoMultiProperty() {
         final Vertex v = graph.addVertex("test", "A", "test", "B", "test", "C");

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0a227451/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 77f588f..730c7ea 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
@@ -39,8 +39,12 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
+import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
 import java.util.stream.Stream;
 
 /**
@@ -80,6 +84,10 @@ public class TinkerGraph implements Graph {
 
     private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph();
 
+    private Class<?> vertexIdClass = null;
+    private Class<?> edgeIdClass = null;
+    private Class<?> vertexPropertyIdClass = null;
+
     /**
      * An empty private constructor that initializes {@link TinkerGraph}.
      */
@@ -136,8 +144,16 @@ public class TinkerGraph implements Graph {
             idValue = TinkerHelper.getNextId(this);
         }
 
+        // todo: enforce vertex id consistency with tests
+        if (vertexIdClass == null)
+            vertexIdClass = idValue.getClass();
+        else if (!idValue.getClass().equals(vertexIdClass)) {
+            throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", vertexIdClass, idValue.getClass()));
+        }
+
         final Vertex vertex = new TinkerVertex(idValue, label, this);
         this.vertices.put(vertex.id(), vertex);
+
         ElementHelper.attachProperties(vertex, VertexProperty.Cardinality.list, keyValues);
         return vertex;
     }
@@ -195,10 +211,70 @@ public class TinkerGraph implements Graph {
         if (0 == vertexIds.length) {
             return this.vertices.values().iterator();
         } else if (1 == vertexIds.length) {
-            final Vertex vertex = this.vertices.get(vertexIds[0]);
-            return null == vertex ? Collections.emptyIterator() : IteratorUtils.of(vertex);
-        } else
-            return Stream.of(vertexIds).map(this.vertices::get).filter(Objects::nonNull).iterator();
+            if (vertexIds[0] instanceof Vertex) {
+                // no need to get the vertex again, so just flip it back - some implementation may want to treat this
+                // as a refresh operation. that's not necessary for tinkergraph.
+                return IteratorUtils.of((Vertex) vertexIds[0]);
+            } else {
+                // convert the id to the expected data type and lookup the vertex
+                final UnaryOperator<Object> conversionFunction = convertToId(vertexIds[0], vertexIdClass);
+                final Vertex vertex = this.vertices.get(conversionFunction.apply(vertexIds[0]));
+                return null == vertex ? Collections.emptyIterator() : IteratorUtils.of(vertex);
+            }
+        } else {
+            // base the conversion function on the first item in the id list as the expectation is that these
+            // id values will be a uniform list
+            if (vertexIds[0] instanceof Vertex) {
+                // based on the first item assume all vertices in the argument list
+                if (!Stream.of(vertexIds).allMatch(id -> id instanceof Vertex))
+                    throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+
+                // no need to get the vertices again, so just flip it back - some implementation may want to treat this
+                // as a refresh operation. that's not necessary for tinkergraph.
+                return Stream.of(vertexIds).map(id -> (Vertex) id).iterator();
+            } else {
+                final Class<?> firstClass = vertexIds[0].getClass();
+                if (!Stream.of(vertexIds).map(Object::getClass).allMatch(firstClass::equals))
+                    throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();     // todo: change exception to be ids of the same type
+                final UnaryOperator<Object> conversionFunction = convertToId(vertexIds[0], vertexIdClass);
+                return Stream.of(vertexIds).map(conversionFunction).map(this.vertices::get).filter(Objects::nonNull).iterator();
+            }
+        }
+    }
+
+    private UnaryOperator<Object> convertToId(final Object id, final Class<?> elementIdClass) {
+        if (id instanceof Number) {
+            if (elementIdClass != null) {
+                if (elementIdClass.equals(Long.class)) {
+                    return o -> ((Number) o).longValue();
+                } else if (elementIdClass.equals(Integer.class)) {
+                    return o -> ((Number) o).intValue();
+                } else if (elementIdClass.equals(Double.class)) {
+                    return o -> ((Number) o).doubleValue();
+                } else if (elementIdClass.equals(Float.class)) {
+                    return o -> ((Number) o).floatValue();
+                } else if (elementIdClass.equals(String.class)) {
+                    return o -> o.toString();
+                }
+            }
+        } else if (id instanceof String) {
+            if (elementIdClass != null) {
+                final String s = (String) id;
+                if (elementIdClass.equals(Long.class)) {
+                    return o -> Long.parseLong(s);
+                } else if (elementIdClass.equals(Integer.class)) {
+                    return o -> Integer.parseInt(s);
+                } else if (elementIdClass.equals(Double.class)) {
+                    return o -> Double.parseDouble(s);
+                } else if (elementIdClass.equals(Float.class)) {
+                    return o -> Float.parseFloat(s);
+                } else if (elementIdClass.equals(UUID.class)) {
+                    return o -> UUID.fromString(s);
+                }
+            }
+        }
+
+        return UnaryOperator.identity();
     }
 
     @Override


[2/7] incubator-tinkerpop git commit: Removed feature check for numeric ids because convertId was being called.

Posted by sp...@apache.org.
Removed feature check for numeric ids because convertId was being called.

convertId ensures that a graph will convert the identifier to something the Graph can support so a check on the type is not relevant.


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

Branch: refs/heads/TINKERPOP3-581
Commit: 021fa748e76588c0be6e5e0182d01ebf11856086
Parents: 339f6ce
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 8 08:46:07 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 8 08:46:07 2015 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/tinkerpop/gremlin/GraphProvider.java    | 4 +++-
 .../java/org/apache/tinkerpop/gremlin/structure/VertexTest.java  | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/021fa748/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
index d6e5bb3..da355b9 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
@@ -154,7 +154,9 @@ public interface GraphProvider {
 
     /**
      * Converts an identifier from a test to an identifier accepted by the Graph instance.  Test that try to
-     * utilize an Element identifier will pass it to this method before usage.
+     * utilize an Element identifier will pass it to this method before usage.  This method should be sure to
+     * consistent in the return value such that calling it with "x" should always return the same transformed
+     * value.
      */
     default public Object convertId(final Object id) {
         return id;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/021fa748/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
index cafcbbd..7821601 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
@@ -150,7 +150,6 @@ public class VertexTest {
         @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
         @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
         @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
-        @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_NUMERIC_IDS)
         public void shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge() {
             final Vertex v = graph.addVertex();
             final Object o = GraphManager.getGraphProvider().convertId("1");