DetachedFactory { public static DetachedVertex detach(final Vertex vertex, final boolean withProperties) { return vertex instanceof DetachedVertex ? (DetachedVertex) vertex : new DetachedVertex(vertex, withProperties); } private  DetachedFactory(); static DetachedVertex detach(final Vertex vertex, final boolean withProperties); static DetachedEdge detach(final Edge edge, final boolean withProperties); static DetachedVertexProperty detach(final VertexProperty<V> vertexProperty, final boolean withProperties); static DetachedProperty<V> detach(final Property<V> property); static DetachedPath detach(final Path path, final boolean withProperties); static DetachedElement detach(final Element element, final boolean withProperties); static D detach(final Object object, final boolean withProperties);  }
@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 = DetachedFactory.detach(path, true); final Vertex v1 = detached.get(0); assertThat(v1, instanceOf(DetachedVertex.class)); assertEquals("stephen", v1.values("name").next()); assertEquals(1, IteratorUtils.count(v1.properties())); final Vertex v2 = (Vertex) ((List) detached.get(1)).get(0); assertThat(v2, instanceOf(DetachedVertex.class)); assertEquals("vadas", v2.values("name").next()); assertEquals(1, IteratorUtils.count(v2.properties())); final Vertex v3 = (Vertex) ((List) ((List) detached.get(2)).get(0)).get(0); assertThat(v3, instanceOf(DetachedVertex.class)); assertEquals("josh", v3.values("name").next()); assertEquals(1, IteratorUtils.count(v3.properties())); }