Skip to content

Commit cd64289

Browse files
author
Jegors Cemisovs
committed
Add subproject sample
1 parent ff58084 commit cd64289

17 files changed

+74
-626
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ out/
3434
##############################
3535
.DS_Store
3636
/algorithm/gradle.properties
37+
/sample/gradle.properties

.idea/jarRepositories.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algorithm/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ publishing {
1818
// The target repository
1919
maven {
2020
// Choose whatever name you want
21-
name = "algorithms"
21+
name = "Algorithms"
2222
// The url of the repository, where the artifacts will be published
2323
url = "https://maven.pkg.github.com/rabestro/algorithms"
2424
credentials {

build.gradle

-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
plugins {
2-
id 'groovy'
3-
id 'java'
4-
}
5-
61
group 'lv.id.jc'
72
version '1.1'
83

9-
repositories {
10-
mavenCentral()
11-
}
12-
13-
dependencies {
14-
// Spock Framework
15-
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
16-
testImplementation 'org.codehaus.groovy:groovy-all:3.0.9'
17-
18-
// Spock Reports
19-
testRuntimeClasspath( "com.athaydes:spock-reports:2.1.1-groovy-3.0" ) {
20-
transitive = false // this avoids affecting your version of Groovy/Spock
21-
}
22-
// Required for spock-reports
23-
testImplementation 'org.slf4j:slf4j-api:1.7.32'
24-
testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.32'
25-
}
26-
27-
test {
28-
useJUnitPlatform()
29-
}

sample/build.gradle

+16
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@ plugins {
66
group 'lv.id.jc'
77
version '1.1'
88

9+
sourceCompatibility = JavaVersion.VERSION_17
10+
911
repositories {
1012
mavenCentral()
13+
14+
maven {
15+
// Choose whatever name you like
16+
name = "Algorithms"
17+
// The url of the repository that contains the published artifacts
18+
url = "https://maven.pkg.github.com/rabestro/algorithms"
19+
credentials {
20+
// The credentials (described in the next section)
21+
username = project.findProperty("gpr.user")
22+
password = project.findProperty("gpr.key")
23+
}
24+
}
1125
}
1226

1327
dependencies {
1428
implementation 'org.codehaus.groovy:groovy-all:3.0.9'
29+
30+
compileOnly 'lv.id.jc:algorithm:1.1'
1531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package lv.id.jc.sample;
2+
3+
import lv.id.jc.algorithm.graph.BreadthFirstSearch;
4+
import lv.id.jc.algorithm.graph.DijkstrasAlgorithm;
5+
import lv.id.jc.algorithm.graph.Graph;
6+
import lv.id.jc.algorithm.graph.SearchAlgorithm;
7+
8+
import java.util.Map;
9+
10+
import static java.lang.System.*;
11+
12+
public class GraphApp {
13+
private static final Graph<Character> COMPLEX_GRAPH = Graph.of(Map.of(
14+
'A', Map.of('B', 5, 'H', 2),
15+
'B', Map.of('A', 5, 'C', 7),
16+
'C', Map.of('B', 7, 'D', 3, 'G', 4),
17+
'D', Map.of('C', 20, 'E', 4),
18+
'E', Map.of('F', 5),
19+
'F', Map.of('G', 6),
20+
'G', Map.of('C', 4),
21+
'H', Map.of('G', 3)
22+
));
23+
private static final SearchAlgorithm<Character> fastest = new DijkstrasAlgorithm<>();
24+
private static final SearchAlgorithm<Character> shortest = new BreadthFirstSearch<>();
25+
26+
public static void main(String[] args) {
27+
out.println(COMPLEX_GRAPH);
28+
29+
printRoute(COMPLEX_GRAPH, 'D', 'C');
30+
printRoute(COMPLEX_GRAPH, 'A', 'G');
31+
printRoute(COMPLEX_GRAPH, 'D', 'H');
32+
}
33+
34+
private static void printRoute(final Graph<Character> graph,
35+
final Character source,
36+
final Character target) {
37+
final var routeOne = shortest.findPath(graph, source, target);
38+
final var routeTwo = fastest.findPath(graph, source, target);
39+
final var message = """
40+
41+
Find the path from %s to %s
42+
- the shortest take %.0f min and the path is %s
43+
- the fastest take %.0f min and the path is %s"""
44+
.formatted(
45+
source, target,
46+
graph.getDistance(routeOne), routeOne,
47+
graph.getDistance(routeTwo), routeTwo);
48+
49+
out.println(message);
50+
}
51+
}

src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java

-48
This file was deleted.

src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java

-48
This file was deleted.

src/main/java/lv/id/jc/algorithm/graph/Graph.java

-71
This file was deleted.

src/main/java/lv/id/jc/algorithm/graph/SearchAlgorithm.java

-23
This file was deleted.

src/main/java/lv/id/jc/algorithm/graph/package-info.java

-4
This file was deleted.

src/main/java/module-info.java

-8
This file was deleted.

0 commit comments

Comments
 (0)