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 2016/08/18 17:08:26 UTC
tinkerpop git commit: Add a GraphFactoryClass for EmptyGraph.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1278 f1912fb0f -> 766d85d70
Add a GraphFactoryClass for EmptyGraph.
This will allow EmptyGraph to get instnatiated by GraphFactory without having to add a open() method to EmptyGraph itself.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/766d85d7
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/766d85d7
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/766d85d7
Branch: refs/heads/TINKERPOP-1278
Commit: 766d85d706a423a615ad4b309ea134a49bba4298
Parents: f1912fb
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 18 13:07:29 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 18 13:07:29 2016 -0400
----------------------------------------------------------------------
.../gremlin/structure/util/empty/EmptyGraph.java | 14 ++++++++++++++
.../gremlin/structure/util/GraphFactoryTest.java | 9 +++++++++
2 files changed, 23 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/766d85d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
index 1d9e6dd..40cf31f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
@@ -25,6 +25,8 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactoryClass;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.Collections;
@@ -34,6 +36,7 @@ import java.util.Iterator;
* @author Marko A. Rodriguez (http://markorodriguez.com)
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
+@GraphFactoryClass(EmptyGraph.EmptyGraphFactory.class)
public final class EmptyGraph implements Graph {
private static final String MESSAGE = "The graph is immutable and empty";
@@ -242,4 +245,15 @@ public final class EmptyGraph implements Graph {
}
}
}
+
+ /**
+ * {@link EmptyGraph} doesn't have a standard {@code open()} method because it is a singleton. Use this factory
+ * to provide as a {@link GraphFactoryClass} for {@link EmptyGraph} so that {@link GraphFactory} can instantiate
+ * it in a generalized way. End users should not generally use this method of instantiation.
+ */
+ public static final class EmptyGraphFactory {
+ public static Graph open(final Configuration conf) {
+ return EmptyGraph.instance();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/766d85d7/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactoryTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactoryTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactoryTest.java
index ee51016..00bb350 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactoryTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactoryTest.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.junit.Test;
import java.io.File;
@@ -35,6 +36,7 @@ import java.util.Iterator;
import java.util.Map;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
/**
@@ -239,6 +241,13 @@ public class GraphFactoryTest {
GraphFactory.open(conf);
}
+ @Test
+ public void shouldCreateAnEmptyGraphInstance() {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(Graph.GRAPH, EmptyGraph.class.getName());
+ final Graph graph = GraphFactory.open(conf);
+ assertSame(EmptyGraph.instance(), graph);
+ }
public static class MockGraphWithoutOpen implements Graph {
@Override