Search in sources :

Example 31 with TraversalDescription

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

the class SpecificDepthTraversalTest method shouldGetSecondNodeWhenAtIsTwoBreadthFirst.

@Test
public void shouldGetSecondNodeWhenAtIsTwoBreadthFirst() {
    TraversalDescription description = getGraphDb().traversalDescription().breadthFirst().evaluator(Evaluators.atDepth(2));
    expectNodes(description.traverse(getNodeWithName("6")), "4");
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 32 with TraversalDescription

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

the class SpecificDepthTraversalTest method shouldGetStartNodeWhenAtIsZeroBreadthFirst.

@Test
public void shouldGetStartNodeWhenAtIsZeroBreadthFirst() {
    TraversalDescription description = getGraphDb().traversalDescription().breadthFirst().evaluator(Evaluators.atDepth(0));
    expectNodes(description.traverse(getNodeWithName("2")), "2");
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 33 with TraversalDescription

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

the class SpecificDepthTraversalTest method shouldGetStartNodeOnDepthZero.

@Test
public void shouldGetStartNodeOnDepthZero() {
    TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.atDepth(0));
    expectNodes(description.traverse(getNodeWithName("6")), "6");
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 34 with TraversalDescription

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

the class SpecificDepthTraversalTest method shouldGetCorrectNodesAtDepthZero.

@Test
public void shouldGetCorrectNodesAtDepthZero() {
    TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.fromDepth(0)).evaluator(Evaluators.toDepth(0));
    expectNodes(description.traverse(getNodeWithName("6")), "6");
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Test(org.junit.Test)

Example 35 with TraversalDescription

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

the class TestTraversalWithIterable method useTraverserInsideTraverser.

@Test
public void useTraverserInsideTraverser() throws Exception {
    /*
         * (a)-->(b)-->(c)
         *  |
         * \/
         * (d)-->(e)-->(f)
         *
         */
    createGraph("a FIRST d", "a TO b", "b TO c", "d TO e", "e TO f");
    try (Transaction tx = beginTx()) {
        TraversalDescription firstTraverser = getGraphDb().traversalDescription().relationships(RelationshipType.withName("FIRST")).evaluator(Evaluators.toDepth(1));
        final Iterable<Path> firstResult = firstTraverser.traverse(getNodeWithName("a"));
        Iterable<Node> startNodesForNestedTraversal = new IterableWrapper<Node, Path>(firstResult) {

            @Override
            protected Node underlyingObjectToObject(Path path) {
                return path.endNode();
            }
        };
        TraversalDescription nestedTraversal = getGraphDb().traversalDescription().evaluator(Evaluators.atDepth(2));
        expectPaths(nestedTraversal.traverse(startNodesForNestedTraversal), "a,b,c", "d,e,f");
        tx.success();
    }
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) Test(org.junit.Test)

Aggregations

TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)37 Test (org.junit.Test)20 Node (org.neo4j.graphdb.Node)12 Path (org.neo4j.graphdb.Path)12 Transaction (org.neo4j.graphdb.Transaction)7 Evaluator (org.neo4j.graphdb.traversal.Evaluator)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 HashMap (java.util.HashMap)3 WeightedPath (org.neo4j.graphalgo.WeightedPath)3 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)3 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)3 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)3 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Direction (org.neo4j.graphdb.Direction)2 PathExpander (org.neo4j.graphdb.PathExpander)2 Relationship (org.neo4j.graphdb.Relationship)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2