Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<neo4j.version>5.9.0</neo4j.version>
<junit-jupiter.version>5.7.0</junit-jupiter.version>
<!-- <neo4j-java-driver.version>4.4.0</neo4j-java-driver.version>-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/tabby/algo/BasePathFinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
public class BasePathFinding {

public static Stream<PathResult> findPathWithState(Node sourceNode, String direct, Node sinkNode, String state,
long maxNodeLength, boolean isDepthFirst, boolean checkAuth, boolean isCheckType,
Number maxNodeLength, boolean isDepthFirst, boolean checkAuth, boolean isCheckType,
GraphDatabaseService db, Transaction tx){

PathExpander<TabbyState> expander;
TraversalPathFinder algo;
Iterable<Path> allPaths;
int maxDepth = (int) maxNodeLength;
Number maxDepth = maxNodeLength;

if(">".equals(direct)){
expander = new TabbyPathExpander(false, false, isCheckType);
Expand All @@ -35,19 +35,19 @@ public static Stream<PathResult> findPathWithState(Node sourceNode, String direc
algo = new TabbyTraversalPathFinder(
new BasicEvaluationContext(tx, db),
expander, initialState, sinkState,
maxDepth, isDepthFirst, checkAuth, false);
maxNodeLength, isDepthFirst, checkAuth, false);

allPaths = algo.findAllPaths(sourceNode, sinkNode);
}else if("<".equals(direct)){
expander = new TabbyPathExpander(false, true, isCheckType);
TabbyState initialState = TabbyState.initialState(sinkNode, state);
if(initialState == null){
maxNodeLength = 0;
maxDepth = 0;
}
algo = new TabbyTraversalPathFinder(
new BasicEvaluationContext(tx, db),
expander, initialState, null,
(int) maxNodeLength, isDepthFirst, false, true);
maxDepth, isDepthFirst, false, true);

allPaths = algo.findAllPaths(sinkNode, sourceNode);
}else{
Expand All @@ -57,7 +57,7 @@ public static Stream<PathResult> findPathWithState(Node sourceNode, String direc
TabbyState sinkState = TabbyState.initialState(sinkNode, state);

algo = new TabbyBidirectionalTraversalPathFinder(new BasicEvaluationContext(tx, db),
expander, sourceState, sinkState, (int) maxNodeLength, isDepthFirst);
expander, sourceState, sinkState, maxNodeLength, isDepthFirst);

allPaths = algo.findAllPaths(sourceNode, sinkNode);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tabby/algo/beta/PathFinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PathFinding extends BasePathFinding {
public Stream<PathResult> findPath(@Name("source") Node sourceNode,
@Name("direct") String direct,
@Name("sink") Node sinkNode,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst){
return findPathWithState(sourceNode, direct, sinkNode, null, maxNodeLength, isDepthFirst, false, true, db, tx);
}
Expand All @@ -52,7 +52,7 @@ public Stream<PathResult> findPathWithState(@Name("source") Node sourceNode,
@Name("direct") String direct,
@Name("sink") Node sinkNode,
@Name("state") String state,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst){
return findPathWithState(sourceNode, direct, sinkNode, state, maxNodeLength, isDepthFirst, false, true, db, tx);
}
Expand All @@ -62,7 +62,7 @@ public Stream<PathResult> findPathWithState(@Name("source") Node sourceNode,
" - using findPath to get source-sink path with maxNodeLength")
public Stream<PathResult> findPathWithAuth(@Name("source") Node sourceNode,
@Name("sink") Node sinkNode,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst){

return findPathWithState(sourceNode, ">", sinkNode, null, maxNodeLength, isDepthFirst, true, true, db, tx);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tabby/algo/release/JavaGadgetPathFinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Stream<PathResult> findJavaGadget(
@Name("source") Node sourceNode,
@Name("direct") String direct,
@Name("sink") Node sinkNode,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst) {

return findJavaGadgetWithState(sourceNode, direct, sinkNode, null, maxNodeLength, isDepthFirst);
Expand All @@ -51,7 +51,7 @@ public Stream<PathResult> findJavaGadgetWithState(
@Name("direct") String direct,
@Name("sink") Node sinkNode,
@Name("sinkState") String state,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst) {
boolean isBackward = "<".equals(direct);
String processor = isBackward ? "JavaGadgetBackward":"JavaGadget";
Expand All @@ -69,7 +69,7 @@ public Stream<PathResult> findJavaGadgetWithState(

MonoDirectionalTraversalPathFinder algo = new MonoDirectionalTraversalPathFinder(
new BasicEvaluationContext(tx, db),
expander, (int) maxNodeLength, initialState, isDepthFirst
expander, maxNodeLength, initialState, isDepthFirst
);

Iterable<Path> allPaths;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tabby/algo/release/PathFinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PathFinding extends BasePathFinding {
public Stream<PathResult> findPath(@Name("source") Node sourceNode,
@Name("direct") String direct,
@Name("sink") Node sinkNode,
@Name("maxNodeLength") long maxNodeLength,
@Name("maxNodeLength") Number maxNodeLength,
@Name("isDepthFirst") boolean isDepthFirst){
return findPathWithState(sourceNode, direct, sinkNode, null, maxNodeLength, isDepthFirst, false, false, db, tx);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/tabby/evaluator/MonoPathEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
public class MonoPathEvaluator extends PathEvaluator.Adapter<State> {

private Node endNode;
private int maxDepth;
private Number maxDepth;
private boolean checkAuth;

public MonoPathEvaluator(Node endNode, int maxDepth, boolean checkAuth) {
public MonoPathEvaluator(Node endNode, Number maxDepth, boolean checkAuth) {
this.endNode = endNode;
this.maxDepth = maxDepth;
this.checkAuth = checkAuth;
Expand All @@ -28,10 +28,10 @@ public MonoPathEvaluator(Node endNode, int maxDepth, boolean checkAuth) {
public Evaluation evaluate(Path path, BranchState<State> state) {
boolean includes = true;
boolean continues = true;
int length = path.length();
long length = path.length();
Node node = path.endNode();

if(length >= maxDepth){
if((Long)length >= (Long)maxDepth){
continues = false; // 超出长度 不继续进行
if(endNode != null && !endNode.equals(node)){
includes = false; // 最后的节点不是endNode,不保存当前结果
Expand All @@ -48,7 +48,7 @@ public Evaluation evaluate(Path path, BranchState<State> state) {
return Evaluation.of(includes, continues);
}

public static MonoPathEvaluator of(Node endNode, int maxDepth){
public static MonoPathEvaluator of(Node endNode, Number maxDepth){
return new MonoPathEvaluator(endNode, maxDepth, false);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/tabby/evaluator/TabbyEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
public class TabbyEvaluator extends PathEvaluator.Adapter<TabbyState>{

private Node endNode;
private int maxDepth;
private Number maxDepth;
private boolean checkAuth;
private boolean isBackward;
private Pollution endPol = null;

public TabbyEvaluator(Node endNode, TabbyState endState, int maxDepth, boolean checkAuth, boolean isBackward) {
public TabbyEvaluator(Node endNode, TabbyState endState, Number maxDepth, boolean checkAuth, boolean isBackward) {
this.endNode = endNode;
this.maxDepth = maxDepth;
this.checkAuth = checkAuth;
Expand All @@ -31,17 +31,17 @@ public TabbyEvaluator(Node endNode, TabbyState endState, int maxDepth, boolean c
}
}

public static TabbyEvaluator of(Node endNode, TabbyState endState, int maxDepth, boolean checkAuth, boolean isBackward){
public static TabbyEvaluator of(Node endNode, TabbyState endState, Number maxDepth, boolean checkAuth, boolean isBackward){
return new TabbyEvaluator(endNode, endState, maxDepth, checkAuth, isBackward);
}
@Override
public Evaluation evaluate(Path path, BranchState<TabbyState> branchState) {
boolean includes = true;
boolean continues = true;
int length = path.length();
Long length = (long) path.length();
Node node = path.endNode();

if(length >= maxDepth){
if(length >= (Long)maxDepth){
continues = false; // 超出长度 不继续进行
if(endNode != null && !endNode.equals(node)){
includes = false; // 最后的节点不是endNode,不保存当前结果
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tabby/path/BasePathFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public abstract class BasePathFinder<STATE> extends TraversalPathFinder {

public final PathExpander<STATE> expander;
public final EvaluationContext context;
public final int maxDepth;
public final Number maxDepth;
public final boolean depthFirst;

public BasePathFinder(EvaluationContext context, PathExpander<STATE> expander, int maxDepth, boolean depthFirst) {
public BasePathFinder(EvaluationContext context, PathExpander<STATE> expander, Number maxDepth, boolean depthFirst) {
this.expander = expander;
this.context = context;
this.maxDepth = maxDepth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BidirectionalTraversalPathFinder extends BasePathFinder<State>{

public BidirectionalTraversalPathFinder(EvaluationContext context,
PathExpander<State> expander,
int maxDepth,
Number maxDepth,
State sourceState,
State sinkState,
boolean depthFirst) {
Expand All @@ -43,8 +43,8 @@ protected Traverser instantiateTraverser(Node start, Node end) {
}

return transaction.bidirectionalTraversalDescription()
.startSide( base.expand( expander, sourceState ).evaluator( toDepth( maxDepth / 2 ) ) )
.endSide( base.expand( expander.reverse(), sinkState ).evaluator( toDepth( maxDepth - maxDepth / 2 ) ) )
.startSide( base.expand( expander, sourceState ).evaluator( toDepth( (Integer)maxDepth / 2 ) ) )
.endSide( base.expand( expander.reverse(), sinkState ).evaluator( toDepth( (Integer)maxDepth - (Integer)maxDepth / 2 ) ) )
.traverse( start, end );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MonoDirectionalTraversalPathFinder extends BasePathFinder<State>{

public MonoDirectionalTraversalPathFinder(EvaluationContext context,
PathExpander<State> expander,
int maxDepth,
Number maxDepth,
State state,
boolean depthFirst
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TabbyBidirectionalTraversalPathFinder extends BasePathFinder<TabbyS
public TabbyBidirectionalTraversalPathFinder(EvaluationContext context,
PathExpander<TabbyState> expander,
TabbyState sourceState,
TabbyState sinkState, int maxDepth,
TabbyState sinkState, Number maxDepth,
boolean depthFirst) {
super(context, expander, maxDepth, depthFirst);
this.sourceState = new InitialBranchState.State<>(sourceState, TabbyState.of());
Expand All @@ -38,8 +38,8 @@ protected Traverser instantiateTraverser(Node start, Node end) {
TraversalDescription base = getBaseDescription(transaction);

return transaction.bidirectionalTraversalDescription()
.startSide( base.expand( expander, sourceState ).evaluator( toDepth( maxDepth / 2 ) ) )
.endSide( base.expand( expander.reverse(), sinkState ).evaluator( toDepth( maxDepth - maxDepth / 2 ) ) )
.startSide( base.expand( expander, sourceState ).evaluator( toDepth( (Integer)maxDepth / 2 ) ) )
.endSide( base.expand( expander.reverse(), sinkState ).evaluator( toDepth( (Integer)maxDepth - (Integer)maxDepth / 2 ) ) )
.collisionEvaluator(Evaluators.all())
.collisionPolicy(CollisionDetector::new)
.traverse( start, end );
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tabby/path/TabbyTraversalPathFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TabbyTraversalPathFinder extends BasePathFinder<TabbyState> {
public TabbyTraversalPathFinder(EvaluationContext context,
PathExpander<TabbyState> expander,
TabbyState initialState,
TabbyState endState, int maxDepth,
TabbyState endState, Number maxDepth,
boolean depthFirst, boolean checkAuth, boolean isBackward) {
super(context, expander, maxDepth, depthFirst);
this.state = new InitialBranchState.State<>(initialState, TabbyState.of());
Expand Down