Search in sources :

Example 16 with TraversalBranch

use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.

the class PostorderDepthFirstSelector method next.

public TraversalBranch next() {
    TraversalBranch result = null;
    while (result == null) {
        if (current == null) {
            return null;
        }
        TraversalBranch next = current.next();
        if (next != null) {
            current = next;
        } else {
            result = current;
            current = current.parent();
        }
    }
    return result;
}
Also used : TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 17 with TraversalBranch

use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j-mobile-android by neo4j-contrib.

the class PreorderBreadthFirstSelector method next.

public TraversalBranch next() {
    TraversalBranch result = null;
    while (result == null) {
        TraversalBranch next = current.next();
        if (next != null) {
            queue.add(next);
            result = next;
        } else {
            current = queue.poll();
            if (current == null) {
                return null;
            }
        }
    }
    return result;
}
Also used : TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 18 with TraversalBranch

use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.

the class TraversalBranchImpl method relationships.

@Override
public Iterable<Relationship> relationships() {
    LinkedList<Relationship> relationships = new LinkedList<>();
    TraversalBranch branch = this;
    while (branch.length() > 0) {
        relationships.addFirst(branch.lastRelationship());
        branch = branch.parent();
    }
    return relationships;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) LinkedList(java.util.LinkedList) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 19 with TraversalBranch

use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.

the class TraversalBranchImpl method nodes.

@Override
public Iterable<Node> nodes() {
    LinkedList<Node> nodes = new LinkedList<>();
    TraversalBranch branch = this;
    while (branch.length() > 0) {
        nodes.addFirst(branch.endNode());
        branch = branch.parent();
    }
    nodes.addFirst(branch.endNode());
    return nodes;
}
Also used : Node(org.neo4j.graphdb.Node) LinkedList(java.util.LinkedList) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 20 with TraversalBranch

use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.

the class TraversalBranchImpl method hashCode.

@Override
public int hashCode() {
    TraversalBranch branch = this;
    int hashCode = 1;
    while (branch.length() > 0) {
        Relationship relationship = branch.lastRelationship();
        hashCode = 31 * hashCode + relationship.hashCode();
        branch = branch.parent();
    }
    if (hashCode == 1) {
        hashCode = endNode().hashCode();
    }
    return hashCode;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Aggregations

TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)28 Node (org.neo4j.graphdb.Node)13 LinkedList (java.util.LinkedList)10 Relationship (org.neo4j.graphdb.Relationship)9 Path (org.neo4j.graphdb.Path)7 Traverser (org.neo4j.graphdb.traversal.Traverser)4 Test (org.junit.jupiter.api.Test)3 Entity (org.neo4j.graphdb.Entity)3 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)3 HashMap (java.util.HashMap)2 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)2 PathExpander (org.neo4j.graphdb.PathExpander)2 Transaction (org.neo4j.graphdb.Transaction)2 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)2 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)2 Predicate (org.neo4j.helpers.Predicate)2 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)2 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1