Skip to content

Commit 84dabb9

Browse files
committed
Merge branch 'master' into BAEL-3442
2 parents cc70ce1 + efda444 commit 84dabb9

4,112 files changed

Lines changed: 42817 additions & 408242 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ software-security/sql-injection-samples/derby.log
8484
spring-soap/src/main/java/com/baeldung/springsoap/gen/
8585
/report-*.json
8686
transaction.log
87-
*-shell.log
87+
*-shell.log
88+
89+
apache-cxf/cxf-aegis/baeldung.xml
90+
apache-fop/src/test/resources/input.xml
91+
apache-fop/src/test/resources/output_herold.pdf
92+
apache-fop/src/test/resources/output_html2fo.pdf
93+
apache-fop/src/test/resources/output_jtidy.pdf

akka-http/pom.xml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1-
<?xml version="1.0"?>
2-
<project
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4-
xmlns="http://maven.apache.org/POM/4.0.0"
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>akka-http</artifactId>
7+
<name>akka-http</name>
68

7-
<modelVersion>4.0.0</modelVersion>
8-
<artifactId>akka-http</artifactId>
9-
<name>akka-http</name>
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>parent-modules</artifactId>
12+
<version>1.0.0-SNAPSHOT</version>
13+
</parent>
1014

11-
<parent>
12-
<artifactId>parent-modules</artifactId>
13-
<groupId>com.baeldung</groupId>
14-
<version>1.0.0-SNAPSHOT</version>
15-
</parent>
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.typesafe.akka</groupId>
18+
<artifactId>akka-http_2.12</artifactId>
19+
<version>${akka.http.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.typesafe.akka</groupId>
23+
<artifactId>akka-stream_2.12</artifactId>
24+
<version>${akka.stream.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>com.typesafe.akka</groupId>
28+
<artifactId>akka-http-jackson_2.12</artifactId>
29+
<version>${akka.http.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.typesafe.akka</groupId>
33+
<artifactId>akka-http-testkit_2.12</artifactId>
34+
<version>${akka.http.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
1638

17-
<dependencies>
18-
<dependency>
19-
<groupId>com.typesafe.akka</groupId>
20-
<artifactId>akka-http_2.12</artifactId>
21-
<version>${akka.http.version}</version>
22-
</dependency>
23-
<dependency>
24-
<groupId>com.typesafe.akka</groupId>
25-
<artifactId>akka-stream_2.12</artifactId>
26-
<version>${akka.stream.version}</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>com.typesafe.akka</groupId>
30-
<artifactId>akka-http-jackson_2.12</artifactId>
31-
<version>${akka.http.version}</version>
32-
</dependency>
33-
<dependency>
34-
<groupId>com.typesafe.akka</groupId>
35-
<artifactId>akka-http-testkit_2.12</artifactId>
36-
<version>${akka.http.version}</version>
37-
<scope>test</scope>
38-
</dependency>
39-
</dependencies>
39+
<properties>
40+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
42+
<akka.http.version>10.0.11</akka.http.version>
43+
<akka.stream.version>2.5.11</akka.stream.version>
44+
</properties>
4045

41-
<properties>
42-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
44-
<akka.http.version>10.0.11</akka.http.version>
45-
<akka.stream.version>2.5.11</akka.stream.version>
46-
</properties>
4746
</project>

akka-streams/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<artifactId>akka-streams</artifactId>
66
<name>akka-streams</name>
77

88
<parent>
9-
<artifactId>parent-modules</artifactId>
109
<groupId>com.baeldung</groupId>
10+
<artifactId>parent-modules</artifactId>
1111
<version>1.0.0-SNAPSHOT</version>
1212
</parent>
1313

algorithms-genetic/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<artifactId>algorithms-genetic</artifactId>
56
<version>0.0.1-SNAPSHOT</version>
67
<name>algorithms-genetic</name>
7-
8+
89
<parent>
910
<groupId>com.baeldung</groupId>
1011
<artifactId>parent-modules</artifactId>
@@ -60,5 +61,4 @@
6061
<commons-codec.version>1.11</commons-codec.version>
6162
</properties>
6263

63-
6464
</project>

algorithms-miscellaneous-1/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
77

88
- [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata)
99
- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm)
10-
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
11-
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search)
1210
- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
1311
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
1412
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)

algorithms-miscellaneous-1/pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<artifactId>algorithms-miscellaneous-1</artifactId>
56
<version>0.0.1-SNAPSHOT</version>
67
<name>algorithms-miscellaneous-1</name>
7-
8+
89
<parent>
910
<groupId>com.baeldung</groupId>
1011
<artifactId>parent-modules</artifactId>
@@ -43,7 +44,7 @@
4344
<groupId>com.github.dpaukov</groupId>
4445
<artifactId>combinatoricslib3</artifactId>
4546
<version>${combinatoricslib3.version}</version>
46-
</dependency>
47+
</dependency>
4748
</dependencies>
4849

4950
<build>

algorithms-miscellaneous-2/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<artifactId>algorithms-miscellaneous-2</artifactId>
56
<version>0.0.1-SNAPSHOT</version>
@@ -34,9 +35,9 @@
3435
<version>${org.jgrapht.core.version}</version>
3536
</dependency>
3637
<dependency>
37-
<groupId>org.jgrapht</groupId>
38-
<artifactId>jgrapht-ext</artifactId>
39-
<version>${org.jgrapht.ext.version}</version>
38+
<groupId>org.jgrapht</groupId>
39+
<artifactId>jgrapht-ext</artifactId>
40+
<version>${org.jgrapht.ext.version}</version>
4041
</dependency>
4142
<dependency>
4243
<groupId>pl.allegro.finance</groupId>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.algorithms.astar;
2+
3+
import java.util.Map;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
8+
public class Graph<T extends GraphNode> {
9+
private final Set<T> nodes;
10+
11+
private final Map<String, Set<String>> connections;
12+
13+
public Graph(Set<T> nodes, Map<String, Set<String>> connections) {
14+
this.nodes = nodes;
15+
this.connections = connections;
16+
}
17+
18+
public T getNode(String id) {
19+
return nodes.stream()
20+
.filter(node -> node.getId().equals(id))
21+
.findFirst()
22+
.orElseThrow(() -> new IllegalArgumentException("No node found with ID"));
23+
}
24+
25+
public Set<T> getConnections(T node) {
26+
return connections.get(node.getId()).stream()
27+
.map(this::getNode)
28+
.collect(Collectors.toSet());
29+
}
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.algorithms.astar;
2+
3+
public interface GraphNode {
4+
String getId();
5+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.baeldung.algorithms.astar;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.PriorityQueue;
8+
import java.util.Queue;
9+
import java.util.stream.Collectors;
10+
11+
public class RouteFinder<T extends GraphNode> {
12+
private final Graph<T> graph;
13+
private final Scorer<T> nextNodeScorer;
14+
private final Scorer<T> targetScorer;
15+
16+
public RouteFinder(Graph<T> graph, Scorer<T> nextNodeScorer, Scorer<T> targetScorer) {
17+
this.graph = graph;
18+
this.nextNodeScorer = nextNodeScorer;
19+
this.targetScorer = targetScorer;
20+
}
21+
22+
public List<T> findRoute(T from, T to) {
23+
Map<T, RouteNode<T>> allNodes = new HashMap<>();
24+
Queue<RouteNode> openSet = new PriorityQueue<>();
25+
26+
RouteNode<T> start = new RouteNode<>(from, null, 0d, targetScorer.computeCost(from, to));
27+
allNodes.put(from, start);
28+
openSet.add(start);
29+
30+
while (!openSet.isEmpty()) {
31+
System.out.println("Open Set contains: " + openSet.stream().map(RouteNode::getCurrent).collect(Collectors.toSet()));
32+
RouteNode<T> next = openSet.poll();
33+
System.out.println("Looking at node: " + next);
34+
if (next.getCurrent().equals(to)) {
35+
System.out.println("Found our destination!");
36+
37+
List<T> route = new ArrayList<>();
38+
RouteNode<T> current = next;
39+
do {
40+
route.add(0, current.getCurrent());
41+
current = allNodes.get(current.getPrevious());
42+
} while (current != null);
43+
44+
System.out.println("Route: " + route);
45+
return route;
46+
}
47+
48+
graph.getConnections(next.getCurrent()).forEach(connection -> {
49+
double newScore = next.getRouteScore() + nextNodeScorer.computeCost(next.getCurrent(), connection);
50+
RouteNode<T> nextNode = allNodes.getOrDefault(connection, new RouteNode<>(connection));
51+
allNodes.put(connection, nextNode);
52+
53+
if (nextNode.getRouteScore() > newScore) {
54+
nextNode.setPrevious(next.getCurrent());
55+
nextNode.setRouteScore(newScore);
56+
nextNode.setEstimatedScore(newScore + targetScorer.computeCost(connection, to));
57+
openSet.add(nextNode);
58+
System.out.println("Found a better route to node: " + nextNode);
59+
}
60+
});
61+
}
62+
63+
throw new IllegalStateException("No route found");
64+
}
65+
66+
}

0 commit comments

Comments
 (0)