List<Object> nodesInPath(Object pathValue) { Path path = (Path) pathValue; List<Object> nodes = new ArrayList<>(path.length()); for (Node node : path.nodes()) { nodes.add(node); } return nodes; }
public List<Object> nodesInPath(Object pathValue) { Path path = (Path) pathValue; List<Object> nodes = new ArrayList<>(path.length()); for (Node node : path.nodes()) { nodes.add(node); } return nodes; }
@SuppressWarnings("unchecked") @Override public long gePathtNodeIdAt(PathInfo pathInfo, int index) { Object obj = pathInfo.getContentObject(); List<Node> nodes = null; if (obj instanceof List<?>) nodes = (List<Node>) obj; else if (obj instanceof Path) { nodes = new ArrayList<Node>(); Iterator<Node> it = ((Path)obj).nodes().iterator(); while(it.hasNext()) nodes.add(it.next()); pathInfo.setContentObject(nodes); } return nodes.get(index).id(); }
@SuppressWarnings("unchecked") @Override public long gePathtNodeIdAt(PathInfo pathInfo, int index) { Object obj = pathInfo.getContentObject(); List<Node> nodes = null; if (obj instanceof List<?>) nodes = (List<Node>) obj; else if (obj instanceof Path) { nodes = new ArrayList<Node>(); Iterator<Node> it = ((Path)obj).nodes().iterator(); while(it.hasNext()) nodes.add(it.next()); pathInfo.setContentObject(nodes); } return nodes.get(index).id(); }
List<Node> pathNodes = Iterables.asList(path.nodes()); List<Relationship> relationships = Iterables.asList(path.relationships());
@Test public void returnPath() { Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort()); try (Session session = driver.session()) { StatementResult setup = session.run("CREATE (n1:Person {name: 'Anders'})-[r:knows]->(n2:Person)" + "RETURN n1,r,n2"); Record createdNodes = setup.single(); Node n1 = createdNodes.get("n1").asNode(); Node n2 = createdNodes.get("n2").asNode(); Relationship r = createdNodes.get("r").asRelationship(); StatementResult result = session.run("MATCH p =(b1 { name: 'Anders' })-->()" + "RETURN p"); Path path = result.single().get("p").asPath(); assertThat(path.contains(n1)).isTrue(); assertThat(path.contains(n2)).isTrue(); assertThat(path.contains(r)).isTrue(); assertThat(path.relationships()).hasSize(1); assertThat(path.nodes()).hasSize(2); } }