diff --git a/.gitignore b/.gitignore
index f6119d5..b1b10da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,4 +32,6 @@ out/
##############################
## OS X
##############################
-.DS_Store
\ No newline at end of file
+.DS_Store
+/algorithm/gradle.properties
+/sample/gradle.properties
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 1b3f3e9..7e20a16 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -11,6 +11,8 @@
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index fdc392f..73a34ad 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -16,5 +16,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/algorithm/build.gradle b/algorithm/build.gradle
new file mode 100644
index 0000000..828691e
--- /dev/null
+++ b/algorithm/build.gradle
@@ -0,0 +1,62 @@
+plugins {
+ id 'groovy'
+ id 'java-library'
+ id 'maven-publish'
+}
+
+group 'lv.id.jc'
+version '1.1'
+
+repositories {
+ mavenCentral()
+}
+
+// Configures the publishing
+publishing {
+ repositories {
+ // The target repository
+ maven {
+ // Choose whatever name you want
+ name = "Algorithms"
+ // The url of the repository, where the artifacts will be published
+ url = "https://maven.pkg.github.com/rabestro/algorithms"
+ credentials {
+ // The credentials (described in the next section)
+ username = project.findProperty("gpr.user")
+ password = project.findProperty("gpr.key")
+ }
+ }
+ }
+ publications {
+ gpr(MavenPublication) {
+ from(components.java)
+ // Fixes the error with dynamic versions when using Spring Boot
+ versionMapping {
+ usage('java-api') {
+ fromResolutionOf('runtimeClasspath')
+ }
+ usage('java-runtime') {
+ fromResolutionResult()
+ }
+ }
+ }
+ }
+}
+
+dependencies {
+ // Spock Framework
+ testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
+ testImplementation 'org.codehaus.groovy:groovy-all:3.0.9'
+
+ // Spock Reports
+ testRuntimeClasspath( "com.athaydes:spock-reports:2.1.1-groovy-3.0" ) {
+ transitive = false // this avoids affecting your version of Groovy/Spock
+ }
+ // Required for spock-reports
+ testImplementation 'org.slf4j:slf4j-api:1.7.32'
+ testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.32'
+}
+
+test {
+ useJUnitPlatform()
+}
diff --git a/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java
similarity index 94%
rename from src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java
rename to algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java
index 6c6cfa2..b7e927d 100644
--- a/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java
+++ b/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java
@@ -1,5 +1,6 @@
package lv.id.jc.algorithm.graph;
+import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -11,18 +12,18 @@
/**
* Algorithm for finding the shortest paths between nodes in a graph.
- *
+ *
* The algorithm doesn't take into account the distance between nodes.
*
- * @author Jegors Čemisovs
* @param the type of vertex
+ * @author Jegors Čemisovs
* @since 1.0
*/
public class BreadthFirstSearch implements SearchAlgorithm {
@Override
public List findPath(Graph graph, T source, T target) {
- var queue = new LinkedList();
+ var queue = new ArrayDeque();
var visited = new HashSet();
var previous = new HashMap();
queue.add(source);
diff --git a/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java
similarity index 95%
rename from src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java
rename to algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java
index c6769c7..41f7817 100644
--- a/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java
+++ b/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java
@@ -1,5 +1,6 @@
package lv.id.jc.algorithm.graph;
+import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -12,15 +13,15 @@
*
* The algorithm uses information about edge's distance to find the fastest path.
*
- * @author Jegors Čemisovs
* @param the type of vertex
+ * @author Jegors Čemisovs
* @since 1.0
*/
public class DijkstrasAlgorithm implements SearchAlgorithm {
@Override
public List findPath(Graph graph, T source, T target) {
- var queue = new LinkedList();
+ var queue = new ArrayDeque();
var distances = new HashMap();
var previous = new HashMap();
queue.add(source);
diff --git a/src/main/java/lv/id/jc/algorithm/graph/Graph.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/Graph.java
similarity index 100%
rename from src/main/java/lv/id/jc/algorithm/graph/Graph.java
rename to algorithm/src/main/java/lv/id/jc/algorithm/graph/Graph.java
diff --git a/src/main/java/lv/id/jc/algorithm/graph/SearchAlgorithm.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/SearchAlgorithm.java
similarity index 100%
rename from src/main/java/lv/id/jc/algorithm/graph/SearchAlgorithm.java
rename to algorithm/src/main/java/lv/id/jc/algorithm/graph/SearchAlgorithm.java
diff --git a/src/main/java/lv/id/jc/algorithm/graph/package-info.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/package-info.java
similarity index 100%
rename from src/main/java/lv/id/jc/algorithm/graph/package-info.java
rename to algorithm/src/main/java/lv/id/jc/algorithm/graph/package-info.java
diff --git a/src/main/java/module-info.java b/algorithm/src/main/java/module-info.java
similarity index 100%
rename from src/main/java/module-info.java
rename to algorithm/src/main/java/module-info.java
diff --git a/src/test/groovy/graph/BreadthFirstSearchSpec.groovy b/algorithm/src/test/groovy/lv/id/jc/graph/BreadthFirstSearchSpec.groovy
similarity index 99%
rename from src/test/groovy/graph/BreadthFirstSearchSpec.groovy
rename to algorithm/src/test/groovy/lv/id/jc/graph/BreadthFirstSearchSpec.groovy
index 1d76485..7feffbd 100644
--- a/src/test/groovy/graph/BreadthFirstSearchSpec.groovy
+++ b/algorithm/src/test/groovy/lv/id/jc/graph/BreadthFirstSearchSpec.groovy
@@ -1,4 +1,4 @@
-package graph
+package lv.id.jc.graph
import lv.id.jc.algorithm.graph.BreadthFirstSearch
import lv.id.jc.algorithm.graph.Graph
diff --git a/src/test/groovy/graph/DijkstrasAlgorithmSpec.groovy b/algorithm/src/test/groovy/lv/id/jc/graph/DijkstrasAlgorithmSpec.groovy
similarity index 99%
rename from src/test/groovy/graph/DijkstrasAlgorithmSpec.groovy
rename to algorithm/src/test/groovy/lv/id/jc/graph/DijkstrasAlgorithmSpec.groovy
index 9ba35d4..db283c6 100644
--- a/src/test/groovy/graph/DijkstrasAlgorithmSpec.groovy
+++ b/algorithm/src/test/groovy/lv/id/jc/graph/DijkstrasAlgorithmSpec.groovy
@@ -1,4 +1,4 @@
-package graph
+package lv.id.jc.graph
import lv.id.jc.algorithm.graph.DijkstrasAlgorithm
import lv.id.jc.algorithm.graph.Graph
diff --git a/src/test/groovy/graph/GraphSpec.groovy b/algorithm/src/test/groovy/lv/id/jc/graph/GraphSpec.groovy
similarity index 99%
rename from src/test/groovy/graph/GraphSpec.groovy
rename to algorithm/src/test/groovy/lv/id/jc/graph/GraphSpec.groovy
index 7264018..5d87b77 100644
--- a/src/test/groovy/graph/GraphSpec.groovy
+++ b/algorithm/src/test/groovy/lv/id/jc/graph/GraphSpec.groovy
@@ -1,4 +1,4 @@
-package graph
+package lv.id.jc.graph
import lv.id.jc.algorithm.graph.Graph
import spock.lang.Narrative
diff --git a/src/test/groovy/graph/SearchAlgorithmSpec.groovy b/algorithm/src/test/groovy/lv/id/jc/graph/SearchAlgorithmSpec.groovy
similarity index 99%
rename from src/test/groovy/graph/SearchAlgorithmSpec.groovy
rename to algorithm/src/test/groovy/lv/id/jc/graph/SearchAlgorithmSpec.groovy
index 337841f..e3b51a2 100644
--- a/src/test/groovy/graph/SearchAlgorithmSpec.groovy
+++ b/algorithm/src/test/groovy/lv/id/jc/graph/SearchAlgorithmSpec.groovy
@@ -1,4 +1,4 @@
-package graph
+package lv.id.jc.graph
import lv.id.jc.algorithm.graph.BreadthFirstSearch
import lv.id.jc.algorithm.graph.DijkstrasAlgorithm
diff --git a/src/test/resources/SpockConfig.groovy b/algorithm/src/test/resources/SpockConfig.groovy
similarity index 100%
rename from src/test/resources/SpockConfig.groovy
rename to algorithm/src/test/resources/SpockConfig.groovy
diff --git a/application/build.gradle b/application/build.gradle
new file mode 100644
index 0000000..7d38e08
--- /dev/null
+++ b/application/build.gradle
@@ -0,0 +1,13 @@
+plugins {
+ id 'application'
+}
+
+dependencies {
+ implementation project(':algorithm')
+}
+
+application {
+ mainModule = 'lv.id.jc.application'
+ mainClass = 'lv.id.jc.application.GraphApp'
+ applicationDefaultJvmArgs = ['-Dgreeting.language=en']
+}
diff --git a/application/src/main/java/lv/id/jc/application/GraphApp.java b/application/src/main/java/lv/id/jc/application/GraphApp.java
new file mode 100644
index 0000000..a6c90b3
--- /dev/null
+++ b/application/src/main/java/lv/id/jc/application/GraphApp.java
@@ -0,0 +1,46 @@
+package lv.id.jc.application;
+
+import lv.id.jc.algorithm.graph.BreadthFirstSearch;
+import lv.id.jc.algorithm.graph.DijkstrasAlgorithm;
+import lv.id.jc.algorithm.graph.Graph;
+import lv.id.jc.algorithm.graph.SearchAlgorithm;
+
+import java.util.Map;
+
+public class GraphApp {
+ private static final Graph graph = Graph.of(Map.of(
+ 'A', Map.of('B', 5, 'H', 2),
+ 'B', Map.of('A', 5, 'C', 7),
+ 'C', Map.of('B', 7, 'D', 3, 'G', 4),
+ 'D', Map.of('C', 20, 'E', 4),
+ 'E', Map.of('F', 5),
+ 'F', Map.of('G', 6),
+ 'G', Map.of('C', 4),
+ 'H', Map.of('G', 3)
+ ));
+ private static final SearchAlgorithm fastest = new DijkstrasAlgorithm<>();
+ private static final SearchAlgorithm shortest = new BreadthFirstSearch<>();
+
+ public static void main(String[] args) {
+ printRoute('D', 'C');
+ printRoute('A', 'G');
+ printRoute('D', 'H');
+ }
+
+ @SuppressWarnings("squid:S106")
+ private static void printRoute(Character source, Character target) {
+ var routeOne = shortest.findPath(graph, source, target);
+ var routeTwo = fastest.findPath(graph, source, target);
+ var message = """
+
+ Find the path from %s to %s
+ - the shortest take %.0f min and the path is %s
+ - the fastest take %.0f min and the path is %s"""
+ .formatted(
+ source, target,
+ graph.getDistance(routeOne), routeOne,
+ graph.getDistance(routeTwo), routeTwo);
+
+ System.out.println(message);
+ }
+}
diff --git a/application/src/main/java/module-info.java b/application/src/main/java/module-info.java
new file mode 100644
index 0000000..1ffe06e
--- /dev/null
+++ b/application/src/main/java/module-info.java
@@ -0,0 +1,4 @@
+module lv.id.jc.application {
+ requires lv.id.jc.algorithm.graph;
+ exports lv.id.jc.application;
+}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index f27459d..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,29 +0,0 @@
-plugins {
- id 'groovy'
- id 'java'
-}
-
-group 'lv.id.jc'
-version '1.1'
-
-repositories {
- mavenCentral()
-}
-
-dependencies {
- // Spock Framework
- testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
- testImplementation 'org.codehaus.groovy:groovy-all:3.0.9'
-
- // Spock Reports
- testRuntimeClasspath( "com.athaydes:spock-reports:2.1.1-groovy-3.0" ) {
- transitive = false // this avoids affecting your version of Groovy/Spock
- }
- // Required for spock-reports
- testImplementation 'org.slf4j:slf4j-api:1.7.32'
- testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.32'
-}
-
-test {
- useJUnitPlatform()
-}
diff --git a/settings.gradle b/settings.gradle
index 89fef3f..b469ed7 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1,2 @@
-rootProject.name = 'search-algorithm'
+rootProject.name = 'graphs-algorithms'
+include 'algorithm', 'application'