Skip to content

Commit b10a7bb

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

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ public record BellmanFordResult(
2626
PathFindingResult negativeCycles,
2727
boolean containsNegativeCycle
2828
) {
29-
public static final BellmanFordResult EMPTY = new BellmanFordResult(
30-
PathFindingResult.empty(),
31-
PathFindingResult.empty(),
32-
false
33-
);
29+
public static BellmanFordResult empty() {
30+
return new BellmanFordResult(
31+
PathFindingResult.empty(),
32+
PathFindingResult.empty(),
33+
false
34+
);
35+
}
3436

3537
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public CompletableFuture<BellmanFordResult> bellmanFord(
149149
) {
150150
// If the input graph is empty return a completed future with empty result
151151
if (graph.isEmpty()) {
152-
return CompletableFuture.completedFuture(BellmanFordResult.EMPTY);
152+
return CompletableFuture.completedFuture(BellmanFordResult.empty());
153153
}
154154

155155
// Create ProgressTracker

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.neo4j.gds.kspanningtree.KSpanningTreeParameters;
3737
import org.neo4j.gds.paths.astar.AStarParameters;
3838
import org.neo4j.gds.paths.bellmanford.BellmanFordParameters;
39-
import org.neo4j.gds.paths.bellmanford.BellmanFordResult;
4039
import org.neo4j.gds.paths.delta.DeltaSteppingParameters;
4140
import org.neo4j.gds.paths.dijkstra.DijkstraSingleSourceParameters;
4241
import org.neo4j.gds.paths.dijkstra.DijkstraSourceTargetParameters;
@@ -110,7 +109,14 @@ void bellmanFord() {
110109
var result = future.join();
111110

112111
assertThat(result).isNotNull();
113-
assertThat(result).isEqualTo(BellmanFordResult.EMPTY);
112+
assertThat(result.shortestPaths())
113+
.extracting(PathFindingResult::pathSet)
114+
.asInstanceOf(SET)
115+
.isEmpty();
116+
assertThat(result.negativeCycles())
117+
.extracting(PathFindingResult::pathSet)
118+
.asInstanceOf(SET)
119+
.isEmpty();
114120

115121
verifyNoInteractions(progressTrackerFactoryMock);
116122
verifyNoInteractions(algorithmCallerMock);

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

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

54-
var streamResult = transformer.apply(BellmanFordResult.EMPTY);
54+
var streamResult = transformer.apply(BellmanFordResult.empty());
5555
assertThat(streamResult).isEmpty();
5656

5757
verifyNoInteractions(graphMock);

0 commit comments

Comments
 (0)