diff --git a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java index 0f6cbc7..383495e 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java +++ b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; import java.util.function.BiPredicate; @@ -32,4 +33,9 @@ public interface Gruphi { * @return A {@link DirectedGraphFactory} to create the initial {@link h07.graph.DirectedGraph} */ DirectedGraphFactory getDirectedGraphFactory(); + + /** + * @return A {@link ShortestPathsAlgorithm} for the path finding + */ + ShortestPathsAlgorithm getShortestPathsAlgorithm(); } diff --git a/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java b/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java index 0c4a0e0..eed3b66 100644 --- a/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java +++ b/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; import java.util.function.BiPredicate; @@ -10,6 +11,7 @@ public class GruphiBuilder { private Double gridSpacing; private BiPredicate neighbourPredicate; private DirectedGraphFactory directedGraphFactory; + private ShortestPathsAlgorithm shortestPathsAlgorithm; public GruphiBuilder setFrameDelay(Long frameDelay) { this.frameDelay = frameDelay; @@ -36,7 +38,12 @@ public class GruphiBuilder { return this; } + public GruphiBuilder setShortestPathsAlgorithm(ShortestPathsAlgorithm shortestPathsAlgorithm) { + this.shortestPathsAlgorithm = shortestPathsAlgorithm; + return this; + } + public GruphiImpl createGruphi() { - return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory); + return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm); } } \ No newline at end of file diff --git a/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java b/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java index d53a216..6cd8bce 100644 --- a/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java +++ b/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; import java.util.Objects; @@ -21,16 +22,19 @@ public class GruphiImpl implements Gruphi { private final DirectedGraphFactory directedGraphFactory; + private final ShortestPathsAlgorithm shortestPathsAlgorithm; + public GruphiImpl(Long frameDelay, Double velocity, Double gridSpacing, BiPredicate neighbourPredicate, - DirectedGraphFactory directedGraphFactory) { + DirectedGraphFactory directedGraphFactory, ShortestPathsAlgorithm shortestPathsAlgorithm) { this.frameDelay = frameDelay == null ? DEFAULT_FRAME_DELAY : frameDelay; this.velocity = velocity == null ? DEFAULT_VELOCITY : velocity; this.gridSpacing = gridSpacing == null ? DEFAULT_GRID_SPACING : gridSpacing; this.neighbourPredicate = neighbourPredicate == null ? this::defaultAreNeighbours : neighbourPredicate; this.directedGraphFactory = Objects.requireNonNull(directedGraphFactory, "A directedGraphFactory must be set"); + this.shortestPathsAlgorithm = shortestPathsAlgorithm; } private boolean defaultAreNeighbours(Node a, Node b) { @@ -61,4 +65,9 @@ public class GruphiImpl implements Gruphi { public DirectedGraphFactory getDirectedGraphFactory() { return directedGraphFactory; } + + @Override + public ShortestPathsAlgorithm getShortestPathsAlgorithm() { + return shortestPathsAlgorithm; + } }