ReferenceFactory { public static ReferenceVertex detach(final Vertex vertex) { return vertex instanceof ReferenceVertex ? (ReferenceVertex) vertex : new ReferenceVertex(vertex); } private  ReferenceFactory(); static ReferenceVertex detach(final Vertex vertex); static ReferenceEdge detach(final Edge edge); static ReferenceVertexProperty detach(final VertexProperty<V> vertexProperty); static ReferenceProperty<V> detach(final Property<V> property); static ReferencePath detach(final Path path); static ReferenceElement detach(final Element element); static D detach(final Object object);  }
@Test public void shouldDetachPathToReferenceWithEmbeddedLists() { final Path path = MutablePath.make(); path.extend(DetachedVertex.build().setId(1).setLabel("person"). addProperty(new DetachedVertexProperty<>( 101, "name", "stephen", Collections.emptyMap())).create(), Collections.singleton("a")); path.extend(Collections.singletonList(DetachedVertex.build().setId(2).setLabel("person"). addProperty(new DetachedVertexProperty<>( 102, "name", "vadas", Collections.emptyMap())).create()), Collections.singleton("a")); path.extend(Collections.singletonList(Collections.singletonList(DetachedVertex.build().setId(3).setLabel("person"). addProperty(new DetachedVertexProperty<>( 103, "name", "josh", Collections.emptyMap())).create())), Collections.singleton("a")); final Path detached = ReferenceFactory.detach(path); final Vertex v1 = detached.get(0); assertThat(v1, instanceOf(ReferenceVertex.class)); assertThat(v1.properties().hasNext(), is(false)); final Vertex v2 = (Vertex) ((List) detached.get(1)).get(0); assertThat(v2, instanceOf(ReferenceVertex.class)); assertThat(v2.properties().hasNext(), is(false)); final Vertex v3 = (Vertex) ((List) ((List) detached.get(2)).get(0)).get(0); assertThat(v3, instanceOf(ReferenceVertex.class)); assertThat(v3.properties().hasNext(), is(false)); }