private Vertex getOrCreate(final Vertex vertex) {
        final Iterator<Vertex> vertexIterator = subgraph.vertices(vertex.id());

        try {
            if (vertexIterator.hasNext()) return vertexIterator.next();
        } finally {
            CloseableIterator.closeIterator(vertexIterator);
        }

        final Vertex subgraphVertex = subgraph.addVertex(T.id, vertex.id(), T.label, vertex.label());

        vertex.properties().forEachRemaining(vertexProperty -> {
            final VertexProperty.Cardinality cardinality = parentGraphFeatures.getCardinality(vertexProperty.key());
            final VertexProperty<?> subgraphVertexProperty = subgraphVertex.property(cardinality, vertexProperty.key(), vertexProperty.value(), T.id, vertexProperty.id());

            // only iterate the VertexProperties if the current graph can have them and if the subgraph can support
            // them. unfortunately we don't have a way to write a test for this as we dont' have a graph that supports
            // user supplied ids and doesn't support metaproperties.
            if (parentGraphFeatures.supportsMetaProperties() && subgraphSupportsMetaProperties) {
                vertexProperty.properties().forEachRemaining(property -> subgraphVertexProperty.property(property.key(), property.value()));
            }
        });
        return subgraphVertex;
    }
A side-effect step that produces an edge induced subgraph.

@author Stephen Mallette (http://stephen.genoprime.com)
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphStep.java