use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class ValuePathTest method canConstructPathWithLengthZero.
@Test
public void canConstructPathWithLengthZero() {
// Given A
Path path = PATH_WITH_LENGTH_ZERO;
// Then
assertThat(path.length(), equalTo(0));
assertThat(path.startNode(), equalTo(ALICE));
assertThat(path.endNode(), equalTo(ALICE));
assertThat(nodes(path), equalTo(nodes(ALICE)));
assertThat(path.lastRelationship(), nullValue());
assertThat(relationships(path), equalTo(relationships()));
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class ExportTest method testFromPathCypherResult.
@Test
public void testFromPathCypherResult() throws Exception {
Node n1 = gdb.createNode();
Node n2 = gdb.createNode();
final Relationship rel = n1.createRelationshipTo(n2, RelationshipType.withName("REL"));
final Path path = new PathImpl.Builder(n1).push(rel).build();
final ExecutionResult result = result("path", path);
final SubGraph graph = CypherResultSubGraph.from(result, gdb, true);
assertEquals("create (_0)" + lineSeparator() + "create (_1)" + lineSeparator() + "create (_0)-[:`REL`]->(_1)" + lineSeparator() + ";" + lineSeparator(), doExportGraph(graph));
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class AStar method findSinglePath.
@Override
public WeightedPath findSinglePath(Node start, Node end) {
lastMetadata = new Metadata();
AStarIterator iterator = new AStarIterator(start, end);
while (iterator.hasNext()) {
Node node = iterator.next();
GraphDatabaseService graphDb = node.getGraphDatabase();
if (node.equals(end)) {
// Hit, return path
double weight = iterator.visitData.get(node.getId()).wayLength;
final Path path;
if (start.getId() == end.getId()) {
// Nothing to iterate over
path = PathImpl.singular(start);
} else {
LinkedList<Relationship> rels = new LinkedList<Relationship>();
Relationship rel = graphDb.getRelationshipById(iterator.visitData.get(node.getId()).cameFromRelationship);
while (rel != null) {
rels.addFirst(rel);
node = rel.getOtherNode(node);
long nextRelId = iterator.visitData.get(node.getId()).cameFromRelationship;
rel = nextRelId == -1 ? null : graphDb.getRelationshipById(nextRelId);
}
path = toPath(start, rels);
}
lastMetadata.paths++;
return new WeightedPathImpl(weight, path);
}
}
return null;
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class ShortestPath method hitToPaths.
private static Collection<Path> hitToPaths(Hit hit, Node start, Node end, boolean stopAsap) {
Collection<Path> paths = new ArrayList<>();
Iterable<LinkedList<Relationship>> startPaths = getPaths(hit.connectingNode, hit.start, stopAsap);
Iterable<LinkedList<Relationship>> endPaths = getPaths(hit.connectingNode, hit.end, stopAsap);
for (LinkedList<Relationship> startPath : startPaths) {
PathImpl.Builder startBuilder = toBuilder(start, startPath);
for (LinkedList<Relationship> endPath : endPaths) {
PathImpl.Builder endBuilder = toBuilder(end, endPath);
Path path = startBuilder.build(endBuilder);
paths.add(path);
}
}
return paths;
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestExactDepthPathFinder method testSingle.
@Test
public void testSingle() {
createGraph();
PathFinder<Path> finder = newFinder();
Path path = finder.findSinglePath(graph.getNode("SOURCE"), graph.getNode("TARGET"));
assertNotNull(path);
assertPathDef(path, "SOURCE", "z", "9", "0", "TARGET");
}
Aggregations