use of org.neo4j.android.common.ParcelableTraversalDescription in project neo4j-mobile-android by neo4j-contrib.
the class DbWrapper method traverse.
@Override
public INodeIterator traverse(ParcelableTraversalDescription desc, long startNodeId, ParcelableError err) throws RemoteException {
try {
resumeTrxIfExists();
try {
Node startNode = mDb.getNodeById(startNodeId);
if (startNode == null) {
throw new IllegalArgumentException("Illegal start node for traversal");
}
TraversalDescription traversalDesc = Traversal.description();
// map order
switch(desc.getOrder()) {
case BREADTH_FIRST:
traversalDesc = traversalDesc.breadthFirst();
break;
case DEPTH_FIRST:
traversalDesc = traversalDesc.depthFirst();
break;
}
// map uniqueness
switch(desc.getUniqueness()) {
case NONE:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NONE);
break;
case NODE_GLOBAL:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_GLOBAL);
break;
case NODE_RECENT:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_RECENT);
break;
case NODE_PATH:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_PATH);
break;
case RELATIONSHIP_GLOBAL:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_GLOBAL);
break;
case RELATIONSHIP_PATH:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_PATH);
break;
case RELATIONSHIP_RECENT:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_RECENT);
break;
}
// map relationships
for (String name : desc.getRelationships().keySet()) {
RelationshipType type = new SimpleRelationshipType(name);
Direction direction = Direction.valueOf(desc.getRelationships().get(name).name());
traversalDesc = traversalDesc.relationships(type, direction);
}
// TODO: support paths
Iterator<Node> nodeIterator = traversalDesc.traverse(startNode).nodes().iterator();
return new NodeIteratorWrapper(nodeIterator);
} finally {
suspendCurrentTrx("traverse");
}
} catch (Exception e) {
err.setError(Errors.TRANSACTION, e.getMessage());
return null;
}
}
Aggregations