use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesWhenNotAlone.
@Test
public void shouldHandleNeighbouringNodesWhenNotAlone() {
// (a) - (b)
// |
// (c)
graph.makeEdge("a", "b");
graph.makeEdge("a", "c");
Node a = graph.getNode("a");
Node b = graph.getNode("b");
ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TreeGraphTest method testDepthFirstTraversalReturnsNodesOnCorrectDepths.
@Test
public void testDepthFirstTraversalReturnsNodesOnCorrectDepths() throws Exception {
Traverser traverser = Traversal.description().depthFirst().traverse(referenceNode());
int i = 0;
for (Path pos : traverser) {
assertEquals(expectedDepth(i++), pos.length());
}
assertEquals(13, i);
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TreeGraphTest method pathsIteratorReturnAllNodes.
@Test
public void pathsIteratorReturnAllNodes() throws Exception {
Traverser traverser = Traversal.description().traverse(referenceNode());
int count = 0;
for (Path path : traverser) {
assertNotNull("returned paths should not be null. path #" + count, path);
count++;
}
assertEquals(13, count);
}
use of org.neo4j.graphdb.Path in project neo4j-mobile-android by neo4j-contrib.
the class TraversalPath method equals.
@Override
public boolean equals(Object obj) {
ensureEntitiesAreGathered();
if (this == obj) {
return true;
} else if (obj instanceof TraversalPath) {
TraversalPath other = (TraversalPath) obj;
return startNode().equals(other.startNode()) && relationships.equals(other.relationships);
} else if (obj instanceof Path) {
Path other = (Path) obj;
if (startNode().equals(other.startNode())) {
Iterator<Relationship> these = relationships().iterator();
Iterator<Relationship> those = other.relationships().iterator();
while (these.hasNext() && those.hasNext()) {
if (!these.next().equals(those.next())) {
return false;
}
}
if (these.hasNext() || those.hasNext()) {
return false;
}
return true;
}
}
return false;
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class Trav method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
assertCurrentIsNode(session);
Node node = this.getCurrent(session).asNode();
boolean caseInsensitiveFilters = parser.options().containsKey("i");
boolean looseFilters = parser.options().containsKey("l");
boolean quiet = parser.options().containsKey("q");
// Order
TraversalDescription description = getServer().getDb().traversalDescription();
String order = parser.options().get("o");
if (order != null) {
description = description.order(parseOrder(order));
}
// Relationship types / expander
String relationshipTypes = parser.options().get("r");
if (relationshipTypes != null) {
Map<String, Object> types = parseFilter(relationshipTypes, out);
description = description.expand(toExpander(getServer().getDb(), null, types, caseInsensitiveFilters, looseFilters));
}
// Uniqueness
String uniqueness = parser.options().get("u");
if (uniqueness != null) {
description = description.uniqueness(parseUniqueness(uniqueness));
}
// Depth limit
String depthLimit = parser.options().get("d");
if (depthLimit != null) {
description = description.evaluator(toDepth(parseInt(depthLimit)));
}
String filterString = parser.options().get("f");
Map<String, Object> filterMap = filterString != null ? parseFilter(filterString, out) : null;
String commandToRun = parser.options().get("c");
Collection<String> commandsToRun = new ArrayList<>();
if (commandToRun != null) {
commandsToRun.addAll(Arrays.asList(commandToRun.split(Pattern.quote("&&"))));
}
for (Path path : description.traverse(node)) {
boolean hit = false;
if (filterMap == null) {
hit = true;
} else {
Node endNode = path.endNode();
Map<String, Boolean> matchPerFilterKey = new HashMap<>();
for (String key : endNode.getPropertyKeys()) {
for (Map.Entry<String, Object> filterEntry : filterMap.entrySet()) {
String filterKey = filterEntry.getKey();
if (matchPerFilterKey.containsKey(filterKey)) {
continue;
}
if (matches(newPattern(filterKey, caseInsensitiveFilters), key, caseInsensitiveFilters, looseFilters)) {
Object value = endNode.getProperty(key);
String filterPattern = filterEntry.getValue() != null ? filterEntry.getValue().toString() : null;
if (matches(newPattern(filterPattern, caseInsensitiveFilters), value.toString(), caseInsensitiveFilters, looseFilters)) {
matchPerFilterKey.put(filterKey, true);
}
}
}
}
if (matchPerFilterKey.size() == filterMap.size()) {
hit = true;
}
}
if (hit) {
if (commandsToRun.isEmpty()) {
printPath(path, quiet, session, out);
} else {
printAndInterpretTemplateLines(commandsToRun, false, true, NodeOrRelationship.wrap(path.endNode()), getServer(), session, out);
}
}
}
return Continuation.INPUT_COMPLETE;
}
Aggregations