Search in sources :

Example 1 with FinalTraversalBranch

use of org.neo4j.kernel.impl.traversal.FinalTraversalBranch in project neo4j-mobile-android by neo4j-contrib.

the class Traversal method combineSourcePaths.

/**
     * Combines two {@link TraversalBranch}s with a common
     * {@link TraversalBranch#node() head node} in order to obtain an
     * {@link TraversalBranch} representing a path from the start node of the
     * <code>source</code> {@link TraversalBranch} to the start node of the
     * <code>target</code> {@link TraversalBranch}. The resulting
     * {@link TraversalBranch} will not {@link TraversalBranch#next() expand
     * further}, and does not provide a {@link TraversalBranch#parent() parent}
     * {@link TraversalBranch}.
     *
     * @param source the {@link TraversalBranch} where the resulting path starts
     * @param target the {@link TraversalBranch} where the resulting path ends
     * @throws IllegalArgumentException if the {@link TraversalBranch#node()
     *             head nodes} of the supplied {@link TraversalBranch}s does not
     *             match
     * @return an {@link TraversalBranch} that represents the path from the
     *         start node of the <code>source</code> {@link TraversalBranch} to
     *         the start node of the <code>target</code> {@link TraversalBranch}
     */
public static TraversalBranch combineSourcePaths(TraversalBranch source, TraversalBranch target) {
    if (!source.node().equals(target.node())) {
        throw new IllegalArgumentException("The nodes of the head and tail must match");
    }
    Path headPath = source.position(), tailPath = target.position();
    Relationship[] relationships = new Relationship[headPath.length() + tailPath.length()];
    Iterator<Relationship> iter = headPath.relationships().iterator();
    for (int i = 0; iter.hasNext(); i++) {
        relationships[i] = iter.next();
    }
    iter = tailPath.relationships().iterator();
    for (int i = relationships.length - 1; iter.hasNext(); i--) {
        relationships[i] = iter.next();
    }
    return new FinalTraversalBranch(tailPath.startNode(), relationships);
}
Also used : Path(org.neo4j.graphdb.Path) Relationship(org.neo4j.graphdb.Relationship) FinalTraversalBranch(org.neo4j.kernel.impl.traversal.FinalTraversalBranch)

Example 2 with FinalTraversalBranch

use of org.neo4j.kernel.impl.traversal.FinalTraversalBranch in project graphdb by neo4j-attic.

the class Traversal method combineSourcePaths.

/**
     * Combines two {@link TraversalBranch}s with a common
     * {@link TraversalBranch#node() head node} in order to obtain an
     * {@link TraversalBranch} representing a path from the start node of the
     * <code>source</code> {@link TraversalBranch} to the start node of the
     * <code>target</code> {@link TraversalBranch}. The resulting
     * {@link TraversalBranch} will not {@link TraversalBranch#next() expand
     * further}, and does not provide a {@link TraversalBranch#parent() parent}
     * {@link TraversalBranch}.
     *
     * @param source the {@link TraversalBranch} where the resulting path starts
     * @param target the {@link TraversalBranch} where the resulting path ends
     * @throws IllegalArgumentException if the {@link TraversalBranch#node()
     *             head nodes} of the supplied {@link TraversalBranch}s does not
     *             match
     * @return an {@link TraversalBranch} that represents the path from the
     *         start node of the <code>source</code> {@link TraversalBranch} to
     *         the start node of the <code>target</code> {@link TraversalBranch}
     */
public static TraversalBranch combineSourcePaths(TraversalBranch source, TraversalBranch target) {
    if (!source.node().equals(target.node())) {
        throw new IllegalArgumentException("The nodes of the head and tail must match");
    }
    Path headPath = source.position(), tailPath = target.position();
    Relationship[] relationships = new Relationship[headPath.length() + tailPath.length()];
    Iterator<Relationship> iter = headPath.relationships().iterator();
    for (int i = 0; iter.hasNext(); i++) {
        relationships[i] = iter.next();
    }
    iter = tailPath.relationships().iterator();
    for (int i = relationships.length - 1; iter.hasNext(); i--) {
        relationships[i] = iter.next();
    }
    return new FinalTraversalBranch(tailPath.startNode(), relationships);
}
Also used : Path(org.neo4j.graphdb.Path) Relationship(org.neo4j.graphdb.Relationship) FinalTraversalBranch(org.neo4j.kernel.impl.traversal.FinalTraversalBranch)

Aggregations

Path (org.neo4j.graphdb.Path)2 Relationship (org.neo4j.graphdb.Relationship)2 FinalTraversalBranch (org.neo4j.kernel.impl.traversal.FinalTraversalBranch)2