从neo4j获取Traverser的多种方式

时间:2012-12-28 17:05:06

标签: neo4j

之间有什么区别吗?

方法1:

   TraversalDescription one = new TraversalDescriptionImpl();
        one = one.breadthFirst()
             .relationships(RelType.KNOWS, Direction.OUTGOING)
             .evaluator(Evaluators.excludeStartPosition());
    Traverser t1 = one.traverse(node);

方法2:

    TraversalDescription two = Traversal.description()
            .breadthFirst()
            .relationships(RelType.KNOWS, Direction.OUTGOING)
            .evaluator(Evaluators.excludeStartPosition());

    Traverser t2 = one.traverse(node);

两个Traversers似乎都提供了相同的结果。有一种方法优于另一种方法吗?何时以及为何?

1 个答案:

答案 0 :(得分:3)

TraversalDescriptionImpl的对象是工厂类Traversal在调用Traversal.description()时将返回的对象。从Traversal类来源剪断:

public static TraversalDescription description() {
    return new TraversalDescriptionImpl();
}

因此,

TraversalDescription one = new TraversalDescriptionImpl();

相同
TraversalDescription two = Traversal.description()