You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/04/09 19:23:59 UTC
incubator-tinkerpop git commit: GreminClassResolved now called
GryoClassResolver. ReferenceXXX are legitimate structure/ interfaces.
Attachable is moved one package up. Attachable has an an Exception static
class for standard exceptions.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/reference_elements 861d77194 -> 885ca509a
GreminClassResolved now called GryoClassResolver. ReferenceXXX are legitimate structure/ interfaces. Attachable is moved one package up. Attachable has an an Exception static class for standard exceptions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/885ca509
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/885ca509
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/885ca509
Branch: refs/heads/reference_elements
Commit: 885ca509ae06505991c4f72adc034541d66c0891
Parents: 861d771
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Apr 9 11:24:11 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Apr 9 11:24:11 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/computer/GraphComputer.java | 4 +
.../gremlin/process/computer/Memory.java | 3 +
.../traversal/step/map/ComputerResultStep.java | 2 +-
.../gremlin/process/traversal/Traverser.java | 2 +-
.../tinkerpop/gremlin/structure/Edge.java | 3 +
.../tinkerpop/gremlin/structure/Element.java | 3 +
.../tinkerpop/gremlin/structure/Graph.java | 7 +-
.../tinkerpop/gremlin/structure/Property.java | 3 +
.../gremlin/structure/Transaction.java | 4 +
.../tinkerpop/gremlin/structure/Vertex.java | 4 +
.../gremlin/structure/VertexProperty.java | 4 +
.../structure/io/gryo/GremlinClassResolver.java | 206 ------------------
.../structure/io/gryo/GryoClassResolver.java | 211 +++++++++++++++++++
.../gremlin/structure/io/gryo/GryoMapper.java | 2 +-
.../gremlin/structure/util/Attachable.java | 76 +++++++
.../structure/util/detached/Attachable.java | 33 ---
.../structure/util/detached/DetachedEdge.java | 10 +-
.../util/detached/DetachedElement.java | 11 +-
.../structure/util/detached/DetachedPath.java | 5 +-
.../util/detached/DetachedProperty.java | 14 +-
.../structure/util/detached/DetachedVertex.java | 31 ++-
.../util/detached/DetachedVertexProperty.java | 6 +-
.../structure/util/reference/ReferenceEdge.java | 35 ++-
.../util/reference/ReferenceElement.java | 32 ++-
.../structure/util/reference/ReferencePath.java | 6 +-
.../util/reference/ReferenceProperty.java | 57 ++++-
.../util/reference/ReferenceVertex.java | 58 ++++-
.../util/reference/ReferenceVertexProperty.java | 48 ++++-
.../apache/tinkerpop/gremlin/GraphProvider.java | 3 +-
.../util/detached/DetachedEdgeTest.java | 4 +-
.../util/detached/DetachedPropertyTest.java | 2 +-
.../detached/DetachedVertexPropertyTest.java | 2 +-
.../util/detached/DetachedVertexTest.java | 6 +-
33 files changed, 565 insertions(+), 332 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
index e847772..95f72dc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
@@ -188,6 +188,10 @@ public interface GraphComputer {
}
public static class Exceptions {
+
+ private Exceptions() {
+ }
+
public static IllegalStateException adjacentElementPropertiesCanNotBeRead() {
return new IllegalStateException("The properties of an adjacent element can not be read, only its id");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Memory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Memory.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Memory.java
index 72cba8c..abae106 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Memory.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Memory.java
@@ -153,6 +153,9 @@ public interface Memory {
public static class Exceptions {
+ private Exceptions() {
+ }
+
public static IllegalArgumentException memoryKeyCanNotBeEmpty() {
return new IllegalArgumentException("Graph computer memory key can not be the empty string");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
index 3b68844..7ed0f06 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ComputerResultStep.java
@@ -31,7 +31,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.util.detached.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.util.EnumSet;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
index e2a63ed..97eef72 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
@@ -20,7 +20,7 @@ package org.apache.tinkerpop.gremlin.process.traversal;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Edge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Edge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Edge.java
index ca80bab..6df38d2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Edge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Edge.java
@@ -93,6 +93,9 @@ public interface Edge extends Element {
*/
public static class Exceptions extends Element.Exceptions {
+ private Exceptions() {
+ }
+
public static UnsupportedOperationException userSuppliedIdsNotSupported() {
return new UnsupportedOperationException("Edge does not support user supplied identifiers");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Element.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Element.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Element.java
index 4769157..a0130eb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Element.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Element.java
@@ -120,6 +120,9 @@ public abstract interface Element {
*/
public static class Exceptions {
+ protected Exceptions() {
+ }
+
public static IllegalArgumentException providedKeyValuesMustBeAMultipleOfTwo() {
return new IllegalArgumentException("The provided key/value array must be a multiple of two");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/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..7eff2a8 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
@@ -19,10 +19,10 @@
package org.apache.tinkerpop.gremlin.structure;
import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.T;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
-import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
import org.apache.tinkerpop.gremlin.structure.io.DefaultIo;
@@ -383,6 +383,9 @@ public interface Graph extends AutoCloseable {
public static class Exceptions {
+ private Exceptions() {
+ }
+
public static IllegalArgumentException variableKeyCanNotBeEmpty() {
return new IllegalArgumentException("Graph variable key can not be the empty string");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Property.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Property.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Property.java
index 997fe51..96685fa 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Property.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Property.java
@@ -132,6 +132,9 @@ public interface Property<V> {
*/
public static class Exceptions {
+ private Exceptions() {
+ }
+
public static IllegalArgumentException propertyKeyCanNotBeEmpty() {
return new IllegalArgumentException("Property key can not be the empty string");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
index 27df0d3..4a26373 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
@@ -121,6 +121,10 @@ public interface Transaction extends Closeable {
}
public static class Exceptions {
+
+ private Exceptions() {
+ }
+
public static IllegalStateException transactionAlreadyOpen() {
return new IllegalStateException("Stop the current transaction before opening another");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
index ceae58b..215cfcb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Vertex.java
@@ -146,6 +146,10 @@ public interface Vertex extends Element {
* Common exceptions to use with a vertex.
*/
public static class Exceptions {
+
+ private Exceptions() {
+ }
+
public static UnsupportedOperationException userSuppliedIdsNotSupported() {
return new UnsupportedOperationException("Vertex does not support user supplied identifiers");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexProperty.java
index 57418fa..4bdad8f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexProperty.java
@@ -85,6 +85,10 @@ public interface VertexProperty<V> extends Property<V>, Element {
* Common exceptions to use with a property.
*/
public static class Exceptions {
+
+ private Exceptions() {
+ }
+
public static UnsupportedOperationException userSuppliedIdsNotSupported() {
return new UnsupportedOperationException("VertexProperty does not support user supplied identifiers");
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GremlinClassResolver.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GremlinClassResolver.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GremlinClassResolver.java
deleted file mode 100644
index bdf4af6..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GremlinClassResolver.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.gryo;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Path;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPath;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
-import org.apache.tinkerpop.shaded.kryo.ClassResolver;
-import org.apache.tinkerpop.shaded.kryo.Kryo;
-import org.apache.tinkerpop.shaded.kryo.KryoException;
-import org.apache.tinkerpop.shaded.kryo.Registration;
-import org.apache.tinkerpop.shaded.kryo.io.Input;
-import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.apache.tinkerpop.shaded.kryo.util.IdentityObjectIntMap;
-import org.apache.tinkerpop.shaded.kryo.util.IntMap;
-import org.apache.tinkerpop.shaded.kryo.util.ObjectMap;
-
-import static org.apache.tinkerpop.shaded.kryo.util.Util.getWrapperClass;
-
-/**
- * This mapper implementation of the {@code ClassResolver} helps ensure that all Vertex and Edge concrete classes
- * get properly serialized and deserialized by stripping them of their concrete class name so that they are treated
- * generically.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-class GremlinClassResolver implements ClassResolver {
- static public final byte NAME = -1;
-
- protected Kryo kryo;
-
- protected final IntMap<Registration> idToRegistration = new IntMap<>();
- protected final ObjectMap<Class, Registration> classToRegistration = new ObjectMap<>();
-
- protected IdentityObjectIntMap<Class> classToNameId;
- protected IntMap<Class> nameIdToClass;
- protected ObjectMap<String, Class> nameToClass;
- protected int nextNameId;
-
- private int memoizedClassId = -1;
- private Registration memoizedClassIdValue;
- private Class memoizedClass;
- private Registration memoizedClassValue;
-
- @Override
- public void setKryo(Kryo kryo) {
- this.kryo = kryo;
- }
-
- @Override
- public Registration register(final Registration registration) {
- if (null == registration) throw new IllegalArgumentException("Registration cannot be null.");
- if (registration.getId() != NAME) idToRegistration.put(registration.getId(), registration);
-
- classToRegistration.put(registration.getType(), registration);
- if (registration.getType().isPrimitive())
- classToRegistration.put(getWrapperClass(registration.getType()), registration);
- return registration;
- }
-
- @Override
- public Registration registerImplicit(final Class type) {
- return register(new Registration(type, kryo.getDefaultSerializer(type), NAME));
- }
-
- @Override
- public Registration getRegistration(final Class clazz) {
- // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface
- final Class type;
- if (!DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz))
- type = Vertex.class;
- else if (!DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz))
- type = Edge.class;
- else if (!DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
- type = VertexProperty.class;
- else if (!DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
- type = Property.class;
- else if (!DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
- type = Path.class;
- else
- type = clazz;
-
- if (type == memoizedClass) return memoizedClassValue;
- final Registration registration = classToRegistration.get(type);
- if (registration != null) {
- memoizedClass = type;
- memoizedClassValue = registration;
- }
-
- return registration;
- }
-
- @Override
- public Registration getRegistration(final int classID) {
- return idToRegistration.get(classID);
- }
-
- @Override
- public Registration writeClass(final Output output, final Class type) {
- if (null == type) {
- output.writeVarInt(Kryo.NULL, true);
- return null;
- }
-
- final Registration registration = kryo.getRegistration(type);
- if (registration.getId() == NAME)
- writeName(output, type);
- else
- output.writeVarInt(registration.getId() + 2, true);
-
- return registration;
- }
-
- protected void writeName(final Output output, final Class type) {
- output.writeVarInt(NAME + 2, true);
- if (classToNameId != null) {
- final int nameId = classToNameId.get(type, -1);
- if (nameId != -1) {
- output.writeVarInt(nameId, true);
- return;
- }
- }
- // Only write the class name the first time encountered in object graph.
- final int nameId = nextNameId++;
- if (classToNameId == null) classToNameId = new IdentityObjectIntMap<>();
- classToNameId.put(type, nameId);
- output.writeVarInt(nameId, true);
- output.writeString(type.getName());
- }
-
- @Override
- public Registration readClass(final Input input) {
- final int classID = input.readVarInt(true);
- switch (classID) {
- case Kryo.NULL:
- return null;
- case NAME + 2: // Offset for NAME and NULL.
- return readName(input);
- }
-
- if (classID == memoizedClassId) return memoizedClassIdValue;
- final Registration registration = idToRegistration.get(classID - 2);
- if (registration == null) throw new KryoException("Encountered unregistered class ID: " + (classID - 2));
- memoizedClassId = classID;
- memoizedClassIdValue = registration;
- return registration;
- }
-
- protected Registration readName(final Input input) {
- final int nameId = input.readVarInt(true);
- if (nameIdToClass == null) nameIdToClass = new IntMap<>();
- Class type = nameIdToClass.get(nameId);
- if (type == null) {
- // Only read the class name the first time encountered in object graph.
- final String className = input.readString();
- type = getTypeByName(className);
- if (type == null) {
- try {
- type = Class.forName(className, false, kryo.getClassLoader());
- } catch (ClassNotFoundException ex) {
- throw new KryoException("Unable to find class: " + className, ex);
- }
- if (nameToClass == null) nameToClass = new ObjectMap<>();
- nameToClass.put(className, type);
- }
- nameIdToClass.put(nameId, type);
- }
- return kryo.getRegistration(type);
- }
-
- protected Class<?> getTypeByName(final String className) {
- return nameToClass != null ? nameToClass.get(className) : null;
- }
-
- @Override
- public void reset() {
- if (!kryo.isRegistrationRequired()) {
- if (classToNameId != null) classToNameId.clear();
- if (nameIdToClass != null) nameIdToClass.clear();
- nextNameId = 0;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
new file mode 100644
index 0000000..3676754
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.gryo;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPath;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferencePath;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceProperty;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
+import org.apache.tinkerpop.shaded.kryo.ClassResolver;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.KryoException;
+import org.apache.tinkerpop.shaded.kryo.Registration;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
+import org.apache.tinkerpop.shaded.kryo.util.IdentityObjectIntMap;
+import org.apache.tinkerpop.shaded.kryo.util.IntMap;
+import org.apache.tinkerpop.shaded.kryo.util.ObjectMap;
+
+import static org.apache.tinkerpop.shaded.kryo.util.Util.getWrapperClass;
+
+/**
+ * This mapper implementation of the {@code ClassResolver} helps ensure that all Vertex and Edge concrete classes
+ * get properly serialized and deserialized by stripping them of their concrete class name so that they are treated
+ * generically.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+class GryoClassResolver implements ClassResolver {
+ static public final byte NAME = -1;
+
+ protected Kryo kryo;
+
+ protected final IntMap<Registration> idToRegistration = new IntMap<>();
+ protected final ObjectMap<Class, Registration> classToRegistration = new ObjectMap<>();
+
+ protected IdentityObjectIntMap<Class> classToNameId;
+ protected IntMap<Class> nameIdToClass;
+ protected ObjectMap<String, Class> nameToClass;
+ protected int nextNameId;
+
+ private int memoizedClassId = -1;
+ private Registration memoizedClassIdValue;
+ private Class memoizedClass;
+ private Registration memoizedClassValue;
+
+ @Override
+ public void setKryo(Kryo kryo) {
+ this.kryo = kryo;
+ }
+
+ @Override
+ public Registration register(final Registration registration) {
+ if (null == registration) throw new IllegalArgumentException("Registration cannot be null.");
+ if (registration.getId() != NAME) idToRegistration.put(registration.getId(), registration);
+
+ classToRegistration.put(registration.getType(), registration);
+ if (registration.getType().isPrimitive())
+ classToRegistration.put(getWrapperClass(registration.getType()), registration);
+ return registration;
+ }
+
+ @Override
+ public Registration registerImplicit(final Class type) {
+ return register(new Registration(type, kryo.getDefaultSerializer(type), NAME));
+ }
+
+ @Override
+ public Registration getRegistration(final Class clazz) {
+ // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface
+ final Class type;
+ if (!ReferenceVertex.class.isAssignableFrom(clazz) && !DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz))
+ type = Vertex.class;
+ else if (!ReferenceEdge.class.isAssignableFrom(clazz) && !DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz))
+ type = Edge.class;
+ else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
+ type = VertexProperty.class;
+ else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
+ type = Property.class;
+ else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
+ type = Path.class;
+ else
+ type = clazz;
+
+ if (type == memoizedClass) return memoizedClassValue;
+ final Registration registration = classToRegistration.get(type);
+ if (registration != null) {
+ memoizedClass = type;
+ memoizedClassValue = registration;
+ }
+
+ return registration;
+ }
+
+ @Override
+ public Registration getRegistration(final int classID) {
+ return idToRegistration.get(classID);
+ }
+
+ @Override
+ public Registration writeClass(final Output output, final Class type) {
+ if (null == type) {
+ output.writeVarInt(Kryo.NULL, true);
+ return null;
+ }
+
+ final Registration registration = kryo.getRegistration(type);
+ if (registration.getId() == NAME)
+ writeName(output, type);
+ else
+ output.writeVarInt(registration.getId() + 2, true);
+
+ return registration;
+ }
+
+ protected void writeName(final Output output, final Class type) {
+ output.writeVarInt(NAME + 2, true);
+ if (classToNameId != null) {
+ final int nameId = classToNameId.get(type, -1);
+ if (nameId != -1) {
+ output.writeVarInt(nameId, true);
+ return;
+ }
+ }
+ // Only write the class name the first time encountered in object graph.
+ final int nameId = nextNameId++;
+ if (classToNameId == null) classToNameId = new IdentityObjectIntMap<>();
+ classToNameId.put(type, nameId);
+ output.writeVarInt(nameId, true);
+ output.writeString(type.getName());
+ }
+
+ @Override
+ public Registration readClass(final Input input) {
+ final int classID = input.readVarInt(true);
+ switch (classID) {
+ case Kryo.NULL:
+ return null;
+ case NAME + 2: // Offset for NAME and NULL.
+ return readName(input);
+ }
+
+ if (classID == memoizedClassId) return memoizedClassIdValue;
+ final Registration registration = idToRegistration.get(classID - 2);
+ if (registration == null) throw new KryoException("Encountered unregistered class ID: " + (classID - 2));
+ memoizedClassId = classID;
+ memoizedClassIdValue = registration;
+ return registration;
+ }
+
+ protected Registration readName(final Input input) {
+ final int nameId = input.readVarInt(true);
+ if (nameIdToClass == null) nameIdToClass = new IntMap<>();
+ Class type = nameIdToClass.get(nameId);
+ if (type == null) {
+ // Only read the class name the first time encountered in object graph.
+ final String className = input.readString();
+ type = getTypeByName(className);
+ if (type == null) {
+ try {
+ type = Class.forName(className, false, kryo.getClassLoader());
+ } catch (ClassNotFoundException ex) {
+ throw new KryoException("Unable to find class: " + className, ex);
+ }
+ if (nameToClass == null) nameToClass = new ObjectMap<>();
+ nameToClass.put(className, type);
+ }
+ nameIdToClass.put(nameId, type);
+ }
+ return kryo.getRegistration(type);
+ }
+
+ protected Class<?> getTypeByName(final String className) {
+ return nameToClass != null ? nameToClass.get(className) : null;
+ }
+
+ @Override
+ public void reset() {
+ if (!kryo.isRegistrationRequired()) {
+ if (classToNameId != null) classToNameId.clear();
+ if (nameIdToClass != null) nameIdToClass.clear();
+ nextNameId = 0;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 2a74661..17b09e5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -120,7 +120,7 @@ public final class GryoMapper implements Mapper<Kryo> {
@Override
public Kryo createMapper() {
- final Kryo kryo = new Kryo(new GremlinClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory());
+ final Kryo kryo = new Kryo(new GryoClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory());
kryo.addDefaultSerializer(Map.Entry.class, new EntrySerializer());
kryo.setRegistrationRequired(true);
serializationList.forEach(p -> {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
new file mode 100644
index 0000000..8a9ed27
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.util;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+
+/**
+ * An interface that provides methods for detached properties and elements to be re-attached to the {@link Graph}.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public interface Attachable<T> {
+ public abstract T attach(final Vertex hostVertex) throws IllegalStateException;
+
+ public abstract T attach(final Graph hostGraph) throws IllegalStateException;
+
+ public static class Exceptions {
+
+ private Exceptions() {
+ }
+
+ public static IllegalStateException canNotAttachVertexToHostVertex(final Attachable<Vertex> vertex, final Vertex hostVertex) {
+ return new IllegalStateException("The provided vertex is not the host vertex: " + vertex + " does not equal " + hostVertex);
+ }
+
+ public static IllegalStateException canNotAttachVertexToHostGraph(final Attachable<Vertex> vertex, final Graph hostGraph) {
+ return new IllegalStateException("The provided vertex could not be found in the host graph: " + vertex + " not in " + hostGraph);
+ }
+
+ public static IllegalStateException canNotAttachEdgeToHostVertex(final Attachable<Edge> edge, final Vertex hostVertex) {
+ return new IllegalStateException("The provided edge is not incident to the host vertex: " + edge + " not incident to " + hostVertex);
+ }
+
+ public static IllegalStateException canNotAttachEdgeToHostGraph(final Attachable<Edge> edge, final Graph hostGraph) {
+ return new IllegalStateException("The provided edge could not be found in the host graph: " + edge + " not in " + hostGraph);
+ }
+
+ public static IllegalStateException canNotAttachVertexPropertyToHostVertex(final Attachable<VertexProperty> vertexProperty, final Vertex hostVertex) {
+ return new IllegalStateException("The provided vertex property is not a property of the host vertex: " + vertexProperty + " not a property of " + hostVertex);
+ }
+
+ public static IllegalStateException canNotAttachVertexPropertyToHostGraph(final Attachable<VertexProperty> vertexProperty, final Graph hostGraph) {
+ return new IllegalStateException("The provided vertex property could not be found in the host graph: " + vertexProperty + " not in " + hostGraph);
+ }
+
+ public static IllegalStateException canNotAttachPropertyToHostVertex(final Attachable<Property> property, final Vertex hostVertex) {
+ return new IllegalStateException("The provided property could not be attached the host vertex: " + property + " not a property in the star of " + hostVertex);
+ }
+
+ public static IllegalStateException canNotAttachPropertyToHostGraph(final Attachable<Property> property, final Graph hostGraph) {
+ return new IllegalStateException("The provided property could not be attached the host graph: " + property + " not in " + hostGraph);
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/Attachable.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/Attachable.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/Attachable.java
deleted file mode 100644
index c07a3ec..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/Attachable.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.util.detached;
-
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-
-/**
- * An interface that provides methods for detached properties and elements to be re-attached to the {@link Graph}.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public interface Attachable<T> {
- public abstract T attach(final Vertex hostVertex) throws IllegalStateException;
-
- public abstract T attach(final Graph hostGraph) throws IllegalStateException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
index 1013129..f32b77d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -97,7 +98,7 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
public Edge attach(final Vertex hostVertex) {
final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT, this.label), edge -> edge.equals(this));
if (!edges.hasNext())
- throw new IllegalStateException("The detached edge could not be found incident to the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
return edges.next();
}
@@ -105,7 +106,7 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
public Edge attach(final Graph hostGraph) {
final Iterator<Edge> edges = hostGraph.edges(this.id);
if (!edges.hasNext())
- throw new IllegalStateException("The detached edge could not be found in the provided graph: " + this);
+ throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
return edges.next();
}
@@ -151,6 +152,11 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
}
@Override
+ public void remove() {
+ throw Edge.Exceptions.edgeRemovalNotSupported();
+ }
+
+ @Override
public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
return (Iterator) super.properties(propertyKeys);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
index d2716b1..54e448c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
@@ -21,7 +21,9 @@ package org.apache.tinkerpop.gremlin.structure.util.detached;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import java.io.Serializable;
import java.util.Collections;
@@ -54,7 +56,7 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
@Override
public Graph graph() {
- throw new UnsupportedOperationException("The detached element is no longer attached to a graph");
+ return EmptyGraph.instance();
}
@Override
@@ -69,7 +71,7 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
@Override
public <V> Property<V> property(final String key, final V value) {
- throw new UnsupportedOperationException("Detached elements are readonly: " + this);
+ throw Element.Exceptions.propertyAdditionNotSupported();
}
@Override
@@ -78,11 +80,6 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
}
@Override
- public void remove() {
- throw new UnsupportedOperationException("Detached elements are readonly: " + this);
- }
-
- @Override
public int hashCode() {
return ElementHelper.hashCode(this);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
index 4f0aa2b..90160e5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -68,8 +69,4 @@ public class DetachedPath extends MutablePath implements Attachable<Path> {
this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex) : object, labels.toArray(new String[labels.size()])));
return path;
}
-
- public String toString() {
- return this.objects.toString();
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
index e09039f..2ebee47 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -31,7 +32,7 @@ import java.io.Serializable;
* @author Stephen Mallette (http://stephen.genoprime.com)
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class DetachedProperty<V> implements Property, Serializable, Attachable<Property<V>> {
+public class DetachedProperty<V> implements Property, Serializable, Attachable<Property> {
private String key;
private V value;
@@ -52,7 +53,6 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
this.element = DetachedFactory.detach(element, false);
}
-
@Override
public boolean isPresent() {
return true;
@@ -75,7 +75,7 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
@Override
public void remove() {
- throw new UnsupportedOperationException("Detached properties are readonly: " + this.toString());
+ throw Element.Exceptions.propertyRemovalNotSupported();
}
@Override
@@ -98,19 +98,19 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
public Property<V> attach(final Vertex hostVertex) {
final Element element = (Element) this.element.attach(hostVertex);
final Property<V> property = element.property(this.key);
- if (property.isPresent())
+ if (property.isPresent() && property.value().equals(this.value))
return property;
else
- throw new IllegalStateException("The detached property could not be be found at the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex);
}
@Override
public Property<V> attach(final Graph hostGraph) {
final Element hostElement = (Element) this.element.attach(hostGraph);
final Property<V> property = hostElement.property(this.key);
- if (property.isPresent())
+ if (property.isPresent() && property.value().equals(this.value))
return property;
else
- throw new IllegalStateException("The detached property could not be be found at the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
index 24eee2c..85b1e3a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
@@ -19,16 +19,18 @@
package org.apache.tinkerpop.gremlin.structure.util.detached;
import org.apache.tinkerpop.gremlin.process.traversal.T;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -88,12 +90,12 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
@Override
public <V> VertexProperty<V> property(final String key, final V value) {
- throw new UnsupportedOperationException("Detached vertices are readonly: " + this);
+ throw Element.Exceptions.propertyAdditionNotSupported();
}
@Override
public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
- throw new UnsupportedOperationException("Detached vertices are readonly: " + this);
+ throw Element.Exceptions.propertyAdditionNotSupported();
}
@Override
@@ -110,7 +112,7 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
@Override
public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
- throw new UnsupportedOperationException("Detached vertices do not store edges: " + this);
+ throw Vertex.Exceptions.edgeAdditionsNotSupported();
}
@Override
@@ -123,12 +125,16 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
if (hostVertex.equals(this))
return hostVertex;
else
- throw new IllegalStateException("The host vertex must be the detached vertex to attach: " + this + "!=" + hostVertex);
+ throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex);
}
@Override
public Vertex attach(final Graph hostGraph) {
- return hostGraph.vertices(this.id).next();
+ final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
+ if(iterator.hasNext())
+ return iterator.next();
+ else
+ throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph);
}
public static Vertex addTo(final Graph graph, final DetachedVertex detachedVertex) {
@@ -161,12 +167,17 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
}
@Override
- public GraphTraversal<Vertex, Edge> edges(final Direction direction, final String... edgeLabels) {
- throw new UnsupportedOperationException("Detached vertices do not have edges");
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... labels) {
+ return Collections.emptyIterator();
}
@Override
- public GraphTraversal<Vertex, Vertex> vertices(final Direction direction, final String... labels) {
- throw new UnsupportedOperationException("Detached vertices do not have edges and thus, adjacent vertices can not be accessed");
+ public void remove() {
+ throw Vertex.Exceptions.vertexRemovalNotSupported();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
index 253b647..ac01526 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
@@ -18,10 +18,12 @@
*/
package org.apache.tinkerpop.gremlin.structure.util.detached;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -95,7 +97,7 @@ public class DetachedVertexProperty<V> extends DetachedElement<Property<V>> impl
@Override
public void remove() {
- throw new UnsupportedOperationException("Detached properties are readonly: " + this.toString());
+ throw Element.Exceptions.propertyRemovalNotSupported();
}
@Override
@@ -113,7 +115,7 @@ public class DetachedVertexProperty<V> extends DetachedElement<Property<V>> impl
public VertexProperty<V> attach(final Vertex hostVertex) {
final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(this.label), vp -> ElementHelper.areEqual(this, vp));
if (!vertexPropertyIterator.hasNext())
- throw new IllegalStateException("The detached vertex property could not be be found at the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex((Attachable) this, hostVertex);
return vertexPropertyIterator.next();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
index 00a51d9..b221cc8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
@@ -23,16 +23,20 @@ package org.apache.tinkerpop.gremlin.structure.util.reference;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import java.util.Collections;
import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceEdge extends ReferenceElement<Edge> {
+public class ReferenceEdge extends ReferenceElement<Edge> implements Edge {
private ReferenceEdge() {
@@ -46,7 +50,7 @@ public class ReferenceEdge extends ReferenceElement<Edge> {
public Edge attach(final Vertex hostVertex) {
final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT), edge -> edge.id().equals(this.id));
if (!edges.hasNext())
- throw new IllegalStateException("The reference edge could not be found incident to the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
return edges.next();
}
@@ -54,21 +58,32 @@ public class ReferenceEdge extends ReferenceElement<Edge> {
public Edge attach(final Graph hostGraph) {
final Iterator<Edge> edges = hostGraph.edges(this.id);
if (!edges.hasNext())
- throw new IllegalStateException("The reference edge could not be found in the provided graph: " + this);
+ throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
return edges.next();
}
@Override
- public String toString() {
- return "e*[" + this.id + "]";
+ public <V> Property<V> property(final String key, final V value) {
+ throw Element.Exceptions.propertyAdditionNotSupported();
+ }
+
+ @Override
+ public void remove() {
+ throw Edge.Exceptions.edgeRemovalNotSupported();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction) {
+ return Collections.emptyIterator();
}
@Override
- public boolean equals(final Object object) {
- if (object instanceof ReferenceEdge)
- return this.id.equals(((ReferenceEdge) object).id);
- else
- return object instanceof Edge && this.id.equals(((Edge) object).id());
+ public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
+ return Collections.emptyIterator();
}
+ @Override
+ public String toString() {
+ return "e[" + this.id + "]";
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
index ebf6aa9..f330395 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
@@ -22,14 +22,19 @@
package org.apache.tinkerpop.gremlin.structure.util.reference;
import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.util.detached.Attachable;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import java.io.Serializable;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public abstract class ReferenceElement<E extends Element> implements Serializable, Attachable<E> {
+public abstract class ReferenceElement<E extends Element> implements Element, Serializable, Attachable<E> {
+
+ protected static final String EMPTY_STRING = "";
protected Object id;
@@ -42,7 +47,28 @@ public abstract class ReferenceElement<E extends Element> implements Serializabl
}
@Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public String label() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public Graph graph() {
+ return EmptyGraph.instance();
+ }
+
+ @Override
public int hashCode() {
- return this.id.hashCode();
+ return ElementHelper.hashCode(this);
+ }
+
+ @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
index 696bc44..c91299e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
@@ -27,7 +27,7 @@ import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -72,8 +72,4 @@ public class ReferencePath extends MutablePath implements Attachable<Path> {
this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex) : object, labels.toArray(new String[labels.size()])));
return path;
}
-
- public String toString() {
- return this.objects.toString();
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
index 9afc9d2..689ec3e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
@@ -21,21 +21,25 @@
package org.apache.tinkerpop.gremlin.structure.util.reference;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.detached.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import java.io.Serializable;
+import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceProperty<V> implements Attachable<Property<V>>, Serializable {
+public class ReferenceProperty<V> implements Attachable<Property>, Serializable, Property<V> {
private ReferenceElement<?> element;
private String key;
- private Object value;
+ private V value;
private ReferenceProperty() {
@@ -44,33 +48,64 @@ public class ReferenceProperty<V> implements Attachable<Property<V>>, Serializab
public ReferenceProperty(final Property<V> property) {
this.element = ReferenceFactory.detach(property.element());
this.key = property.key();
+ this.value = property.value();
}
@Override
public Property<V> attach(final Vertex hostVertex) throws IllegalStateException {
- return this.element.attach(hostVertex).property(this.key);
+ final Property<V> property = this.element.attach(hostVertex).property(this.key);
+ if (property.isPresent() && property.value().equals(this.value))
+ return property;
+ else
+ throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex);
}
@Override
public Property<V> attach(final Graph hostGraph) throws IllegalStateException {
- return this.element.attach(hostGraph).property(this.key);
+ final Property<V> property = this.element.attach(hostGraph).property(this.key);
+ if (property.isPresent() && property.value().equals(this.value))
+ return property;
+ else
+ throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph);
}
@Override
public int hashCode() {
- return this.value.hashCode() + this.key.hashCode();
+ return ElementHelper.hashCode(this);
}
@Override
public String toString() {
- return "p*[" + this.key + "->" + this.value.toString().substring(0, Math.min(this.value.toString().length(), 20)) + "]";
+ return StringFactory.propertyString(this);
}
@Override
public boolean equals(final Object object) {
- if (object instanceof ReferenceProperty)
- return ((ReferenceProperty) object).element.equals(this.element) && this.key.equals(((ReferenceProperty) object).key) && this.value.equals(((ReferenceProperty) object).value);
- else
- return object instanceof Property && this.element.equals(((Property) object).element()) && this.key.equals(((Property) object).key()) && this.value.equals(((Property) object).value());
+ return ElementHelper.areEqual(this, object);
+ }
+
+ @Override
+ public String key() {
+ return this.key;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return this.value;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Element element() {
+ return this.element;
+ }
+
+ @Override
+ public void remove() {
+ throw Element.Exceptions.propertyRemovalNotSupported();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
index 87f29aa..ac57da0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
@@ -21,13 +21,23 @@
package org.apache.tinkerpop.gremlin.structure.util.reference;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+
+import java.util.Collections;
+import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceVertex extends ReferenceElement<Vertex> {
+public class ReferenceVertex extends ReferenceElement<Vertex> implements Vertex {
private ReferenceVertex() {
@@ -39,27 +49,53 @@ public class ReferenceVertex extends ReferenceElement<Vertex> {
@Override
public Vertex attach(final Vertex hostVertex) {
- if (hostVertex.id().equals(this.id))
+ if (ElementHelper.areEqual(this,hostVertex))
return hostVertex;
else
- throw new IllegalStateException("The host vertex must be the reference vertex to attach: " + this + "!=" + hostVertex);
+ throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex);
}
@Override
public Vertex attach(final Graph hostGraph) {
- return hostGraph.vertices(this.id).next();
+ final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
+ if (iterator.hasNext())
+ return iterator.next();
+ else
+ throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph);
}
@Override
- public String toString() {
- return "v*[" + this.id + "]";
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ throw Vertex.Exceptions.edgeAdditionsNotSupported();
}
@Override
- public boolean equals(final Object object) {
- if (object instanceof ReferenceVertex)
- return this.id.equals(((ReferenceVertex) object).id);
- else
- return object instanceof Vertex && this.id.equals(((Vertex) object).id());
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
+ throw Element.Exceptions.propertyAdditionNotSupported();
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public void remove() {
+ throw Vertex.Exceptions.vertexRemovalNotSupported();
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.vertexString(this);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
index 636b54b..4ef4913 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
@@ -21,17 +21,22 @@
package org.apache.tinkerpop.gremlin.structure.util.reference;
+import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import java.util.Collections;
import java.util.Iterator;
+import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty> {
+public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty> implements VertexProperty<V> {
private ReferenceVertexProperty() {
@@ -45,7 +50,7 @@ public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty>
public VertexProperty<V> attach(final Vertex hostVertex) {
final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(), vp -> vp.id().equals(this.id));
if (!vertexPropertyIterator.hasNext())
- throw new IllegalStateException("The reference vertex property could not be be found at the provided vertex: " + this);
+ throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
return vertexPropertyIterator.next();
}
@@ -56,14 +61,41 @@ public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty>
@Override
public String toString() {
- return "vp*[" + this.id + "]";
+ return "vp[" + this.id + "]";
}
@Override
- public boolean equals(final Object object) {
- if (object instanceof ReferenceVertexProperty)
- return this.id.equals(((ReferenceVertexProperty) object).id);
- else
- return object instanceof VertexProperty && this.id.equals(((VertexProperty) object).id());
+ public String key() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return null;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Vertex element() {
+ return null;
+ }
+
+ @Override
+ public <U> Property<U> property(final String key, final U value) {
+ throw Element.Exceptions.propertyAdditionNotSupported();
+ }
+
+ @Override
+ public void remove() {
+ throw Element.Exceptions.propertyRemovalNotSupported();
+ }
+
+ @Override
+ public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
+ return Collections.emptyIterator();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/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..3df0267 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
@@ -37,6 +37,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import java.util.Collections;
@@ -218,7 +219,7 @@ public interface GraphProvider {
* When serializing a mapper identifier type to GraphSON an implementer will typically specify a mapper serializer
* in {@link org.apache.tinkerpop.gremlin.structure.Graph.Io}. That will serialize the identifier to a GraphSON representation.
* When the GraphSON is deserialized, the identifier is written to an
- * {@link org.apache.tinkerpop.gremlin.structure.util.detached.Attachable} object where it is passed to a user supplied
+ * {@link Attachable} object where it is passed to a user supplied
* conversion {@link java.util.function.Function} that ultimately processes it. It is in this conversion process
* that vendor specific identifier conversion would occur (if desired). This method mimics that conversion by
* providing the mechanism that a test can use to do the conversion.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
index 5aae34a..12cba03 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdgeTest.java
@@ -163,7 +163,7 @@ public class DetachedEdgeTest extends AbstractGremlinTest {
assertEquals("y", de.property("y").key());
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldNotAllowSetProperty() {
final Vertex v = graph.addVertex();
@@ -172,7 +172,7 @@ public class DetachedEdgeTest extends AbstractGremlinTest {
detachedEdge.property("test", "test");
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldNotAllowRemove() {
final Vertex v = graph.addVertex();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
index 6601960..299d089 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
@@ -54,7 +54,7 @@ public class DetachedPropertyTest extends AbstractGremlinTest {
assertEquals(DetachedEdge.class, p.element().getClass());
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldNotSupportRemove() {
DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next().property("weight")).remove();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
index 19bbaef..3ac0131 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
@@ -65,7 +65,7 @@ public class DetachedVertexPropertyTest extends AbstractGremlinTest {
assertEquals(DetachedVertex.class, mp.element().getClass());
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldNotSupportRemove() {
final Vertex v = graph.addVertex();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/885ca509/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
index 01a6f78..5041892 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
@@ -231,7 +231,7 @@ public class DetachedVertexTest extends AbstractGremlinTest {
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldNotAllowAddEdge() {
final Vertex v = graph.addVertex();
@@ -239,7 +239,7 @@ public class DetachedVertexTest extends AbstractGremlinTest {
detachedVertex.addEdge("test", null);
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldNotAllowSetProperty() {
final Vertex v = graph.addVertex();
@@ -247,7 +247,7 @@ public class DetachedVertexTest extends AbstractGremlinTest {
detachedVertex.property("test", "test");
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test(expected = IllegalStateException.class)
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldNotAllowRemove() {
final Vertex v = graph.addVertex();