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/21 19:20:30 UTC

incubator-tinkerpop git commit: not finished, but saving for now the new attachable work.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/attachable_work [created] 58a63998a


not finished, but saving for now the new attachable work.


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

Branch: refs/heads/attachable_work
Commit: 58a63998afa27c46c0f718ce741f941258f31a9f
Parents: 8562f50
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 21 11:20:22 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 21 11:20:22 2015 -0600

----------------------------------------------------------------------
 .../gremlin/structure/util/Attachable.java      | 266 ++++++++++++++++++-
 .../structure/util/detached/DetachedEdge.java   |  21 +-
 .../util/detached/DetachedElement.java          |   4 +
 .../structure/util/detached/DetachedPath.java   |  12 +-
 .../util/detached/DetachedProperty.java         |  18 +-
 .../structure/util/detached/DetachedVertex.java |  22 +-
 .../util/detached/DetachedVertexProperty.java   |  14 +-
 .../structure/util/reference/ReferenceEdge.java |  16 +-
 .../util/reference/ReferenceElement.java        |   4 +
 .../structure/util/reference/ReferencePath.java |  12 +-
 .../util/reference/ReferenceProperty.java       |  19 +-
 .../util/reference/ReferenceVertex.java         |  16 +-
 .../util/reference/ReferenceVertexProperty.java |  14 +-
 .../gremlin/structure/util/star/StarGraph.java  |  15 +-
 14 files changed, 373 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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
index 8a9ed27..ba50374 100644
--- 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
@@ -18,21 +18,272 @@
  */
 package org.apache.tinkerpop.gremlin.structure.util;
 
+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 java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
 /**
  * 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 enum Method implements BiFunction<Attachable, Object, Object> {
+
+        GET {
+            @Override
+            public Object apply(final Attachable attachable, final Object hostVertexOrGraph) {
+                final Object base = attachable.get();
+                if (base instanceof Vertex) {
+                    final Optional<Vertex> optional = hostVertexOrGraph instanceof Graph ?
+                            Method.getVertex(attachable, (Graph) hostVertexOrGraph) :
+                            Method.getVertex(attachable, (Vertex) hostVertexOrGraph);
+                    return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+                } else if (base instanceof Edge) {
+                    final Optional<Edge> optional = hostVertexOrGraph instanceof Graph ?
+                            Method.getEdge(attachable, (Graph) hostVertexOrGraph) :
+                            Method.getEdge(attachable, (Vertex) hostVertexOrGraph);
+                    return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+                } else if (base instanceof VertexProperty) {
+                    final Optional<VertexProperty> optional = hostVertexOrGraph instanceof Graph ?
+                            Method.getVertexProperty(attachable, (Graph) hostVertexOrGraph) :
+                            Method.getVertexProperty(attachable, (Vertex) hostVertexOrGraph);
+                    return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+                } else if (base instanceof Property) {
+                    final Optional<Property> optional = hostVertexOrGraph instanceof Graph ?
+                            Method.getProperty(attachable, (Graph) hostVertexOrGraph) :
+                            Method.getProperty(attachable, (Vertex) hostVertexOrGraph);
+                    return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+                } else {
+                    throw new IllegalArgumentException("The attachable must contain an graph object");
+                }
+            }
+        },
+
+        CREATE {
+            @Override
+            public Object apply(final Attachable attachable, final Object hostVertexOrGraph) {
+                final Object base = attachable.get();
+                if (base instanceof Vertex) {
+                    return hostVertexOrGraph instanceof Graph ?
+                            Method.createVertex(attachable, (Graph) hostVertexOrGraph) :
+                            Method.createVertex(attachable, (Vertex) hostVertexOrGraph);
+                } else if (base instanceof Edge) {
+                    return hostVertexOrGraph instanceof Graph ?
+                            Method.createEdge(attachable, (Graph) hostVertexOrGraph) :
+                            Method.createEdge(attachable, (Vertex) hostVertexOrGraph);
+                } else if (base instanceof VertexProperty) {
+                    return hostVertexOrGraph instanceof Graph ?
+                            Method.createVertexProperty(attachable, (Graph) hostVertexOrGraph) :
+                            Method.createVertexProperty(attachable, (Vertex) hostVertexOrGraph);
+                } else if (base instanceof Property) {
+                    return hostVertexOrGraph instanceof Graph ?
+                            Method.createProperty(attachable, (Graph) hostVertexOrGraph) :
+                            Method.createProperty(attachable, (Vertex) hostVertexOrGraph);
+                } else {
+                    throw new IllegalArgumentException("The attachable must contain an graph object");
+                }
+            }
+        };
+
+        ///////////////////
+
+        public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) {
+            final Iterator<Vertex> vertexIterator = hostGraph.vertices(attachableVertex.get().id());
+            return vertexIterator.hasNext() ? Optional.of(vertexIterator.next()) : Optional.empty();
+        }
+
+        public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Vertex hostVertex) {
+            return ElementHelper.areEqual(attachableVertex.get(), hostVertex) ? Optional.of(hostVertex) : Optional.empty();
+        }
+
+        public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
+            final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id());
+            return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty();
+        }
+
+        public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
+            final Object baseId = attachableEdge.get().id();
+            final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
+            while (edgeIterator.hasNext()) {
+                final Edge edge = edgeIterator.next();
+                if (edge.id().equals(baseId))
+                    return Optional.of(edge);
+            }
+            return Optional.empty();
+        }
+
+        public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) {
+            final VertexProperty baseVertexProperty = attachableVertexProperty.get();
+            final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id());
+            if (vertexIterator.hasNext()) {
+                final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key());
+                while (vertexPropertyIterator.hasNext()) {
+                    final VertexProperty vertexProperty = vertexPropertyIterator.next();
+                    if (ElementHelper.areEqual(vertexProperty, baseVertexProperty))
+                        return Optional.of(vertexProperty);
+                }
+            }
+            return Optional.empty();
+        }
+
+        public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) {
+            final VertexProperty baseVertexProperty = attachableVertexProperty.get();
+            final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(baseVertexProperty.key());
+            while (vertexPropertyIterator.hasNext()) {
+                final VertexProperty vertexProperty = vertexPropertyIterator.next();
+                if (ElementHelper.areEqual(vertexProperty, baseVertexProperty))
+                    return Optional.of(vertexProperty);
+            }
+            return Optional.empty();
+        }
+
+        public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) {
+            final Property baseProperty = attachableProperty.get();
+            final Element propertyElement = attachableProperty.get().element();
+            if (propertyElement instanceof Edge) {
+                final Iterator<Edge> edgeIterator = hostGraph.edges(propertyElement.id());
+                if (edgeIterator.hasNext()) {
+                    final Property property = edgeIterator.next().property(baseProperty.key());
+                    if (property.isPresent() && property.value().equals(baseProperty.value()))
+                        return Optional.of(property);
+                }
+                return Optional.empty();
+            } else {
+                final Iterator<Vertex> vertexIterator = hostGraph.vertices(((VertexProperty) propertyElement).element().id());
+                if (vertexIterator.hasNext()) {
+                    final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties();
+                    while (vertexPropertyIterator.hasNext()) {
+                        final VertexProperty vertexProperty = vertexPropertyIterator.next();
+                        if (ElementHelper.areEqual(vertexProperty, baseProperty.element())) {
+                            final Property property = vertexProperty.property(baseProperty.key());
+                            if (property.isPresent() && property.value().equals(baseProperty.value()))
+                                return Optional.of(property);
+                            else
+                                return Optional.empty();
+                        }
+                    }
+                }
+                return Optional.empty();
+            }
+        }
+
+        public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) {
+            final Property baseProperty = attachableProperty.get();
+            final Element propertyElement = attachableProperty.get().element();
+            if (propertyElement instanceof Edge) {
+                final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
+                if (edgeIterator.hasNext()) {
+                    final Property property = edgeIterator.next().property(baseProperty.key());
+                    if (property.isPresent() && property.value().equals(baseProperty.value()))
+                        return Optional.of(property);
+                }
+                return Optional.empty();
+            } else {
+                final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties();
+                while (vertexPropertyIterator.hasNext()) {
+                    final VertexProperty vertexProperty = vertexPropertyIterator.next();
+                    if (ElementHelper.areEqual(vertexProperty, baseProperty.element())) {
+                        final Property property = vertexProperty.property(baseProperty.key());
+                        if (property.isPresent() && property.value().equals(baseProperty.value()))
+                            return Optional.of(property);
+                        else
+                            return Optional.empty();
+                    }
+                }
+                return Optional.empty();
+            }
+        }
+
+        /////
+
+        public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) {
+            final Vertex baseVertex = attachableVertex.get();
+            final List<Object> keyValues = new ArrayList<>();
+            keyValues.add(org.apache.tinkerpop.gremlin.process.traversal.T.id);
+            keyValues.add(baseVertex.id());
+            keyValues.add(org.apache.tinkerpop.gremlin.process.traversal.T.label);
+            keyValues.add(baseVertex.label());
+            final Vertex vertex = hostGraph.addVertex(keyValues.toArray());
+            baseVertex.properties().forEachRemaining(vp -> {
+                final VertexProperty vertexProperty = vertex.property(VertexProperty.Cardinality.list, vp.key(), vp.value());
+                vp.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
+            });
+            return vertex;
+        }
+
+        public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Vertex hostVertex) {
+            throw new IllegalStateException("It is not possible to create a vertex at a host vertex");
+        }
+
+        public static Edge createEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
+            final Edge baseEdge = attachableEdge.get();
+            Iterator<Vertex> vertices = hostGraph.vertices(baseEdge.outVertex().id());
+            final Vertex outV = vertices.hasNext() ? vertices.next() : hostGraph.addVertex(org.apache.tinkerpop.gremlin.process.traversal.T.id, baseEdge.outVertex().id());
+            vertices = hostGraph.vertices(baseEdge.inVertex().id());
+            final Vertex inV = vertices.hasNext() ? vertices.next() : hostGraph.addVertex(org.apache.tinkerpop.gremlin.process.traversal.T.id, baseEdge.inVertex().id());
+            if (ElementHelper.areEqual(outV, inV)) {
+                final Iterator<Edge> itty = outV.edges(Direction.OUT, baseEdge.label());
+                while (itty.hasNext()) {
+                    final Edge e = itty.next();
+                    if (ElementHelper.areEqual(baseEdge, e))
+                        return e;
+                }
+            }
+            final Edge e = outV.addEdge(baseEdge.label(), inV, org.apache.tinkerpop.gremlin.process.traversal.T.id, baseEdge.id());
+            baseEdge.properties().forEachRemaining(p -> e.property(p.key(), p.value()));
+            return e;
+        }
+
+        public static Edge createEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
+            return Method.createEdge(attachableEdge, hostVertex.graph());
+        }
+
+        public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) {
+            final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get();
+            final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id());
+            if (vertexIterator.hasNext()) {
+                final VertexProperty vertexProperty = vertexIterator.next().property(VertexProperty.Cardinality.list, baseVertexProperty.key(), baseVertexProperty.value(), org.apache.tinkerpop.gremlin.process.traversal.T.id, baseVertexProperty.id());
+                baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
+                return vertexProperty;
+            }
+            throw new IllegalStateException("Could not find vertex to add the vertex property to");
+        }
+
+        public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) {
+            final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get();
+            final VertexProperty vertexProperty = hostVertex.property(VertexProperty.Cardinality.list, baseVertexProperty.key(), baseVertexProperty.value(), org.apache.tinkerpop.gremlin.process.traversal.T.id, baseVertexProperty.id());
+            baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
+            return vertexProperty;
+        }
+
+        public static Property createProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) {
+            return null;
+
+        }
+
+        public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) {
+            return null;
+        }
+
+    }
+
+    public T get();
+
+    public T attach(final Vertex hostVertex, final Method method) throws IllegalStateException;
+
+    public T attach(final Graph hostGraph, final Method method) throws IllegalStateException;
 
-    public abstract T attach(final Graph hostGraph) throws IllegalStateException;
 
     public static class Exceptions {
 
@@ -70,7 +321,16 @@ public interface Attachable<T> {
         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);
         }
-    }
 
+        ////
+
+        public static IllegalArgumentException illegalMethodOnHostVertex(final Attachable attachable, final Method method, final Vertex hostVertex) {
+            return new IllegalArgumentException("The following method on the host vertex is not legal: " + hostVertex + "." + method + "(" + attachable + ")");
+        }
+
+        public static IllegalArgumentException illegalMethodOnHostGraph(final Attachable attachable, final Method method, final Graph hostGraph) {
+            return new IllegalArgumentException("The following method on the host graph is not legal: " + hostGraph + "." + method + "(" + attachable + ")");
+        }
+    }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 f32b77d..cffa268 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
@@ -18,14 +18,11 @@
  */
 package org.apache.tinkerpop.gremlin.structure.util.detached;
 
-import org.apache.tinkerpop.gremlin.process.traversal.T;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 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;
 import org.javatuples.Pair;
@@ -95,22 +92,24 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
     }
 
     @Override
-    public Edge attach(final Vertex hostVertex) {
-        final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT, this.label), edge -> edge.equals(this));
+    public Edge attach(final Vertex hostVertex, final Method method) {
+        return (Edge) method.apply(this, hostVertex);
+        /*final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT, this.label), edge -> edge.equals(this));
         if (!edges.hasNext())
             throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
-        return edges.next();
+        return edges.next();*/
     }
 
     @Override
-    public Edge attach(final Graph hostGraph) {
-        final Iterator<Edge> edges = hostGraph.edges(this.id);
+    public Edge attach(final Graph hostGraph, final Method method) {
+        return (Edge) method.apply(this, hostGraph);
+        /*final Iterator<Edge> edges = hostGraph.edges(this.id);
         if (!edges.hasNext())
             throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
-        return edges.next();
+        return edges.next();*/
     }
 
-    public static Edge addTo(final Graph graph, final DetachedEdge detachedEdge) {
+    /*public static Edge addTo(final Graph graph, final DetachedEdge detachedEdge) {
         Iterator<Vertex> vertices = graph.vertices(detachedEdge.outVertex.id());
         final Vertex outV = vertices.hasNext() ? vertices.next() : graph.addVertex(T.id, detachedEdge.outVertex.id());
         vertices = graph.vertices(detachedEdge.inVertex.id());
@@ -127,7 +126,7 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
         if (null != detachedEdge.properties)
             detachedEdge.properties.entrySet().forEach(kv -> kv.getValue().forEach(p -> e.<Object>property(kv.getKey(), p.value())));
         return e;
-    }
+    }*/
 
     @Override
     public Vertex inVertex() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 54e448c..b748633 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
@@ -96,4 +96,8 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
                 Collections.emptyIterator() :
                 (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).flatMap(entry -> entry.getValue().stream()).iterator();
     }
+
+    public E get() {
+        return (E) this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 90160e5..8610922 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
@@ -35,6 +35,10 @@ public class DetachedPath extends MutablePath implements Attachable<Path> {
 
     }
 
+    public Path get() {
+        return this;
+    }
+
     protected DetachedPath(final Path path, final boolean withProperties) {
         path.forEach((object, labels) -> {
             if (object instanceof DetachedElement || object instanceof DetachedProperty || object instanceof DetachedPath) {
@@ -57,16 +61,16 @@ public class DetachedPath extends MutablePath implements Attachable<Path> {
     }
 
     @Override
-    public Path attach(final Graph hostGraph) {
+    public Path attach(final Graph hostGraph, final Method method) {
         final Path path = MutablePath.make();  // TODO: Use ImmutablePath?
-        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostGraph) : object, labels.toArray(new String[labels.size()])));
+        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostGraph, method) : object, labels.toArray(new String[labels.size()])));
         return path;
     }
 
     @Override
-    public Path attach(final Vertex hostVertex) {
+    public Path attach(final Vertex hostVertex, final Method method) {
         final Path path = MutablePath.make();  // TODO: Use ImmutablePath?
-        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex) : object, labels.toArray(new String[labels.size()])));
+        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex, method) : object, labels.toArray(new String[labels.size()])));
         return path;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 1394f89..c5b3a9d 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
@@ -53,6 +53,10 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
         this.element = DetachedFactory.detach(element, false);
     }
 
+    public Property get() {
+        return this;
+    }
+
     @Override
     public boolean isPresent() {
         return true;
@@ -95,22 +99,24 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
     }
 
     @Override
-    public Property<V> attach(final Vertex hostVertex) {
-        final Element element = (Element) this.element.attach(hostVertex);
+    public Property<V> attach(final Vertex hostVertex, final Method method) {
+        return (Property<V>) method.apply(this, hostVertex);
+        /*final Element element = (Element) this.element.attach(hostVertex);
         final Property<V> property = element.property(this.key);
         if (property.isPresent() && property.value().equals(this.value))
             return property;
         else
-            throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex);
+            throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex);*/
     }
 
     @Override
-    public Property<V> attach(final Graph hostGraph) {
-        final Element hostElement = (Element) this.element.attach(hostGraph);
+    public Property<V> attach(final Graph hostGraph, final Method method) {
+        return (Property<V>) method.apply(this, method);
+        /*final Element hostElement = (Element) this.element.attach(hostGraph);
         final Property<V> property = hostElement.property(this.key);
         if (property.isPresent() && property.value().equals(this.value))
             return property;
         else
-            throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph);
+            throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph); */
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 a4857ef..f0b9b75 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
@@ -26,7 +26,6 @@ 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;
@@ -126,23 +125,16 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
     }
 
     @Override
-    public Vertex attach(final Vertex hostVertex) {
-        if (hostVertex.equals(this))
-            return hostVertex;
-        else
-            throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex);
+    public Vertex attach(final Vertex hostVertex, final Method method) {
+        return (Vertex) method.apply(this, hostVertex);
     }
 
     @Override
-    public Vertex attach(final Graph hostGraph) {
-        final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
-        if(iterator.hasNext())
-            return iterator.next();
-        else
-            throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph);
+    public Vertex attach(final Graph hostGraph, final Method method) {
+        return (Vertex) method.apply(this, hostGraph);
     }
 
-    public static Vertex addTo(final Graph graph, final DetachedVertex detachedVertex) {
+    /*public static Vertex addTo(final Graph graph, final DetachedVertex detachedVertex) {
         final Vertex vertex = graph.addVertex(T.id, detachedVertex.id(), T.label, detachedVertex.label());
         if (null != detachedVertex.properties) {
             detachedVertex.properties.values().forEach(list -> {
@@ -164,7 +156,7 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
             });
         }
         return vertex;
-    }
+    } */
 
     @Override
     public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
@@ -178,7 +170,7 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
 
     @Override
     public Iterator<Vertex> vertices(final Direction direction, final String... labels) {
-      return Collections.emptyIterator();
+        return Collections.emptyIterator();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 8ee0759..675244a 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
@@ -22,10 +22,8 @@ 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;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -111,16 +109,18 @@ public class DetachedVertexProperty<V> extends DetachedElement<Property<V>> impl
     }
 
     @Override
-    public VertexProperty<V> attach(final Vertex hostVertex) {
-        final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(this.label), vp -> ElementHelper.areEqual(this, vp));
+    public VertexProperty<V> attach(final Vertex hostVertex, final Method method) {
+        return (VertexProperty<V>) method.apply(this, hostVertex);
+        /*final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(this.label), vp -> ElementHelper.areEqual(this, vp));
         if (!vertexPropertyIterator.hasNext())
             throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex((Attachable) this, hostVertex);
-        return vertexPropertyIterator.next();
+        return vertexPropertyIterator.next(); */
     }
 
     @Override
-    public VertexProperty<V> attach(final Graph hostGraph) {
-        return this.attach(this.vertex.attach(hostGraph));
+    public VertexProperty<V> attach(final Graph hostGraph, final Method method) {
+        return (VertexProperty<V>) method.apply(this, hostGraph);
+        //return this.attach(this.vertex.attach(hostGraph));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 b221cc8..2788d3a 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
@@ -27,8 +27,6 @@ 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;
@@ -47,19 +45,21 @@ public class ReferenceEdge extends ReferenceElement<Edge> implements Edge {
     }
 
     @Override
-    public Edge attach(final Vertex hostVertex) {
-        final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT), edge -> edge.id().equals(this.id));
+    public Edge attach(final Vertex hostVertex, final Method method) {
+        return (Edge) method.apply(this, hostVertex);
+       /* final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT), edge -> edge.id().equals(this.id));
         if (!edges.hasNext())
             throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
-        return edges.next();
+        return edges.next();  */
     }
 
     @Override
-    public Edge attach(final Graph hostGraph) {
-        final Iterator<Edge> edges = hostGraph.edges(this.id);
+    public Edge attach(final Graph hostGraph, final Method method) {
+        return (Edge) method.apply(this, hostGraph);
+        /*final Iterator<Edge> edges = hostGraph.edges(this.id);
         if (!edges.hasNext())
             throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
-        return edges.next();
+        return edges.next(); */
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 f330395..c7b68b7 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
@@ -71,4 +71,8 @@ public abstract class ReferenceElement<E extends Element> implements Element, Se
     public boolean equals(final Object other) {
         return ElementHelper.areEqual(this, other);
     }
+
+    public E get() {
+        return (E) this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 c91299e..7b85c17 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
@@ -38,6 +38,10 @@ public class ReferencePath extends MutablePath implements Attachable<Path> {
 
     }
 
+    public Path get() {
+        return this;
+    }
+
     protected ReferencePath(final Path path) {
         path.forEach((object, labels) -> {
             if (object instanceof ReferenceElement || object instanceof ReferenceProperty || object instanceof ReferencePath) {
@@ -60,16 +64,16 @@ public class ReferencePath extends MutablePath implements Attachable<Path> {
     }
 
     @Override
-    public Path attach(final Graph hostGraph) {
+    public Path attach(final Graph hostGraph, final Method method) {
         final Path path = MutablePath.make();  // TODO: Use ImmutablePath?
-        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostGraph) : object, labels.toArray(new String[labels.size()])));
+        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostGraph, method) : object, labels.toArray(new String[labels.size()])));
         return path;
     }
 
     @Override
-    public Path attach(final Vertex hostVertex) {
+    public Path attach(final Vertex hostVertex, final Method method) {
         final Path path = MutablePath.make();  // TODO: Use ImmutablePath?
-        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex) : object, labels.toArray(new String[labels.size()])));
+        this.forEach((object, labels) -> path.extend(object instanceof Attachable ? ((Attachable) object).attach(hostVertex, method) : object, labels.toArray(new String[labels.size()])));
         return path;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 47850f5..d68d1aa 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
@@ -45,6 +45,10 @@ public class ReferenceProperty<V> implements Attachable<Property>, Serializable,
 
     }
 
+    public Property get() {
+        return this;
+    }
+
     public ReferenceProperty(final Property<V> property) {
         this.element = ReferenceFactory.detach(property.element());
         this.key = property.key();
@@ -52,21 +56,24 @@ public class ReferenceProperty<V> implements Attachable<Property>, Serializable,
     }
 
     @Override
-    public Property<V> attach(final Vertex hostVertex) throws IllegalStateException {
-        final Property<V> property = this.element.attach(hostVertex).property(this.key);
+    public Property<V> attach(final Vertex hostVertex, final Method method) throws IllegalStateException {
+        return (Property<V>) method.apply(this,hostVertex);
+        /*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);
+            throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex); */
     }
 
     @Override
-    public Property<V> attach(final Graph hostGraph) throws IllegalStateException {
-        final Property<V> property = this.element.attach(hostGraph).property(this.key);
+    public Property<V> attach(final Graph hostGraph, final Method method) throws IllegalStateException {
+        return (Property<V>) method.apply(this,hostGraph);
+
+        /*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);
+            throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph);*/
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 415ca61..775305d 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
@@ -27,9 +27,7 @@ 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;
@@ -48,20 +46,22 @@ public class ReferenceVertex extends ReferenceElement<Vertex> implements Vertex
     }
 
     @Override
-    public Vertex attach(final Vertex hostVertex) {
-        if (ElementHelper.areEqual(this,hostVertex))
+    public Vertex attach(final Vertex hostVertex, final Method method) {
+        return (Vertex) method.apply(this, hostVertex);
+        /*if (ElementHelper.areEqual(this,hostVertex))
             return hostVertex;
         else
-            throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex);
+            throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex);  */
     }
 
     @Override
-    public Vertex attach(final Graph hostGraph) {
-        final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
+    public Vertex attach(final Graph hostGraph, final Method method) {
+        return (Vertex) method.apply(this, hostGraph);
+        /*final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
         if (iterator.hasNext())
             return iterator.next();
         else
-            throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph);
+            throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph);   */
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/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 c4cdcf4..8898e75 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
@@ -26,8 +26,6 @@ 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;
@@ -50,18 +48,20 @@ public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty>
     }
 
     @Override
-    public VertexProperty<V> attach(final Vertex hostVertex) {
-        if (!hostVertex.equals(this.vertex))
+    public VertexProperty<V> attach(final Vertex hostVertex, final Method method) {
+        return (VertexProperty<V>) method.apply(this, hostVertex);
+        /*if (!hostVertex.equals(this.vertex))
             throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
         final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(), vp -> vp.id().equals(this.id));
         if (!vertexPropertyIterator.hasNext())
             throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
-        return vertexPropertyIterator.next();
+        return vertexPropertyIterator.next();*/
     }
 
     @Override
-    public VertexProperty<V> attach(final Graph hostGraph) {
-        return this.attach(this.vertex.attach(hostGraph));
+    public VertexProperty<V> attach(final Graph hostGraph, final Method method) {
+        return (VertexProperty<V>) method.apply(this, hostGraph);
+        // return this.attach(this.vertex.attach(hostGraph));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58a63998/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index 9c7385c..b474fdb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -33,6 +33,7 @@ import org.apache.tinkerpop.gremlin.structure.Property;
 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.Attachable;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
@@ -236,7 +237,7 @@ public final class StarGraph implements Graph {
     //// STAR VERTEX ////
     /////////////////////
 
-    public final class StarVertex extends StarElement implements Vertex {
+    public final class StarVertex extends StarElement implements Vertex, Attachable<Vertex> {
 
         private Map<String, List<Edge>> outEdges = new HashMap<>();
         private Map<String, List<Edge>> inEdges = new HashMap<>();
@@ -246,6 +247,18 @@ public final class StarGraph implements Graph {
             super(id, label);
         }
 
+        public Vertex get() {
+            return this;
+        }
+
+        public Vertex attach(final Vertex hostVertex, final Method method) {
+            return (Vertex) method.apply(this, hostVertex);
+        }
+
+        public Vertex attach(final Graph hostGraph, final Method method) {
+            return (Vertex) method.apply(this, hostGraph);
+        }
+
         public void dropEdges() {
             this.outEdges.clear();
             this.inEdges.clear();