@@ -32,26 +32,14 @@ public class FindAnyOnePath {
3232 @ Procedure (name = "bytecodedl.findOnePath" , mode = Mode .READ )
3333 @ Description ("find one path from start to end under maxlength, also show first multi dispatch" )
3434 public Stream <PathRecord > findOnePath (@ Name ("start" ) Node start , @ Name ("end" ) Node end , @ Name ("maxLength" ) long maxLength , @ Name ("callProperty" ) String callProperty ){
35- final Traverser traverse = tx .traversalDescription ()
35+ final Traverser traverser = tx .traversalDescription ()
3636 .breadthFirst ()
3737 .evaluator (Evaluators .toDepth ((int )maxLength ))
3838 .expand (PathExpanders .forTypeAndDirection (RelationshipType .withName ("Call" ), Direction .OUTGOING ))
3939 .uniqueness (Uniqueness .NODE_GLOBAL )
4040 .traverse (start );
4141
42- Optional <Path > optionalPath = StreamSupport
43- .stream (traverse .spliterator (), false ).findFirst ();
44-
45- if (optionalPath .isPresent ()){
46- Path path = optionalPath .get ();
47- List <Relationship > multiDispatchRelationship = getFirstMultiDispatch (path , callProperty );
48- List <Path > pathList = multiDispatchRelationship .stream ().map (this ::relationShipToPath ).collect (Collectors .toList ());
49- pathList .add (path );
50- return pathList .stream ().map (PathRecord ::new );
51- }else {
52- return StreamSupport
53- .stream (traverse .spliterator (), false ).map (PathRecord ::new );
54- }
42+ return returnWithFirstMultiDispatch (traverser , callProperty );
5543 }
5644
5745 @ Procedure (name = "bytecodedl.biFindOnePath" , mode = Mode .READ )
@@ -61,7 +49,7 @@ public Stream<PathRecord> biFindOnePath(@Name("start") Node start, @Name("end")
6149 PathExpander expander = PathExpanders .forTypeAndDirection (RelationshipType .withName ("Call" ), Direction .OUTGOING );
6250 int maxDepth = (int ) maxLength ;
6351
64- final Traverser traverse = tx .bidirectionalTraversalDescription ()
52+ final Traverser traverser = tx .bidirectionalTraversalDescription ()
6553 .startSide (
6654 base .expand (expander )
6755 .evaluator (Evaluators .toDepth (maxDepth / 2 ))
@@ -71,19 +59,23 @@ public Stream<PathRecord> biFindOnePath(@Name("start") Node start, @Name("end")
7159 )
7260 .traverse (start , end );
7361
62+ return returnWithFirstMultiDispatch (traverser , callProperty );
63+
64+ }
65+
66+ public Stream <PathRecord > returnWithFirstMultiDispatch (Traverser traverser , String callProperty ){
7467 Optional <Path > optionalPath = StreamSupport
75- .stream (traverse .spliterator (), false ).findFirst ();
68+ .stream (traverser .spliterator (), false ).findFirst ();
7669
7770 if (optionalPath .isPresent ()){
7871 Path path = optionalPath .get ();
79- // System.out.println(path);
8072 List <Relationship > multiDispatchRelationship = getFirstMultiDispatch (path , callProperty );
8173 List <Path > pathList = multiDispatchRelationship .stream ().map (this ::relationShipToPath ).collect (Collectors .toList ());
8274 pathList .add (path );
8375 return pathList .stream ().map (PathRecord ::new );
8476 }else {
8577 return StreamSupport
86- .stream (traverse .spliterator (), false ).map (PathRecord ::new );
78+ .stream (traverser .spliterator (), false ).map (PathRecord ::new );
8779 }
8880 }
8981
0 commit comments