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:23 UTC
[7/7] incubator-tinkerpop git commit: Add tests to enforce proper
filtering of vertices during iteration TINKERPOP3-581
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