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/10 19:57:05 UTC
[3/3] incubator-tinkerpop git commit: Refactor IdManager
configuration in TinkerGraph.
Refactor IdManager configuration in TinkerGraph.
Provides for less cut/paste of similar code and improved readability of constructor.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3aa7e215
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3aa7e215
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3aa7e215
Branch: refs/heads/TINKERPOP3-581
Commit: 3aa7e215381723f29e982a54bd076816bf081e36
Parents: 975f0a1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 10 13:56:01 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Apr 10 13:56:01 2015 -0400
----------------------------------------------------------------------
.../tinkergraph/structure/TinkerGraph.java | 58 ++++++++------------
1 file changed, 22 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3aa7e215/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 07cab24..aacc223 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
@@ -86,9 +86,9 @@ public class TinkerGraph implements Graph {
private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph(EMPTY_CONFIGURATION);
- protected IdManager<?> vertexIdManager;
- protected IdManager<?> edgeIdManager;
- protected IdManager<?> vertexPropertyIdManager;
+ protected final IdManager<?> vertexIdManager;
+ protected final IdManager<?> edgeIdManager;
+ protected final IdManager<?> vertexPropertyIdManager;
private final Configuration configuration;
@@ -97,39 +97,9 @@ public class TinkerGraph implements Graph {
*/
private TinkerGraph(final Configuration configuration) {
this.configuration = configuration;
-
- final String vertexIdManagerConfigValue = configuration.getString(CONFIG_VERTEX_ID, DefaultIdManager.ANY.name());
- try {
- vertexIdManager = DefaultIdManager.valueOf(vertexIdManagerConfigValue);
- } catch (IllegalArgumentException iae) {
- try {
- vertexIdManager = (IdManager) Class.forName(vertexIdManagerConfigValue).newInstance();
- } catch (Exception ex) {
- throw new IllegalStateException(String.format("Could not configure TinkerGraph vertex id manager with %s", vertexIdManagerConfigValue));
- }
- }
-
- final String edgeIdManagerConfigValue = configuration.getString(CONFIG_EDGE_ID, DefaultIdManager.ANY.name());
- try {
- edgeIdManager = DefaultIdManager.valueOf(edgeIdManagerConfigValue);
- } catch (IllegalArgumentException iae) {
- try {
- edgeIdManager = (IdManager) Class.forName(edgeIdManagerConfigValue).newInstance();
- } catch (Exception ex) {
- throw new IllegalStateException(String.format("Could not configure TinkerGraph edge id manager with %s", edgeIdManagerConfigValue));
- }
- }
-
- final String vertexPropIdManagerConfigValue = configuration.getString(CONFIG_VERTEX_PROPERTY_ID, DefaultIdManager.ANY.name());
- try {
- vertexPropertyIdManager = DefaultIdManager.valueOf(vertexPropIdManagerConfigValue);
- } catch (IllegalArgumentException iae) {
- try {
- vertexPropertyIdManager = (IdManager) Class.forName(vertexPropIdManagerConfigValue).newInstance();
- } catch (Exception ex) {
- throw new IllegalStateException(String.format("Could not configure TinkerGraph vertex property id manager with %s", vertexPropIdManagerConfigValue));
- }
- }
+ vertexIdManager = selectIdManager(configuration, CONFIG_VERTEX_ID, Vertex.class);
+ edgeIdManager = selectIdManager(configuration, CONFIG_EDGE_ID, Edge.class);
+ vertexPropertyIdManager = selectIdManager(configuration, CONFIG_VERTEX_PROPERTY_ID, VertexProperty.class);
}
public static TinkerGraph empty() {
@@ -426,6 +396,22 @@ public class TinkerGraph implements Graph {
}
/**
+ * Construct an {@link TinkerGraph.IdManager} from the TinkerGraph {@link Configuration}.
+ */
+ private static IdManager<?> selectIdManager(final Configuration config, final String configKey, final Class<? extends Element> clazz) {
+ final String vertexIdManagerConfigValue = config.getString(configKey, DefaultIdManager.ANY.name());
+ try {
+ return DefaultIdManager.valueOf(vertexIdManagerConfigValue);
+ } catch (IllegalArgumentException iae) {
+ try {
+ return (IdManager) Class.forName(vertexIdManagerConfigValue).newInstance();
+ } catch (Exception ex) {
+ throw new IllegalStateException(String.format("Could not configure TinkerGraph %s id manager with %s", clazz.getSimpleName(), vertexIdManagerConfigValue));
+ }
+ }
+ }
+
+ /**
* TinkerGraph will use an implementation of this interface to generate identifiers when a user does not supply
* them and to handle identifier conversions when querying to provide better flexibility with respect to
* handling different data types that mean the same thing. For example, the