use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.
the class TraversalBranchImpl method next.
@Override
public TraversalBranch next(PathExpander expander, TraversalContext context) {
if (relationships == null) {
expandRelationships(expander);
}
while (relationships.hasNext()) {
Relationship relationship = relationships.next();
if (relationship.equals(howIGotHere)) {
context.unnecessaryRelationshipTraversed();
continue;
}
expandedCount++;
Node node = relationship.getOtherNode(source);
// TODO maybe an unnecessary instantiation. Instead pass in this+node+relationship to uniqueness check
TraversalBranch next = newNextBranch(node, relationship);
if (context.isUnique(next)) {
context.relationshipTraversed();
next.initialize(expander, context);
return next;
} else {
context.unnecessaryRelationshipTraversed();
}
}
resetRelationships();
return null;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.
the class TraversalBranchImpl method next.
public TraversalBranch next() {
while (relationships.hasNext()) {
Relationship relationship = relationships.next();
if (relationship.equals(howIGotHere)) {
continue;
}
expandedCount++;
Node node = relationship.getOtherNode(source);
TraversalBranch next = new TraversalBranchImpl(traverser, this, depth + 1, node, traverser.description.expander, relationship);
if (traverser.okToProceed(next)) {
next.initialize();
return next;
}
}
return null;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.
the class PostorderBreadthFirstSelector method gatherOneLevel.
private List<TraversalBranch> gatherOneLevel(List<TraversalBranch> queue) {
List<TraversalBranch> level = new LinkedList<TraversalBranch>();
Integer depth = null;
for (TraversalBranch source : queue) {
if (depth == null) {
depth = source.depth();
} else if (source.depth() != depth) {
break;
}
while (true) {
TraversalBranch next = source.next();
if (next == null) {
break;
}
level.add(next);
}
}
return level;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.
the class ExactDepthPathFinder method paths.
private Iterator<Path> paths(final Node start, final Node end) {
TraversalDescription base = Traversal.description().uniqueness(Uniqueness.RELATIONSHIP_PATH).order(new BranchOrderingPolicy() {
public BranchSelector create(TraversalBranch startSource) {
return new LiteDepthFirstSelector(startSource, startThreshold);
}
});
final int firstHalf = onDepth / 2;
Traverser startTraverser = base.prune(Traversal.pruneAfterDepth(firstHalf)).expand(expander).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == firstHalf;
}
}).traverse(start);
final int secondHalf = onDepth - firstHalf;
Traverser endTraverser = base.prune(Traversal.pruneAfterDepth(secondHalf)).expand(expander.reversed()).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == secondHalf;
}
}).traverse(end);
final Iterator<Path> startIterator = startTraverser.iterator();
final Iterator<Path> endIterator = endTraverser.iterator();
final Map<Node, Visit> visits = new HashMap<Node, Visit>();
return new PrefetchingIterator<Path>() {
@Override
protected Path fetchNextOrNull() {
Path[] found = null;
while (found == null && (startIterator.hasNext() || endIterator.hasNext())) {
found = goOneStep(start, startIterator, visits);
if (found == null) {
found = goOneStep(end, endIterator, visits);
}
}
return found != null ? toPath(found, start) : null;
}
};
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.
the class TraversalPath method ensureEntitiesAreGathered.
private void ensureEntitiesAreGathered() {
if (nodes == null) {
// We don't synchronize on nodes/relationship... and that's fine
// because even if there would be a situation where two (or more)
// threads comes here at the same time everything would still
// work as expected (in here as well as outside).
LinkedList<Node> nodesList = new LinkedList<Node>();
LinkedList<Relationship> relationshipsList = new LinkedList<Relationship>();
TraversalBranch stepper = branch;
while (stepper != null) {
nodesList.addFirst(stepper.node());
Relationship relationship = stepper.relationship();
if (relationship != null) {
relationshipsList.addFirst(relationship);
}
stepper = stepper.parent();
}
nodes = nodesList;
relationships = relationshipsList;
}
}
Aggregations