Skip to content

Commit b980b05

Browse files
Migrate constant PathFindingResult.EMPTY to method
Co-authored-by: Ioannis Panagiotas <ioannis.panagiotas@neotechnology.com>
1 parent b2552f3 commit b980b05

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

algo/src/main/java/org/neo4j/gds/paths/bellmanford/BellmanFordResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public record BellmanFordResult(
2727
boolean containsNegativeCycle
2828
) {
2929
public static final BellmanFordResult EMPTY = new BellmanFordResult(
30-
PathFindingResult.EMPTY,
31-
PathFindingResult.EMPTY,
30+
PathFindingResult.empty(),
31+
PathFindingResult.empty(),
3232
false
3333
);
3434

algo/src/main/java/org/neo4j/gds/paths/dijkstra/PathFindingResult.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
public class PathFindingResult {
3333

34-
public static final PathFindingResult EMPTY = new PathFindingResult(Stream.empty());
35-
3634
private final Stream<PathResult> paths;
3735

3836
private final Runnable closeStreamAction;
@@ -75,4 +73,8 @@ private void runConsumptionAction() {
7573
closeStreamAction.run();
7674
}
7775
}
76+
77+
public static PathFindingResult empty() {
78+
return new PathFindingResult(Stream.empty());
79+
}
7880
}

algorithms-compute-facade/src/main/java/org/neo4j/gds/pathfinding/PathFindingComputeFacade.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public CompletableFuture<PathFindingResult> deltaStepping(
228228
) {
229229
// If the input graph is empty return a completed future with empty result
230230
if (graph.isEmpty()) {
231-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
231+
return CompletableFuture.completedFuture(PathFindingResult.empty());
232232
}
233233

234234
// Create ProgressTracker
@@ -334,7 +334,7 @@ public CompletableFuture<PathFindingResult> longestPath(
334334
) {
335335
// If the input graph is empty return a completed future with empty result
336336
if (graph.isEmpty()) {
337-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
337+
return CompletableFuture.completedFuture(PathFindingResult.empty());
338338
}
339339

340340
// Create ProgressTracker
@@ -474,7 +474,7 @@ public CompletableFuture<PathFindingResult> singlePairShortestPathAStar(
474474
) {
475475
// If the input graph is empty return a completed future with empty result
476476
if (graph.isEmpty()) {
477-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
477+
return CompletableFuture.completedFuture(PathFindingResult.empty());
478478
}
479479

480480
// Create ProgressTracker
@@ -508,7 +508,7 @@ public CompletableFuture<PathFindingResult> singlePairShortestPathDijkstra(
508508
) {
509509
// If the input graph is empty return a completed future with empty result
510510
if (graph.isEmpty()) {
511-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
511+
return CompletableFuture.completedFuture(PathFindingResult.empty());
512512
}
513513

514514
// Create ProgressTracker
@@ -545,7 +545,7 @@ public CompletableFuture<PathFindingResult> singlePairShortestPathYens(
545545
) {
546546
// If the input graph is empty return a completed future with empty result
547547
if (graph.isEmpty()) {
548-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
548+
return CompletableFuture.completedFuture(PathFindingResult.empty());
549549
}
550550

551551
// Create ProgressTracker
@@ -582,7 +582,7 @@ public CompletableFuture<PathFindingResult> singleSourceShortestPathDijkstra(
582582
) {
583583
// If the input graph is empty return a completed future with empty result
584584
if (graph.isEmpty()) {
585-
return CompletableFuture.completedFuture(PathFindingResult.EMPTY);
585+
return CompletableFuture.completedFuture(PathFindingResult.empty());
586586
}
587587

588588
// Create ProgressTracker

algorithms-compute-facade/src/test/java/org/neo4j/gds/pathfinding/PathFindingComputeFacadeEmptyGraphTest.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.neo4j.gds.traversal.TraversalParameters;
5454

5555
import static org.assertj.core.api.Assertions.assertThat;
56+
import static org.assertj.core.api.InstanceOfAssertFactories.SET;
5657
import static org.mockito.Mockito.mock;
5758
import static org.mockito.Mockito.verifyNoInteractions;
5859
import static org.mockito.Mockito.when;
@@ -142,7 +143,11 @@ void deltaStepping() {
142143
);
143144
var result = future.join();
144145

145-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
146+
assertThat(result)
147+
.isNotNull()
148+
.extracting(PathFindingResult::pathSet)
149+
.asInstanceOf(SET)
150+
.isEmpty();
146151

147152
verifyNoInteractions(progressTrackerFactoryMock);
148153
verifyNoInteractions(algorithmCallerMock);
@@ -191,7 +196,11 @@ void longestPath() {
191196
);
192197
var result = future.join();
193198

194-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
199+
assertThat(result)
200+
.isNotNull()
201+
.extracting(PathFindingResult::pathSet)
202+
.asInstanceOf(SET)
203+
.isEmpty();
195204

196205
verifyNoInteractions(progressTrackerFactoryMock);
197206
verifyNoInteractions(algorithmCallerMock);
@@ -257,7 +266,11 @@ void singlePairShortestPathAStar() {
257266
);
258267
var result = future.join();
259268

260-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
269+
assertThat(result)
270+
.isNotNull()
271+
.extracting(PathFindingResult::pathSet)
272+
.asInstanceOf(SET)
273+
.isEmpty();
261274

262275
verifyNoInteractions(progressTrackerFactoryMock);
263276
verifyNoInteractions(algorithmCallerMock);
@@ -273,7 +286,11 @@ void singlePairShortestPathDijkstra() {
273286
);
274287
var result = future.join();
275288

276-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
289+
assertThat(result)
290+
.isNotNull()
291+
.extracting(PathFindingResult::pathSet)
292+
.asInstanceOf(SET)
293+
.isEmpty();
277294

278295
verifyNoInteractions(progressTrackerFactoryMock);
279296
verifyNoInteractions(algorithmCallerMock);
@@ -289,7 +306,11 @@ void singlePairShortestPathYens() {
289306
);
290307
var result = future.join();
291308

292-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
309+
assertThat(result)
310+
.isNotNull()
311+
.extracting(PathFindingResult::pathSet)
312+
.asInstanceOf(SET)
313+
.isEmpty();
293314

294315
verifyNoInteractions(progressTrackerFactoryMock);
295316
verifyNoInteractions(algorithmCallerMock);
@@ -305,7 +326,11 @@ void singleSourceShortestPathDijkstra() {
305326
);
306327
var result = future.join();
307328

308-
assertThat(result).isNotNull().isEqualTo(PathFindingResult.EMPTY);
329+
assertThat(result)
330+
.isNotNull()
331+
.extracting(PathFindingResult::pathSet)
332+
.asInstanceOf(SET)
333+
.isEmpty();
309334

310335
verifyNoInteractions(progressTrackerFactoryMock);
311336
verifyNoInteractions(algorithmCallerMock);

procedures/pushback-procedures-facade/src/test/java/org/neo4j/gds/procedures/algorithms/pathfinding/PathFindingStreamResultTransformerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void shouldReturnEmptyStreamOnEmptyResult() {
5050
pathFactoryFacadeMock
5151
);
5252

53-
var streamResult = transformer.apply(PathFindingResult.EMPTY);
53+
var streamResult = transformer.apply(PathFindingResult.empty());
5454
assertThat(streamResult).isEmpty();
5555

5656
verifyNoInteractions(graphMock);

0 commit comments

Comments
 (0)