public static <V> Function<Attachable<V>, V> getOrCreate(final Host hostVertexOrGraph) {
            return (Attachable<V> attachable) -> {
                final Object base = attachable.get();
                if (base instanceof Vertex) {
                    return (V) (hostVertexOrGraph instanceof Graph ?
                            Method.getVertex((Attachable<Vertex>) attachable, (Graph) hostVertexOrGraph) :
                            Method.getVertex((Attachable<Vertex>) attachable, (Vertex) hostVertexOrGraph))
                            .orElseGet(() -> hostVertexOrGraph instanceof Graph ?
                                    Method.createVertex((Attachable<Vertex>) attachable, (Graph) hostVertexOrGraph) :
                                    Method.createVertex((Attachable<Vertex>) attachable, (Vertex) hostVertexOrGraph));
                } else if (base instanceof Edge) {
                    return (V) (hostVertexOrGraph instanceof Graph ?
                            Method.getEdge((Attachable<Edge>) attachable, (Graph) hostVertexOrGraph) :
                            Method.getEdge((Attachable<Edge>) attachable, (Vertex) hostVertexOrGraph))
                            .orElseGet(() -> hostVertexOrGraph instanceof Graph ?
                                    Method.createEdge((Attachable<Edge>) attachable, (Graph) hostVertexOrGraph) :
                                    Method.createEdge((Attachable<Edge>) attachable, (Vertex) hostVertexOrGraph));
                } else if (base instanceof VertexProperty) {
                    return (V) (hostVertexOrGraph instanceof Graph ?
                            Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Graph) hostVertexOrGraph) :
                            Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Vertex) hostVertexOrGraph))
                            .orElseGet(() -> hostVertexOrGraph instanceof Graph ?
                                    Method.createVertexProperty((Attachable<VertexProperty>) attachable, (Graph) hostVertexOrGraph) :
                                    Method.createVertexProperty((Attachable<VertexProperty>) attachable, (Vertex) hostVertexOrGraph));
                } else if (base instanceof Property) {
                    return (V) (hostVertexOrGraph instanceof Graph ?
                            Method.getProperty((Attachable<Property>) attachable, (Graph) hostVertexOrGraph) :
                            Method.getProperty((Attachable<Property>) attachable, (Vertex) hostVertexOrGraph))
                            .orElseGet(() -> hostVertexOrGraph instanceof Graph ?
                                    Method.createProperty((Attachable<Property>) attachable, (Graph) hostVertexOrGraph) :
                                    Method.createProperty((Attachable<Property>) attachable, (Vertex) hostVertexOrGraph));
                } else
                    throw Attachable.Exceptions.providedAttachableMustContainAGraphObject(attachable);
            };
        }
A collection of general methods of attachment. Note that more efficient methods of attachment might exist
if the user knows the source data being attached and the features of the graph that the data is being
attached to.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java