diff --git a/.gitignore b/.gitignore
index 7fe2778755..0e71421ee7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,4 +63,6 @@ jmeter/src/main/resources/*-JMeter.csv
**/tmp
**/out-tsc
**/nbproject/
-**/nb-configuration.xml
\ No newline at end of file
+**/nb-configuration.xml
+core-scala/.cache-main
+core-scala/.cache-tests
diff --git a/.travis.yml b/.travis.yml
index 683422dc97..5e86714a89 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,7 @@ before_install:
- echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc
install: skip
-script: travis_wait 60 mvn -q install -Pdefault-first,default-second
+script: travis_wait 60 mvn -q install -Pdefault-first,default-second -Dgib.enabled=true
sudo: required
diff --git a/JGit/src/main/java/com/baeldung/jgit/porcelain/Log.java b/JGit/src/main/java/com/baeldung/jgit/porcelain/Log.java
index cb476b9d9e..a50028a9ae 100644
--- a/JGit/src/main/java/com/baeldung/jgit/porcelain/Log.java
+++ b/JGit/src/main/java/com/baeldung/jgit/porcelain/Log.java
@@ -28,14 +28,14 @@ public class Log {
System.out.println("Had " + count + " commits overall on current branch");
logs = git.log()
- .add(repository.resolve("remotes/origin/testbranch"))
+ .add(repository.resolve(git.getRepository().getFullBranch()))
.call();
count = 0;
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
- System.out.println("Had " + count + " commits overall on test-branch");
+ System.out.println("Had " + count + " commits overall on "+git.getRepository().getFullBranch());
logs = git.log()
.all()
diff --git a/JGit/src/test/java/com/baeldung/jgit/JGitBugIntegrationTest.java b/JGit/src/test/java/com/baeldung/jgit/JGitBugIntegrationTest.java
index ed7168b2c2..ad34890996 100644
--- a/JGit/src/test/java/com/baeldung/jgit/JGitBugIntegrationTest.java
+++ b/JGit/src/test/java/com/baeldung/jgit/JGitBugIntegrationTest.java
@@ -1,3 +1,5 @@
+package com.baeldung.jgit;
+
import com.baeldung.jgit.helper.Helper;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader;
diff --git a/akka-http/pom.xml b/akka-http/pom.xml
new file mode 100644
index 0000000000..51e70fb583
--- /dev/null
+++ b/akka-http/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+ 4.0.0
+ akka-http
+ akka-http
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+
+
+
+ com.typesafe.akka
+ akka-http_2.12
+ ${akka.http.version}
+
+
+ com.typesafe.akka
+ akka-stream_2.12
+ 2.5.11
+
+
+ com.typesafe.akka
+ akka-http-jackson_2.12
+ ${akka.http.version}
+
+
+ com.typesafe.akka
+ akka-http-testkit_2.12
+ ${akka.http.version}
+ test
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ 10.0.11
+ 2.5.11
+
+
diff --git a/akka-http/src/main/java/com/baeldung/akkahttp/User.java b/akka-http/src/main/java/com/baeldung/akkahttp/User.java
new file mode 100644
index 0000000000..43c21eca62
--- /dev/null
+++ b/akka-http/src/main/java/com/baeldung/akkahttp/User.java
@@ -0,0 +1,26 @@
+package com.baeldung.akkahttp;
+
+public class User {
+
+ private final Long id;
+
+ private final String name;
+
+ public User() {
+ this.name = "";
+ this.id = null;
+ }
+
+ public User(Long id, String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+}
\ No newline at end of file
diff --git a/akka-http/src/main/java/com/baeldung/akkahttp/UserActor.java b/akka-http/src/main/java/com/baeldung/akkahttp/UserActor.java
new file mode 100644
index 0000000000..431014a88b
--- /dev/null
+++ b/akka-http/src/main/java/com/baeldung/akkahttp/UserActor.java
@@ -0,0 +1,41 @@
+package com.baeldung.akkahttp;
+
+import akka.actor.AbstractActor;
+import akka.actor.Props;
+import akka.japi.pf.FI;
+import com.baeldung.akkahttp.UserMessages.ActionPerformed;
+import com.baeldung.akkahttp.UserMessages.CreateUserMessage;
+import com.baeldung.akkahttp.UserMessages.GetUserMessage;
+
+
+class UserActor extends AbstractActor {
+
+ private UserService userService = new UserService();
+
+ static Props props() {
+ return Props.create(UserActor.class);
+ }
+
+ @Override
+ public Receive createReceive() {
+ return receiveBuilder()
+ .match(CreateUserMessage.class, handleCreateUser())
+ .match(GetUserMessage.class, handleGetUser())
+ .build();
+ }
+
+ private FI.UnitApply handleCreateUser() {
+ return createUserMessageMessage -> {
+ userService.createUser(createUserMessageMessage.getUser());
+ sender().tell(new ActionPerformed(String.format("User %s created.", createUserMessageMessage.getUser()
+ .getName())), getSelf());
+ };
+ }
+
+ private FI.UnitApply handleGetUser() {
+ return getUserMessageMessage -> {
+ sender().tell(userService.getUser(getUserMessageMessage.getUserId()), getSelf());
+ };
+ }
+
+}
diff --git a/akka-http/src/main/java/com/baeldung/akkahttp/UserMessages.java b/akka-http/src/main/java/com/baeldung/akkahttp/UserMessages.java
new file mode 100644
index 0000000000..995b92bcb0
--- /dev/null
+++ b/akka-http/src/main/java/com/baeldung/akkahttp/UserMessages.java
@@ -0,0 +1,49 @@
+package com.baeldung.akkahttp;
+
+import java.io.Serializable;
+
+public interface UserMessages {
+
+ class ActionPerformed implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String description;
+
+ public ActionPerformed(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+ }
+
+ class CreateUserMessage implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private final User user;
+
+ public CreateUserMessage(User user) {
+ this.user = user;
+ }
+
+ public User getUser() {
+ return user;
+ }
+ }
+
+ class GetUserMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private final Long userId;
+
+ public GetUserMessage(Long userId) {
+ this.userId = userId;
+ }
+
+ public Long getUserId() {
+ return userId;
+ }
+ }
+
+}
diff --git a/akka-http/src/main/java/com/baeldung/akkahttp/UserServer.java b/akka-http/src/main/java/com/baeldung/akkahttp/UserServer.java
new file mode 100644
index 0000000000..0c1dbd1f60
--- /dev/null
+++ b/akka-http/src/main/java/com/baeldung/akkahttp/UserServer.java
@@ -0,0 +1,70 @@
+package com.baeldung.akkahttp;
+
+import java.util.Optional;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.TimeUnit;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.http.javadsl.marshallers.jackson.Jackson;
+import akka.http.javadsl.model.StatusCodes;
+import akka.http.javadsl.server.HttpApp;
+import akka.http.javadsl.server.Route;
+import akka.pattern.PatternsCS;
+import akka.util.Timeout;
+import com.baeldung.akkahttp.UserMessages.ActionPerformed;
+import com.baeldung.akkahttp.UserMessages.CreateUserMessage;
+import com.baeldung.akkahttp.UserMessages.GetUserMessage;
+import scala.concurrent.duration.Duration;
+import static akka.http.javadsl.server.PathMatchers.*;
+
+class UserServer extends HttpApp {
+
+ private final ActorRef userActor;
+
+ Timeout timeout = new Timeout(Duration.create(5, TimeUnit.SECONDS));
+
+ UserServer(ActorRef userActor) {
+ this.userActor = userActor;
+ }
+
+ @Override
+ public Route routes() {
+ return path("users", this::postUser)
+ .orElse(path(segment("users").slash(longSegment()), id ->
+ route(getUser(id))));
+ }
+
+ private Route getUser(Long id) {
+ return get(() -> {
+ CompletionStage> user = PatternsCS.ask(userActor, new GetUserMessage(id), timeout)
+ .thenApply(obj -> (Optional) obj);
+
+ return onSuccess(() -> user, performed -> {
+ if (performed.isPresent())
+ return complete(StatusCodes.OK, performed.get(), Jackson.marshaller());
+ else
+ return complete(StatusCodes.NOT_FOUND);
+ });
+ });
+ }
+
+ private Route postUser() {
+ return route(post(() -> entity(Jackson.unmarshaller(User.class), user -> {
+ CompletionStage userCreated = PatternsCS.ask(userActor, new CreateUserMessage(user), timeout)
+ .thenApply(obj -> (ActionPerformed) obj);
+
+ return onSuccess(() -> userCreated, performed -> {
+ return complete(StatusCodes.CREATED, performed, Jackson.marshaller());
+ });
+ })));
+ }
+
+ public static void main(String[] args) throws Exception {
+ ActorSystem system = ActorSystem.create("userServer");
+ ActorRef userActor = system.actorOf(UserActor.props(), "userActor");
+ UserServer server = new UserServer(userActor);
+ server.startServer("localhost", 8080, system);
+ }
+
+}
diff --git a/akka-http/src/main/java/com/baeldung/akkahttp/UserService.java b/akka-http/src/main/java/com/baeldung/akkahttp/UserService.java
new file mode 100644
index 0000000000..50dc1e1b28
--- /dev/null
+++ b/akka-http/src/main/java/com/baeldung/akkahttp/UserService.java
@@ -0,0 +1,35 @@
+package com.baeldung.akkahttp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+public class UserService {
+
+ private final static List users = new ArrayList<>();
+
+ static {
+ users.add(new User(1l, "Alice"));
+ users.add(new User(2l, "Bob"));
+ users.add(new User(3l, "Chris"));
+ users.add(new User(4l, "Dick"));
+ users.add(new User(5l, "Eve"));
+ users.add(new User(6l, "Finn"));
+ }
+
+ public Optional getUser(Long id) {
+ return users.stream()
+ .filter(user -> user.getId()
+ .equals(id))
+ .findFirst();
+ }
+
+ public void createUser(User user) {
+ users.add(user);
+ }
+
+ public List getUsers(){
+ return users;
+ }
+
+}
diff --git a/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java b/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java
new file mode 100644
index 0000000000..1170a2d761
--- /dev/null
+++ b/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.akkahttp;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.http.javadsl.model.ContentTypes;
+import akka.http.javadsl.model.HttpEntities;
+import akka.http.javadsl.model.HttpRequest;
+import akka.http.javadsl.testkit.JUnitRouteTest;
+import akka.http.javadsl.testkit.TestRoute;
+import org.junit.Test;
+
+public class UserServerUnitTest extends JUnitRouteTest {
+
+ ActorSystem system = ActorSystem.create("helloAkkaHttpServer");
+
+ ActorRef userActorRef = system.actorOf(UserActor.props(), "userActor");
+
+ TestRoute appRoute = testRoute(new UserServer(userActorRef).routes());
+
+ @Test
+ public void whenRequest_thenActorResponds() {
+
+ appRoute.run(HttpRequest.GET("/users/1"))
+ .assertEntity(alice())
+ .assertStatusCode(200);
+
+ appRoute.run(HttpRequest.GET("/users/42"))
+ .assertStatusCode(404);
+
+ appRoute.run(HttpRequest.DELETE("/users/1"))
+ .assertStatusCode(200);
+
+ appRoute.run(HttpRequest.DELETE("/users/42"))
+ .assertStatusCode(200);
+
+ appRoute.run(HttpRequest.POST("/users")
+ .withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, zaphod())))
+ .assertStatusCode(201);
+
+ }
+
+ private String alice() {
+ return "{\"id\":1,\"name\":\"Alice\"}";
+ }
+
+ private String zaphod() {
+ return "{\"id\":42,\"name\":\"Zaphod\"}";
+ }
+
+}
diff --git a/algorithms-genetic/.gitignore b/algorithms-genetic/.gitignore
new file mode 100644
index 0000000000..30b2b7442c
--- /dev/null
+++ b/algorithms-genetic/.gitignore
@@ -0,0 +1,4 @@
+/target/
+.settings/
+.classpath
+.project
\ No newline at end of file
diff --git a/algorithms-genetic/README.md b/algorithms-genetic/README.md
new file mode 100644
index 0000000000..39f8d59eee
--- /dev/null
+++ b/algorithms-genetic/README.md
@@ -0,0 +1,6 @@
+## Relevant articles:
+
+- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
+- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
+- [Design a Genetic Algorithm in Java](https://www.baeldung.com/java-genetic-algorithm)
+- [The Traveling Salesman Problem in Java](https://www.baeldung.com/java-simulated-annealing-for-traveling-salesman)
diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml
new file mode 100644
index 0000000000..fc6d36dac1
--- /dev/null
+++ b/algorithms-genetic/pom.xml
@@ -0,0 +1,65 @@
+
+ 4.0.0
+ algorithms-genetic
+ 0.0.1-SNAPSHOT
+ algorithms-genetic
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ io.jenetics
+ jenetics
+ ${io.jenetics.version}
+
+
+ org.assertj
+ assertj-core
+ ${org.assertj.core.version}
+ test
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+
+
+
+
+ 1.16.12
+ 3.6.1
+ 3.7.0
+ 3.9.0
+ 1.11
+
+
+
+
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
similarity index 71%
rename from algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
index ce04d26db3..779cb9b970 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
+++ b/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
@@ -5,7 +5,6 @@ import java.util.Scanner;
import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
-import com.baeldung.algorithms.slope_one.SlopeOne;
public class RunAlgorithm {
@@ -13,11 +12,8 @@ public class RunAlgorithm {
Scanner in = new Scanner(System.in);
System.out.println("Run algorithm:");
System.out.println("1 - Simulated Annealing");
- System.out.println("2 - Slope One");
- System.out.println("3 - Simple Genetic Algorithm");
- System.out.println("4 - Ant Colony");
- System.out.println("5 - Dijkstra");
- System.out.println("6 - All pairs in an array that add up to a given sum");
+ System.out.println("2 - Simple Genetic Algorithm");
+ System.out.println("3 - Ant Colony");
int decision = in.nextInt();
switch (decision) {
case 1:
@@ -25,19 +21,13 @@ public class RunAlgorithm {
"Optimized distance for travel: " + SimulatedAnnealing.simulateAnnealing(10, 10000, 0.9995));
break;
case 2:
- SlopeOne.slopeOne(3);
- break;
- case 3:
SimpleGeneticAlgorithm ga = new SimpleGeneticAlgorithm();
ga.runAlgorithm(50, "1011000100000100010000100000100111001000000100000100000000001111");
break;
- case 4:
+ case 3:
AntColonyOptimization antColony = new AntColonyOptimization(21);
antColony.startAntOptimization();
break;
- case 5:
- System.out.println("Please run the DijkstraAlgorithmTest.");
- break;
default:
System.out.println("Unknown option");
break;
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/City.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/City.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/City.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/City.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/SimulatedAnnealing.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/SimulatedAnnealing.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/SimulatedAnnealing.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/SimulatedAnnealing.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/Travel.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/Travel.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/annealing/Travel.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/annealing/Travel.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/ant_colony/Ant.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/ant_colony/Ant.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/ant_colony/Ant.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/ant_colony/Ant.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/ant_colony/AntColonyOptimization.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/ant_colony/AntColonyOptimization.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/ant_colony/AntColonyOptimization.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/ant_colony/AntColonyOptimization.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/binary/Individual.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/Individual.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/binary/Individual.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/Individual.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/binary/Population.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/Population.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/binary/Population.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/Population.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/binary/SimpleGeneticAlgorithm.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/SimpleGeneticAlgorithm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/binary/SimpleGeneticAlgorithm.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/binary/SimpleGeneticAlgorithm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/Knapsack.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/Knapsack.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/Knapsack.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/Knapsack.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackFF.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackFF.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackFF.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackFF.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackItem.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackItem.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackItem.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/KnapsackItem.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SimpleGeneticAlgorithm.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SimpleGeneticAlgorithm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SimpleGeneticAlgorithm.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SimpleGeneticAlgorithm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenProblem.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenProblem.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenProblem.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenProblem.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenRecord.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenRecord.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenRecord.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SpringsteenRecord.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SubsetSum.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SubsetSum.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/SubsetSum.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/SubsetSum.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/TravelingSalesman.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/TravelingSalesman.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/jenetics/TravelingSalesman.java
rename to algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/jenetics/TravelingSalesman.java
diff --git a/activejdbc/src/main/resources/logback.xml b/algorithms-genetic/src/main/resources/logback.xml
similarity index 100%
rename from activejdbc/src/main/resources/logback.xml
rename to algorithms-genetic/src/main/resources/logback.xml
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/AntColonyOptimizationLongRunningUnitTest.java b/algorithms-genetic/src/test/java/com/baeldung/algorithms/AntColonyOptimizationLongRunningUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/AntColonyOptimizationLongRunningUnitTest.java
rename to algorithms-genetic/src/test/java/com/baeldung/algorithms/AntColonyOptimizationLongRunningUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java b/algorithms-genetic/src/test/java/com/baeldung/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java
rename to algorithms-genetic/src/test/java/com/baeldung/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/SimulatedAnnealingLongRunningUnitTest.java b/algorithms-genetic/src/test/java/com/baeldung/algorithms/SimulatedAnnealingLongRunningUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/SimulatedAnnealingLongRunningUnitTest.java
rename to algorithms-genetic/src/test/java/com/baeldung/algorithms/SimulatedAnnealingLongRunningUnitTest.java
diff --git a/algorithms-miscellaneous-1/.gitignore b/algorithms-miscellaneous-1/.gitignore
new file mode 100644
index 0000000000..30b2b7442c
--- /dev/null
+++ b/algorithms-miscellaneous-1/.gitignore
@@ -0,0 +1,4 @@
+/target/
+.settings/
+.classpath
+.project
\ No newline at end of file
diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md
new file mode 100644
index 0000000000..a725bbd141
--- /dev/null
+++ b/algorithms-miscellaneous-1/README.md
@@ -0,0 +1,15 @@
+## Relevant articles:
+
+- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
+- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
+- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
+- [Binary Search Algorithm in Java](http://www.baeldung.com/java-binary-search)
+- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
+- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)
+- [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element)
+- [Multi-Swarm Optimization Algorithm in Java](http://www.baeldung.com/java-multi-swarm-algorithm)
+- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
+- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
+- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
+- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial)
+- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)
\ No newline at end of file
diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml
new file mode 100644
index 0000000000..5006670dd9
--- /dev/null
+++ b/algorithms-miscellaneous-1/pom.xml
@@ -0,0 +1,84 @@
+
+ 4.0.0
+ algorithms-miscellaneous-1
+ 0.0.1-SNAPSHOT
+ algorithms-miscellaneous-1
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.assertj
+ assertj-core
+ ${org.assertj.core.version}
+ test
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+
+
+ com/baeldung/algorithms/dijkstra/*
+
+
+ com/baeldung/algorithms/dijkstra/*
+
+
+
+
+
+
+
+
+ 1.16.12
+ 3.6.1
+ 3.9.0
+ 1.11
+ 25.1-jre
+
+
+
\ No newline at end of file
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/FiniteStateMachine.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/FiniteStateMachine.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/FiniteStateMachine.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/FiniteStateMachine.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/RtFiniteStateMachine.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtFiniteStateMachine.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/RtFiniteStateMachine.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtFiniteStateMachine.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/RtState.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtState.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/RtState.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtState.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/RtTransition.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtTransition.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/RtTransition.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/RtTransition.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/State.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/State.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/State.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/State.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/automata/Transition.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/Transition.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/automata/Transition.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/automata/Transition.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
new file mode 100644
index 0000000000..43d2221773
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
@@ -0,0 +1,63 @@
+package com.baeldung.algorithms.factorial;
+
+import java.math.BigInteger;
+import java.util.stream.LongStream;
+
+import org.apache.commons.math3.util.CombinatoricsUtils;
+
+import com.google.common.math.BigIntegerMath;
+
+public class Factorial {
+
+ public long factorialUsingForLoop(int n) {
+ long fact = 1;
+ for (int i = 2; i <= n; i++) {
+ fact = fact * i;
+ }
+ return fact;
+ }
+
+ public long factorialUsingStreams(int n) {
+ return LongStream.rangeClosed(1, n)
+ .reduce(1, (long x, long y) -> x * y);
+ }
+
+ public long factorialUsingRecursion(int n) {
+ if (n <= 2) {
+ return n;
+ }
+ return n * factorialUsingRecursion(n - 1);
+ }
+
+ private Long[] factorials = new Long[20];
+
+ public long factorialUsingMemoize(int n) {
+
+ if (factorials[n] != null) {
+ return factorials[n];
+ }
+
+ if (n <= 2) {
+ return n;
+ }
+ long nthValue = n * factorialUsingMemoize(n - 1);
+ factorials[n] = nthValue;
+ return nthValue;
+ }
+
+ public BigInteger factorialHavingLargeResult(int n) {
+ BigInteger result = BigInteger.ONE;
+ for (int i = 2; i <= n; i++)
+ result = result.multiply(BigInteger.valueOf(i));
+ return result;
+ }
+
+ public long factorialUsingApacheCommons(int n) {
+ return CombinatoricsUtils.factorial(n);
+ }
+
+ public BigInteger factorialUsingGuava(int n) {
+ return BigIntegerMath.factorial(n);
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/hillclimbing/HillClimbing.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/hillclimbing/HillClimbing.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/hillclimbing/HillClimbing.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/hillclimbing/HillClimbing.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/hillclimbing/State.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/hillclimbing/State.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/hillclimbing/State.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/hillclimbing/State.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/MiddleElementLookup.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/middleelementlookup/MiddleElementLookup.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/MiddleElementLookup.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/middleelementlookup/MiddleElementLookup.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/Node.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/middleelementlookup/Node.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/Node.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/middleelementlookup/Node.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/minimax/GameOfBones.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/GameOfBones.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/minimax/GameOfBones.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/GameOfBones.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/minimax/MiniMax.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/MiniMax.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/minimax/MiniMax.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/MiniMax.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/minimax/Node.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/Node.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/minimax/Node.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/Node.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/minimax/Tree.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/Tree.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/minimax/Tree.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/minimax/Tree.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Constants.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Constants.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Constants.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Constants.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/multiswarm/FitnessFunction.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/FitnessFunction.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/multiswarm/FitnessFunction.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/FitnessFunction.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Multiswarm.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Multiswarm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Multiswarm.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Multiswarm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Particle.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Particle.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Particle.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Particle.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Swarm.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Swarm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/multiswarm/Swarm.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/multiswarm/Swarm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/string/EnglishAlphabetLetters.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/EnglishAlphabetLetters.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/string/EnglishAlphabetLetters.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/EnglishAlphabetLetters.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharacters.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharacters.java
new file mode 100644
index 0000000000..cd1f3e94d5
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharacters.java
@@ -0,0 +1,54 @@
+package com.baeldung.algorithms.string;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class LongestSubstringNonRepeatingCharacters {
+
+ public static String getUniqueCharacterSubstringBruteForce(String input) {
+ String output = "";
+ for (int start = 0; start < input.length(); start++) {
+ Set visited = new HashSet<>();
+ int end = start;
+ for (; end < input.length(); end++) {
+ char currChar = input.charAt(end);
+ if (visited.contains(currChar)) {
+ break;
+ } else {
+ visited.add(currChar);
+ }
+ }
+ if (output.length() < end - start + 1) {
+ output = input.substring(start, end);
+ }
+ }
+ return output;
+ }
+
+ public static String getUniqueCharacterSubstring(String input) {
+ Map visited = new HashMap<>();
+ String output = "";
+ for (int start = 0, end = 0; end < input.length(); end++) {
+ char currChar = input.charAt(end);
+ if (visited.containsKey(currChar)) {
+ start = Math.max(visited.get(currChar) + 1, start);
+ }
+ if (output.length() < end - start + 1) {
+ output = input.substring(start, end + 1);
+ }
+ visited.put(currChar, end);
+ }
+ return output;
+ }
+
+ public static void main(String[] args) {
+ if(args.length > 0) {
+ System.out.println(getUniqueCharacterSubstring(args[0]));
+ } else {
+ System.err.println("This program expects command-line input. Please try again!");
+ }
+ }
+
+}
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/SubstringPalindrome.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/SubstringPalindrome.java
new file mode 100644
index 0000000000..b3d142eb07
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/SubstringPalindrome.java
@@ -0,0 +1,90 @@
+package com.baeldung.algorithms.string;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class SubstringPalindrome {
+
+ public Set findAllPalindromesUsingCenter(String input) {
+ final Set palindromes = new HashSet<>();
+ if (input == null || input.isEmpty()) {
+ return palindromes;
+ }
+ if (input.length() == 1) {
+ palindromes.add(input);
+ return palindromes;
+ }
+ for (int i = 0; i < input.length(); i++) {
+ palindromes.addAll(findPalindromes(input, i, i + 1));
+ palindromes.addAll(findPalindromes(input, i, i));
+ }
+ return palindromes;
+ }
+
+ private Set findPalindromes(String input, int low, int high) {
+ Set result = new HashSet<>();
+ while (low >= 0 && high < input.length() && input.charAt(low) == input.charAt(high)) {
+ result.add(input.substring(low, high + 1));
+ low--;
+ high++;
+ }
+ return result;
+ }
+
+ public Set findAllPalindromesUsingBruteForceApproach(String input) {
+ Set palindromes = new HashSet<>();
+ if (input == null || input.isEmpty()) {
+ return palindromes;
+ }
+ if (input.length() == 1) {
+ palindromes.add(input);
+ return palindromes;
+ }
+ for (int i = 0; i < input.length(); i++) {
+ for (int j = i + 1; j <= input.length(); j++)
+ if (isPalindrome(input.substring(i, j))) {
+ palindromes.add(input.substring(i, j));
+ }
+ }
+ return palindromes;
+ }
+
+ private boolean isPalindrome(String input) {
+ StringBuilder plain = new StringBuilder(input);
+ StringBuilder reverse = plain.reverse();
+ return (reverse.toString()).equals(input);
+ }
+
+ public Set findAllPalindromesUsingManachersAlgorithm(String input) {
+ Set palindromes = new HashSet<>();
+ String formattedInput = "@" + input + "#";
+ char inputCharArr[] = formattedInput.toCharArray();
+ int max;
+ int radius[][] = new int[2][input.length() + 1];
+ for (int j = 0; j <= 1; j++) {
+ radius[j][0] = max = 0;
+ int i = 1;
+ while (i <= input.length()) {
+ palindromes.add(Character.toString(inputCharArr[i]));
+ while (inputCharArr[i - max - 1] == inputCharArr[i + j + max])
+ max++;
+ radius[j][i] = max;
+ int k = 1;
+ while ((radius[j][i - k] != max - k) && (k < max)) {
+ radius[j][i + k] = Math.min(radius[j][i - k], max - k);
+ k++;
+ }
+ max = Math.max(max - k, 0);
+ i += k;
+ }
+ }
+ for (int i = 1; i <= input.length(); i++) {
+ for (int j = 0; j <= 1; j++) {
+ for (max = radius[j][i]; max > 0; max--) {
+ palindromes.add(input.substring(i - max - 1, max + j + i - 1));
+ }
+ }
+ }
+ return palindromes;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java
rename to algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java
diff --git a/algorithms/src/main/resources/logback.xml b/algorithms-miscellaneous-1/src/main/resources/logback.xml
similarity index 100%
rename from algorithms/src/main/resources/logback.xml
rename to algorithms-miscellaneous-1/src/main/resources/logback.xml
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/HillClimbingAlgorithmUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/HillClimbingAlgorithmUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/HillClimbingAlgorithmUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/HillClimbingAlgorithmUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/MiddleElementLookupUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/MiddleElementLookupUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/MiddleElementLookupUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/MiddleElementLookupUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/RtFiniteStateMachineLongRunningUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
new file mode 100644
index 0000000000..c185dba62b
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
@@ -0,0 +1,72 @@
+package com.baeldung.algorithms.factorial;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.math.BigInteger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class FactorialUnitTest {
+
+ Factorial factorial;
+
+ @Before
+ public void setup() {
+ factorial = new Factorial();
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingForLoop_thenCorrect() {
+ int n = 5;
+
+ assertThat(factorial.factorialUsingForLoop(n)).isEqualTo(120);
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingStreams_thenCorrect() {
+ int n = 5;
+
+ assertThat(factorial.factorialUsingStreams(n)).isEqualTo(120);
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingRecursion_thenCorrect() {
+ int n = 5;
+
+ assertThat(factorial.factorialUsingRecursion(n)).isEqualTo(120);
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingMemoize_thenCorrect() {
+ int n = 5;
+
+ assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(120);
+
+ n = 6;
+
+ assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(720);
+ }
+
+ @Test
+ public void whenCalculatingFactorialHavingLargeResult_thenCorrect() {
+ int n = 22;
+
+ assertThat(factorial.factorialHavingLargeResult(n)).isEqualTo(new BigInteger("1124000727777607680000"));
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingApacheCommons_thenCorrect() {
+ int n = 5;
+
+ assertThat(factorial.factorialUsingApacheCommons(n)).isEqualTo(120);
+ }
+
+ @Test
+ public void whenCalculatingFactorialUsingGuava_thenCorrect() {
+ int n = 22;
+
+ assertThat(factorial.factorialUsingGuava(n)).isEqualTo(new BigInteger("1124000727777607680000"));
+ }
+
+}
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/kthlargest/FindKthLargestUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/kthlargest/FindKthLargestUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/kthlargest/FindKthLargestUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/kthlargest/FindKthLargestUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/minimax/MinimaxUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/minimax/MinimaxUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/minimax/MinimaxUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/minimax/MinimaxUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/multiswarm/LolFitnessFunction.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/multiswarm/LolFitnessFunction.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/multiswarm/LolFitnessFunction.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/multiswarm/LolFitnessFunction.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/multiswarm/MultiswarmUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/multiswarm/MultiswarmUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/multiswarm/MultiswarmUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/multiswarm/MultiswarmUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/string/EnglishAlphabetLettersUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/EnglishAlphabetLettersUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/string/EnglishAlphabetLettersUnitTest.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/EnglishAlphabetLettersUnitTest.java
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharactersUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharactersUnitTest.java
new file mode 100644
index 0000000000..9f1e6a2519
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/LongestSubstringNonRepeatingCharactersUnitTest.java
@@ -0,0 +1,31 @@
+package com.baeldung.algorithms.string;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static com.baeldung.algorithms.string.LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstring;
+import static com.baeldung.algorithms.string.LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstringBruteForce;
+
+public class LongestSubstringNonRepeatingCharactersUnitTest {
+
+ @Test
+ void givenString_whenGetUniqueCharacterSubstringBruteForceCalled_thenResultFoundAsExpectedUnitTest() {
+ assertEquals("", getUniqueCharacterSubstringBruteForce(""));
+ assertEquals("A", getUniqueCharacterSubstringBruteForce("A"));
+ assertEquals("ABCDEF", getUniqueCharacterSubstringBruteForce("AABCDEF"));
+ assertEquals("ABCDEF", getUniqueCharacterSubstringBruteForce("ABCDEFF"));
+ assertEquals("NGISAWE", getUniqueCharacterSubstringBruteForce("CODINGISAWESOME"));
+ assertEquals("be coding", getUniqueCharacterSubstringBruteForce("always be coding"));
+ }
+
+ @Test
+ void givenString_whenGetUniqueCharacterSubstringCalled_thenResultFoundAsExpectedUnitTest() {
+ assertEquals("", getUniqueCharacterSubstring(""));
+ assertEquals("A", getUniqueCharacterSubstring("A"));
+ assertEquals("ABCDEF", getUniqueCharacterSubstring("AABCDEF"));
+ assertEquals("ABCDEF", getUniqueCharacterSubstring("ABCDEFF"));
+ assertEquals("NGISAWE", getUniqueCharacterSubstring("CODINGISAWESOME"));
+ assertEquals("be coding", getUniqueCharacterSubstring("always be coding"));
+ }
+
+}
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/SubstringPalindromeUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/SubstringPalindromeUnitTest.java
new file mode 100644
index 0000000000..8d225f67fa
--- /dev/null
+++ b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/string/SubstringPalindromeUnitTest.java
@@ -0,0 +1,83 @@
+package com.baeldung.algorithms.string;
+
+import static org.junit.Assert.assertEquals;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Test;
+
+public class SubstringPalindromeUnitTest {
+
+ private static final String INPUT_BUBBLE = "bubble";
+ private static final String INPUT_CIVIC = "civic";
+ private static final String INPUT_INDEED = "indeed";
+ private static final String INPUT_ABABAC = "ababac";
+
+ Set EXPECTED_PALINDROME_BUBBLE = new HashSet() {
+ {
+ add("b");
+ add("u");
+ add("l");
+ add("e");
+ add("bb");
+ add("bub");
+ }
+ };
+
+ Set EXPECTED_PALINDROME_CIVIC = new HashSet() {
+ {
+ add("civic");
+ add("ivi");
+ add("i");
+ add("c");
+ add("v");
+ }
+ };
+
+ Set EXPECTED_PALINDROME_INDEED = new HashSet() {
+ {
+ add("i");
+ add("n");
+ add("d");
+ add("e");
+ add("ee");
+ add("deed");
+ }
+ };
+
+ Set EXPECTED_PALINDROME_ABABAC = new HashSet() {
+ {
+ add("a");
+ add("b");
+ add("c");
+ add("aba");
+ add("bab");
+ add("ababa");
+ }
+ };
+
+ private SubstringPalindrome palindrome = new SubstringPalindrome();
+
+ @Test
+ public void whenUsingManachersAlgorithm_thenFindsAllPalindromes() {
+ assertEquals(EXPECTED_PALINDROME_BUBBLE, palindrome.findAllPalindromesUsingManachersAlgorithm(INPUT_BUBBLE));
+ assertEquals(EXPECTED_PALINDROME_INDEED, palindrome.findAllPalindromesUsingManachersAlgorithm(INPUT_INDEED));
+ assertEquals(EXPECTED_PALINDROME_CIVIC, palindrome.findAllPalindromesUsingManachersAlgorithm(INPUT_CIVIC));
+ assertEquals(EXPECTED_PALINDROME_ABABAC, palindrome.findAllPalindromesUsingManachersAlgorithm(INPUT_ABABAC));
+ }
+
+ @Test
+ public void whenUsingCenterApproach_thenFindsAllPalindromes() {
+ assertEquals(EXPECTED_PALINDROME_BUBBLE, palindrome.findAllPalindromesUsingCenter(INPUT_BUBBLE));
+ assertEquals(EXPECTED_PALINDROME_INDEED, palindrome.findAllPalindromesUsingCenter(INPUT_INDEED));
+ assertEquals(EXPECTED_PALINDROME_CIVIC, palindrome.findAllPalindromesUsingCenter(INPUT_CIVIC));
+ assertEquals(EXPECTED_PALINDROME_ABABAC, palindrome.findAllPalindromesUsingCenter(INPUT_ABABAC));
+ }
+
+ @Test
+ public void whenUsingBruteForceApproach_thenFindsAllPalindromes() {
+ assertEquals(EXPECTED_PALINDROME_BUBBLE, palindrome.findAllPalindromesUsingBruteForceApproach(INPUT_BUBBLE));
+ assertEquals(EXPECTED_PALINDROME_INDEED, palindrome.findAllPalindromesUsingBruteForceApproach(INPUT_INDEED));
+ assertEquals(EXPECTED_PALINDROME_CIVIC, palindrome.findAllPalindromesUsingBruteForceApproach(INPUT_CIVIC));
+ assertEquals(EXPECTED_PALINDROME_ABABAC, palindrome.findAllPalindromesUsingBruteForceApproach(INPUT_ABABAC));
+ }
+}
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/support/MayFailRule.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/support/MayFailRule.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/support/MayFailRule.java
rename to algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/support/MayFailRule.java
diff --git a/algorithms-miscellaneous-2/.gitignore b/algorithms-miscellaneous-2/.gitignore
new file mode 100644
index 0000000000..30b2b7442c
--- /dev/null
+++ b/algorithms-miscellaneous-2/.gitignore
@@ -0,0 +1,4 @@
+/target/
+.settings/
+.classpath
+.project
\ No newline at end of file
diff --git a/algorithms/README.md b/algorithms-miscellaneous-2/README.md
similarity index 50%
rename from algorithms/README.md
rename to algorithms-miscellaneous-2/README.md
index b9a37a7bf2..d693a44f66 100644
--- a/algorithms/README.md
+++ b/algorithms-miscellaneous-2/README.md
@@ -2,35 +2,19 @@
- [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra)
- [Introduction to Cobertura](http://www.baeldung.com/cobertura)
-- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
-- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
-- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
-- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
-- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
-- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
- [Test a Linked List for Cyclicity](http://www.baeldung.com/java-linked-list-cyclicity)
-- [Binary Search Algorithm in Java](http://www.baeldung.com/java-binary-search)
-- [Bubble Sort in Java](http://www.baeldung.com/java-bubble-sort)
- [Introduction to JGraphT](http://www.baeldung.com/jgrapht)
-- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
-- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)
-- [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element)
-- [Multi-Swarm Optimization Algorithm in Java](http://www.baeldung.com/java-multi-swarm-algorithm)
- [A Maze Solver in Java](http://www.baeldung.com/java-solve-maze)
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
-- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
- [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation)
- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
-- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
-- [Merge Sort in Java](https://www.baeldung.com/java-merge-sort)
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
-- [Quicksort Algorithm Implementation in Java](https://www.baeldung.com/java-quicksort)
-- [Insertion Sort in Java](https://www.baeldung.com/java-insertion-sort)
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
+- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
diff --git a/algorithms/pom.xml b/algorithms-miscellaneous-2/pom.xml
similarity index 89%
rename from algorithms/pom.xml
rename to algorithms-miscellaneous-2/pom.xml
index db4a1c2eff..5461f4ebe1 100644
--- a/algorithms/pom.xml
+++ b/algorithms-miscellaneous-2/pom.xml
@@ -1,96 +1,96 @@
-
- 4.0.0
- com.baeldung
- algorithms
- 0.0.1-SNAPSHOT
-
-
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.apache.commons
- commons-math3
- ${commons-math3.version}
-
-
- commons-codec
- commons-codec
- ${commons-codec.version}
-
-
- org.projectlombok
- lombok
- ${lombok.version}
- provided
-
-
- io.jenetics
- jenetics
- ${io.jenetics.version}
-
-
- org.jgrapht
- jgrapht-core
- ${org.jgrapht.core.version}
-
-
- pl.allegro.finance
- tradukisto
- ${tradukisto.version}
-
-
- org.assertj
- assertj-core
- ${org.assertj.core.version}
- test
-
-
-
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
-
-
- com/baeldung/algorithms/dijkstra/*
-
-
- com/baeldung/algorithms/dijkstra/*
-
-
-
-
-
-
-
-
- 1.16.12
- 3.6.1
- 1.0.1
- 3.7.0
- 1.0.1
- 3.9.0
- 1.11
-
-
+
+ 4.0.0
+ algorithms-miscellaneous-2
+ 0.0.1-SNAPSHOT
+ algorithms-miscellaneous-2
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.jgrapht
+ jgrapht-core
+ ${org.jgrapht.core.version}
+
+
+ org.jgrapht
+ jgrapht-ext
+ ${org.jgrapht.ext.version}
+
+
+ pl.allegro.finance
+ tradukisto
+ ${tradukisto.version}
+
+
+ org.assertj
+ assertj-core
+ ${org.assertj.core.version}
+ test
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+
+
+ com/baeldung/algorithms/dijkstra/*
+
+
+ com/baeldung/algorithms/dijkstra/*
+
+
+
+
+
+
+
+
+ 1.16.12
+ 3.6.1
+ 1.0.1
+ 1.0.1
+ 1.0.1
+ 3.9.0
+ 1.11
+
+
\ No newline at end of file
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
new file mode 100644
index 0000000000..a1a096bc30
--- /dev/null
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java
@@ -0,0 +1,28 @@
+package com.baeldung.algorithms;
+
+import java.util.Scanner;
+
+import com.baeldung.algorithms.slope_one.SlopeOne;
+
+public class RunAlgorithm {
+
+ public static void main(String[] args) throws InstantiationException, IllegalAccessException {
+ Scanner in = new Scanner(System.in);
+ System.out.println("1 - Slope One");
+ System.out.println("2 - Dijkstra");
+ int decision = in.nextInt();
+ switch (decision) {
+ case 1:
+ SlopeOne.slopeOne(3);
+ break;
+ case 2:
+ System.out.println("Please run the DijkstraAlgorithmLongRunningUnitTest.");
+ break;
+ default:
+ System.out.println("Unknown option");
+ break;
+ }
+ in.close();
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/conversion/HexStringConverter.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/conversion/HexStringConverter.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/conversion/HexStringConverter.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/conversion/HexStringConverter.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java
similarity index 95%
rename from algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java
index ec66621928..4df1de9994 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java
@@ -1,15 +1,15 @@
-package com.baeldung.algorithms.editdistance;
-
-import java.util.Arrays;
-
-public class EditDistanceBase {
-
- static int costOfSubstitution(char a, char b) {
- return a == b ? 0 : 1;
- }
-
- static int min(int... numbers) {
- return Arrays.stream(numbers)
- .min().orElse(Integer.MAX_VALUE);
- }
-}
+package com.baeldung.algorithms.editdistance;
+
+import java.util.Arrays;
+
+public class EditDistanceBase {
+
+ static int costOfSubstitution(char a, char b) {
+ return a == b ? 0 : 1;
+ }
+
+ static int min(int... numbers) {
+ return Arrays.stream(numbers)
+ .min().orElse(Integer.MAX_VALUE);
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java
index 1f8824c4f4..10ce43bf5f 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java
@@ -1,26 +1,26 @@
-package com.baeldung.algorithms.editdistance;
-
-public class EditDistanceDynamicProgramming extends EditDistanceBase {
-
- static int calculate(String x, String y) {
- int[][] dp = new int[x.length() + 1][y.length() + 1];
-
- for (int i = 0; i <= x.length(); i++) {
- for (int j = 0; j <= y.length(); j++) {
- if (i == 0)
- dp[i][j] = j;
-
- else if (j == 0)
- dp[i][j] = i;
-
- else {
- dp[i][j] = min(dp[i - 1][j - 1]
- + costOfSubstitution(x.charAt(i - 1), y.charAt(j - 1)),
- dp[i - 1][j] + 1, dp[i][j - 1] + 1);
- }
- }
- }
-
- return dp[x.length()][y.length()];
- }
-}
+package com.baeldung.algorithms.editdistance;
+
+public class EditDistanceDynamicProgramming extends EditDistanceBase {
+
+ static int calculate(String x, String y) {
+ int[][] dp = new int[x.length() + 1][y.length() + 1];
+
+ for (int i = 0; i <= x.length(); i++) {
+ for (int j = 0; j <= y.length(); j++) {
+ if (i == 0)
+ dp[i][j] = j;
+
+ else if (j == 0)
+ dp[i][j] = i;
+
+ else {
+ dp[i][j] = min(dp[i - 1][j - 1]
+ + costOfSubstitution(x.charAt(i - 1), y.charAt(j - 1)),
+ dp[i - 1][j] + 1, dp[i][j - 1] + 1);
+ }
+ }
+ }
+
+ return dp[x.length()][y.length()];
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java
index 8ed48dc554..fc907c45f8 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java
@@ -1,21 +1,21 @@
-package com.baeldung.algorithms.editdistance;
-
-public class EditDistanceRecursive extends EditDistanceBase {
-
- static int calculate(String x, String y) {
-
- if (x.isEmpty()) {
- return y.length();
- }
-
- if (y.isEmpty()) {
- return x.length();
- }
-
- int substitution = calculate(x.substring(1), y.substring(1)) + costOfSubstitution(x.charAt(0), y.charAt(0));
- int insertion = calculate(x, y.substring(1)) + 1;
- int deletion = calculate(x.substring(1), y) + 1;
-
- return min(substitution, insertion, deletion);
- }
-}
+package com.baeldung.algorithms.editdistance;
+
+public class EditDistanceRecursive extends EditDistanceBase {
+
+ static int calculate(String x, String y) {
+
+ if (x.isEmpty()) {
+ return y.length();
+ }
+
+ if (y.isEmpty()) {
+ return x.length();
+ }
+
+ int substitution = calculate(x.substring(1), y.substring(1)) + costOfSubstitution(x.charAt(0), y.charAt(0));
+ int insertion = calculate(x, y.substring(1)) + 1;
+ int deletion = calculate(x.substring(1), y) + 1;
+
+ return min(substitution, insertion, deletion);
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java
index 1df425ad2e..907bd9042d 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionBruteForce.java
@@ -1,38 +1,38 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleDetectionBruteForce {
-
- public static CycleDetectionResult detectCycle(Node head) {
- if (head == null) {
- return new CycleDetectionResult<>(false, null);
- }
-
- Node it1 = head;
- int nodesTraversedByOuter = 0;
- while (it1 != null && it1.next != null) {
- it1 = it1.next;
- nodesTraversedByOuter++;
-
- int x = nodesTraversedByOuter;
- Node it2 = head;
- int noOfTimesCurrentNodeVisited = 0;
-
- while (x > 0) {
- it2 = it2.next;
-
- if (it2 == it1) {
- noOfTimesCurrentNodeVisited++;
- }
-
- if (noOfTimesCurrentNodeVisited == 2) {
- return new CycleDetectionResult<>(true, it1);
- }
-
- x--;
- }
- }
-
- return new CycleDetectionResult<>(false, null);
- }
-
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleDetectionBruteForce {
+
+ public static CycleDetectionResult detectCycle(Node head) {
+ if (head == null) {
+ return new CycleDetectionResult<>(false, null);
+ }
+
+ Node it1 = head;
+ int nodesTraversedByOuter = 0;
+ while (it1 != null && it1.next != null) {
+ it1 = it1.next;
+ nodesTraversedByOuter++;
+
+ int x = nodesTraversedByOuter;
+ Node it2 = head;
+ int noOfTimesCurrentNodeVisited = 0;
+
+ while (x > 0) {
+ it2 = it2.next;
+
+ if (it2 == it1) {
+ noOfTimesCurrentNodeVisited++;
+ }
+
+ if (noOfTimesCurrentNodeVisited == 2) {
+ return new CycleDetectionResult<>(true, it1);
+ }
+
+ x--;
+ }
+ }
+
+ return new CycleDetectionResult<>(false, null);
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java
index ab088de44a..2817f6f783 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByFastAndSlowIterators.java
@@ -1,25 +1,25 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleDetectionByFastAndSlowIterators {
-
- public static CycleDetectionResult detectCycle(Node head) {
- if (head == null) {
- return new CycleDetectionResult<>(false, null);
- }
-
- Node slow = head;
- Node fast = head;
-
- while (fast != null && fast.next != null) {
- slow = slow.next;
- fast = fast.next.next;
-
- if (slow == fast) {
- return new CycleDetectionResult<>(true, fast);
- }
- }
-
- return new CycleDetectionResult<>(false, null);
- }
-
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleDetectionByFastAndSlowIterators {
+
+ public static CycleDetectionResult detectCycle(Node head) {
+ if (head == null) {
+ return new CycleDetectionResult<>(false, null);
+ }
+
+ Node slow = head;
+ Node fast = head;
+
+ while (fast != null && fast.next != null) {
+ slow = slow.next;
+ fast = fast.next.next;
+
+ if (slow == fast) {
+ return new CycleDetectionResult<>(true, fast);
+ }
+ }
+
+ return new CycleDetectionResult<>(false, null);
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java
index 90d5ecd711..fba4cad2e6 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionByHashing.java
@@ -1,27 +1,27 @@
-package com.baeldung.algorithms.linkedlist;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class CycleDetectionByHashing {
-
- public static CycleDetectionResult detectCycle(Node head) {
- if (head == null) {
- return new CycleDetectionResult<>(false, null);
- }
-
- Set> set = new HashSet<>();
- Node node = head;
-
- while (node != null) {
- if (set.contains(node)) {
- return new CycleDetectionResult<>(true, node);
- }
- set.add(node);
- node = node.next;
- }
-
- return new CycleDetectionResult<>(false, null);
- }
-
-}
+package com.baeldung.algorithms.linkedlist;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class CycleDetectionByHashing {
+
+ public static CycleDetectionResult detectCycle(Node head) {
+ if (head == null) {
+ return new CycleDetectionResult<>(false, null);
+ }
+
+ Set> set = new HashSet<>();
+ Node node = head;
+
+ while (node != null) {
+ if (set.contains(node)) {
+ return new CycleDetectionResult<>(true, node);
+ }
+ set.add(node);
+ node = node.next;
+ }
+
+ return new CycleDetectionResult<>(false, null);
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java
index e7556311b3..4e258ec2ef 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleDetectionResult.java
@@ -1,12 +1,12 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleDetectionResult {
- boolean cycleExists;
- Node node;
-
- public CycleDetectionResult(boolean cycleExists, Node node) {
- super();
- this.cycleExists = cycleExists;
- this.node = node;
- }
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleDetectionResult {
+ boolean cycleExists;
+ Node node;
+
+ public CycleDetectionResult(boolean cycleExists, Node node) {
+ super();
+ this.cycleExists = cycleExists;
+ this.node = node;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java
index a2bfaee9a1..216ebcdde3 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalBruteForce.java
@@ -1,56 +1,56 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleRemovalBruteForce {
-
- public static boolean detectAndRemoveCycle(Node head) {
- CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
-
- if (result.cycleExists) {
- removeCycle(result.node, head);
- }
-
- return result.cycleExists;
- }
-
- /**
- * @param loopNodeParam - reference to the node where Flyods cycle
- * finding algorithm ends, i.e. the fast and the slow iterators
- * meet.
- * @param head - reference to the head of the list
- */
- private static void removeCycle(Node loopNodeParam, Node head) {
- Node it = head;
-
- while (it != null) {
- if (isNodeReachableFromLoopNode(it, loopNodeParam)) {
- Node loopStart = it;
- findEndNodeAndBreakCycle(loopStart);
- break;
- }
- it = it.next;
- }
- }
-
- private static boolean isNodeReachableFromLoopNode(Node it, Node loopNodeParam) {
- Node loopNode = loopNodeParam;
-
- do {
- if (it == loopNode) {
- return true;
- }
- loopNode = loopNode.next;
- } while (loopNode.next != loopNodeParam);
-
- return false;
- }
-
- private static void findEndNodeAndBreakCycle(Node loopStartParam) {
- Node loopStart = loopStartParam;
-
- while (loopStart.next != loopStartParam) {
- loopStart = loopStart.next;
- }
-
- loopStart.next = null;
- }
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleRemovalBruteForce {
+
+ public static boolean detectAndRemoveCycle(Node head) {
+ CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
+
+ if (result.cycleExists) {
+ removeCycle(result.node, head);
+ }
+
+ return result.cycleExists;
+ }
+
+ /**
+ * @param loopNodeParam - reference to the node where Flyods cycle
+ * finding algorithm ends, i.e. the fast and the slow iterators
+ * meet.
+ * @param head - reference to the head of the list
+ */
+ private static void removeCycle(Node loopNodeParam, Node head) {
+ Node it = head;
+
+ while (it != null) {
+ if (isNodeReachableFromLoopNode(it, loopNodeParam)) {
+ Node loopStart = it;
+ findEndNodeAndBreakCycle(loopStart);
+ break;
+ }
+ it = it.next;
+ }
+ }
+
+ private static boolean isNodeReachableFromLoopNode(Node it, Node loopNodeParam) {
+ Node loopNode = loopNodeParam;
+
+ do {
+ if (it == loopNode) {
+ return true;
+ }
+ loopNode = loopNode.next;
+ } while (loopNode.next != loopNodeParam);
+
+ return false;
+ }
+
+ private static void findEndNodeAndBreakCycle(Node loopStartParam) {
+ Node loopStart = loopStartParam;
+
+ while (loopStart.next != loopStartParam) {
+ loopStart = loopStart.next;
+ }
+
+ loopStart.next = null;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java
index d8db37fc4c..f961feb97d 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalByCountingLoopNodes.java
@@ -1,44 +1,44 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleRemovalByCountingLoopNodes {
-
- public static boolean detectAndRemoveCycle(Node head) {
- CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
-
- if (result.cycleExists) {
- removeCycle(result.node, head);
- }
-
- return result.cycleExists;
- }
-
- private static void removeCycle(Node loopNodeParam, Node head) {
- int cycleLength = calculateCycleLength(loopNodeParam);
- Node cycleLengthAdvancedIterator = head;
- Node it = head;
-
- for (int i = 0; i < cycleLength; i++) {
- cycleLengthAdvancedIterator = cycleLengthAdvancedIterator.next;
- }
-
- while (it.next != cycleLengthAdvancedIterator.next) {
- it = it.next;
- cycleLengthAdvancedIterator = cycleLengthAdvancedIterator.next;
- }
-
- cycleLengthAdvancedIterator.next = null;
- }
-
- private static int calculateCycleLength(Node loopNodeParam) {
- Node loopNode = loopNodeParam;
- int length = 1;
-
- while (loopNode.next != loopNodeParam) {
- length++;
- loopNode = loopNode.next;
- }
-
- return length;
- }
-
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleRemovalByCountingLoopNodes {
+
+ public static boolean detectAndRemoveCycle(Node head) {
+ CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
+
+ if (result.cycleExists) {
+ removeCycle(result.node, head);
+ }
+
+ return result.cycleExists;
+ }
+
+ private static void removeCycle(Node loopNodeParam, Node head) {
+ int cycleLength = calculateCycleLength(loopNodeParam);
+ Node cycleLengthAdvancedIterator = head;
+ Node it = head;
+
+ for (int i = 0; i < cycleLength; i++) {
+ cycleLengthAdvancedIterator = cycleLengthAdvancedIterator.next;
+ }
+
+ while (it.next != cycleLengthAdvancedIterator.next) {
+ it = it.next;
+ cycleLengthAdvancedIterator = cycleLengthAdvancedIterator.next;
+ }
+
+ cycleLengthAdvancedIterator.next = null;
+ }
+
+ private static int calculateCycleLength(Node loopNodeParam) {
+ Node loopNode = loopNodeParam;
+ int length = 1;
+
+ while (loopNode.next != loopNodeParam) {
+ length++;
+ loopNode = loopNode.next;
+ }
+
+ return length;
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java
index b979f7f677..1e41c832db 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/CycleRemovalWithoutCountingLoopNodes.java
@@ -1,27 +1,27 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class CycleRemovalWithoutCountingLoopNodes {
-
- public static boolean detectAndRemoveCycle(Node head) {
- CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
-
- if (result.cycleExists) {
- removeCycle(result.node, head);
- }
-
- return result.cycleExists;
- }
-
- private static void removeCycle(Node meetingPointParam, Node head) {
- Node loopNode = meetingPointParam;
- Node it = head;
-
- while (loopNode.next != it.next) {
- it = it.next;
- loopNode = loopNode.next;
- }
-
- loopNode.next = null;
- }
-
-}
+package com.baeldung.algorithms.linkedlist;
+
+public class CycleRemovalWithoutCountingLoopNodes {
+
+ public static boolean detectAndRemoveCycle(Node head) {
+ CycleDetectionResult result = CycleDetectionByFastAndSlowIterators.detectCycle(head);
+
+ if (result.cycleExists) {
+ removeCycle(result.node, head);
+ }
+
+ return result.cycleExists;
+ }
+
+ private static void removeCycle(Node meetingPointParam, Node head) {
+ Node loopNode = meetingPointParam;
+ Node it = head;
+
+ while (loopNode.next != it.next) {
+ it = it.next;
+ loopNode = loopNode.next;
+ }
+
+ loopNode.next = null;
+ }
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/Node.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/Node.java
similarity index 95%
rename from algorithms/src/main/java/com/baeldung/algorithms/linkedlist/Node.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/Node.java
index 4add22c77d..9573bcd981 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/linkedlist/Node.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/linkedlist/Node.java
@@ -1,38 +1,38 @@
-package com.baeldung.algorithms.linkedlist;
-
-public class Node {
- T data;
- Node next;
-
- public static Node createNewNode(T data, Node next) {
- Node node = new Node();
- node.data = data;
- node.next = next;
- return node;
- }
-
- public static void traverseList(Node root) {
- if (root == null) {
- return;
- }
-
- Node node = root;
- while (node != null) {
- System.out.println(node.data);
- node = node.next;
- }
- }
-
- public static Node getTail(Node root) {
- if (root == null) {
- return null;
- }
-
- Node node = root;
- while (node.next != null) {
- node = node.next;
- }
- return node;
- }
-
+package com.baeldung.algorithms.linkedlist;
+
+public class Node {
+ T data;
+ Node next;
+
+ public static Node createNewNode(T data, Node next) {
+ Node node = new Node();
+ node.data = data;
+ node.next = next;
+ return node;
+ }
+
+ public static void traverseList(Node root) {
+ if (root == null) {
+ return;
+ }
+
+ Node node = root;
+ while (node != null) {
+ System.out.println(node.data);
+ node = node.next;
+ }
+ }
+
+ public static Node getTail(Node root) {
+ if (root == null) {
+ return null;
+ }
+
+ Node node = root;
+ while (node.next != null) {
+ node = node.next;
+ }
+ return node;
+ }
+
}
\ No newline at end of file
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java
index 08972251b8..0e3101925c 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/BFSMazeSolver.java
@@ -1,52 +1,52 @@
-package com.baeldung.algorithms.maze.solver;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-public class BFSMazeSolver {
- private static final int[][] DIRECTIONS = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
-
- public List solve(Maze maze) {
- LinkedList nextToVisit = new LinkedList<>();
- Coordinate start = maze.getEntry();
- nextToVisit.add(start);
-
- while (!nextToVisit.isEmpty()) {
- Coordinate cur = nextToVisit.remove();
-
- if (!maze.isValidLocation(cur.getX(), cur.getY()) || maze.isExplored(cur.getX(), cur.getY())) {
- continue;
- }
-
- if (maze.isWall(cur.getX(), cur.getY())) {
- maze.setVisited(cur.getX(), cur.getY(), true);
- continue;
- }
-
- if (maze.isExit(cur.getX(), cur.getY())) {
- return backtrackPath(cur);
- }
-
- for (int[] direction : DIRECTIONS) {
- Coordinate coordinate = new Coordinate(cur.getX() + direction[0], cur.getY() + direction[1], cur);
- nextToVisit.add(coordinate);
- maze.setVisited(cur.getX(), cur.getY(), true);
- }
- }
- return Collections.emptyList();
- }
-
- private List backtrackPath(Coordinate cur) {
- List path = new ArrayList<>();
- Coordinate iter = cur;
-
- while (iter != null) {
- path.add(iter);
- iter = iter.parent;
- }
-
- return path;
- }
-}
+package com.baeldung.algorithms.maze.solver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+public class BFSMazeSolver {
+ private static final int[][] DIRECTIONS = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
+
+ public List solve(Maze maze) {
+ LinkedList nextToVisit = new LinkedList<>();
+ Coordinate start = maze.getEntry();
+ nextToVisit.add(start);
+
+ while (!nextToVisit.isEmpty()) {
+ Coordinate cur = nextToVisit.remove();
+
+ if (!maze.isValidLocation(cur.getX(), cur.getY()) || maze.isExplored(cur.getX(), cur.getY())) {
+ continue;
+ }
+
+ if (maze.isWall(cur.getX(), cur.getY())) {
+ maze.setVisited(cur.getX(), cur.getY(), true);
+ continue;
+ }
+
+ if (maze.isExit(cur.getX(), cur.getY())) {
+ return backtrackPath(cur);
+ }
+
+ for (int[] direction : DIRECTIONS) {
+ Coordinate coordinate = new Coordinate(cur.getX() + direction[0], cur.getY() + direction[1], cur);
+ nextToVisit.add(coordinate);
+ maze.setVisited(cur.getX(), cur.getY(), true);
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ private List backtrackPath(Coordinate cur) {
+ List path = new ArrayList<>();
+ Coordinate iter = cur;
+
+ while (iter != null) {
+ path.add(iter);
+ iter = iter.parent;
+ }
+
+ return path;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java
similarity index 94%
rename from algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java
index 09b2ced5e6..8202c89076 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Coordinate.java
@@ -1,31 +1,31 @@
-package com.baeldung.algorithms.maze.solver;
-
-public class Coordinate {
- int x;
- int y;
- Coordinate parent;
-
- public Coordinate(int x, int y) {
- this.x = x;
- this.y = y;
- this.parent = null;
- }
-
- public Coordinate(int x, int y, Coordinate parent) {
- this.x = x;
- this.y = y;
- this.parent = parent;
- }
-
- int getX() {
- return x;
- }
-
- int getY() {
- return y;
- }
-
- Coordinate getParent() {
- return parent;
- }
-}
+package com.baeldung.algorithms.maze.solver;
+
+public class Coordinate {
+ int x;
+ int y;
+ Coordinate parent;
+
+ public Coordinate(int x, int y) {
+ this.x = x;
+ this.y = y;
+ this.parent = null;
+ }
+
+ public Coordinate(int x, int y, Coordinate parent) {
+ this.x = x;
+ this.y = y;
+ this.parent = parent;
+ }
+
+ int getX() {
+ return x;
+ }
+
+ int getY() {
+ return y;
+ }
+
+ Coordinate getParent() {
+ return parent;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java
index f9640066b9..ee821631db 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/DFSMazeSolver.java
@@ -1,48 +1,48 @@
-package com.baeldung.algorithms.maze.solver;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class DFSMazeSolver {
- private static final int[][] DIRECTIONS = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
-
- public List solve(Maze maze) {
- List path = new ArrayList<>();
- if (explore(maze, maze.getEntry()
- .getX(),
- maze.getEntry()
- .getY(),
- path)) {
- return path;
- }
- return Collections.emptyList();
- }
-
- private boolean explore(Maze maze, int row, int col, List path) {
- if (!maze.isValidLocation(row, col) || maze.isWall(row, col) || maze.isExplored(row, col)) {
- return false;
- }
-
- path.add(new Coordinate(row, col));
- maze.setVisited(row, col, true);
-
- if (maze.isExit(row, col)) {
- return true;
- }
-
- for (int[] direction : DIRECTIONS) {
- Coordinate coordinate = getNextCoordinate(row, col, direction[0], direction[1]);
- if (explore(maze, coordinate.getX(), coordinate.getY(), path)) {
- return true;
- }
- }
-
- path.remove(path.size() - 1);
- return false;
- }
-
- private Coordinate getNextCoordinate(int row, int col, int i, int j) {
- return new Coordinate(row + i, col + j);
- }
-}
+package com.baeldung.algorithms.maze.solver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class DFSMazeSolver {
+ private static final int[][] DIRECTIONS = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
+
+ public List solve(Maze maze) {
+ List path = new ArrayList<>();
+ if (explore(maze, maze.getEntry()
+ .getX(),
+ maze.getEntry()
+ .getY(),
+ path)) {
+ return path;
+ }
+ return Collections.emptyList();
+ }
+
+ private boolean explore(Maze maze, int row, int col, List path) {
+ if (!maze.isValidLocation(row, col) || maze.isWall(row, col) || maze.isExplored(row, col)) {
+ return false;
+ }
+
+ path.add(new Coordinate(row, col));
+ maze.setVisited(row, col, true);
+
+ if (maze.isExit(row, col)) {
+ return true;
+ }
+
+ for (int[] direction : DIRECTIONS) {
+ Coordinate coordinate = getNextCoordinate(row, col, direction[0], direction[1]);
+ if (explore(maze, coordinate.getX(), coordinate.getY(), path)) {
+ return true;
+ }
+ }
+
+ path.remove(path.size() - 1);
+ return false;
+ }
+
+ private Coordinate getNextCoordinate(int row, int col, int i, int j) {
+ return new Coordinate(row + i, col + j);
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java
index 8aaa44d9b1..d0a0ed65d9 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/Maze.java
@@ -1,141 +1,141 @@
-package com.baeldung.algorithms.maze.solver;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Scanner;
-
-public class Maze {
- private static final int ROAD = 0;
- private static final int WALL = 1;
- private static final int START = 2;
- private static final int EXIT = 3;
- private static final int PATH = 4;
-
- private int[][] maze;
- private boolean[][] visited;
- private Coordinate start;
- private Coordinate end;
-
- public Maze(File maze) throws FileNotFoundException {
- String fileText = "";
- try (Scanner input = new Scanner(maze)) {
- while (input.hasNextLine()) {
- fileText += input.nextLine() + "\n";
- }
- }
- initializeMaze(fileText);
- }
-
- private void initializeMaze(String text) {
- if (text == null || (text = text.trim()).length() == 0) {
- throw new IllegalArgumentException("empty lines data");
- }
-
- String[] lines = text.split("[\r]?\n");
- maze = new int[lines.length][lines[0].length()];
- visited = new boolean[lines.length][lines[0].length()];
-
- for (int row = 0; row < getHeight(); row++) {
- if (lines[row].length() != getWidth()) {
- throw new IllegalArgumentException("line " + (row + 1) + " wrong length (was " + lines[row].length() + " but should be " + getWidth() + ")");
- }
-
- for (int col = 0; col < getWidth(); col++) {
- if (lines[row].charAt(col) == '#')
- maze[row][col] = WALL;
- else if (lines[row].charAt(col) == 'S') {
- maze[row][col] = START;
- start = new Coordinate(row, col);
- } else if (lines[row].charAt(col) == 'E') {
- maze[row][col] = EXIT;
- end = new Coordinate(row, col);
- } else
- maze[row][col] = ROAD;
- }
- }
- }
-
- public int getHeight() {
- return maze.length;
- }
-
- public int getWidth() {
- return maze[0].length;
- }
-
- public Coordinate getEntry() {
- return start;
- }
-
- public Coordinate getExit() {
- return end;
- }
-
- public boolean isExit(int x, int y) {
- return x == end.getX() && y == end.getY();
- }
-
- public boolean isStart(int x, int y) {
- return x == start.getX() && y == start.getY();
- }
-
- public boolean isExplored(int row, int col) {
- return visited[row][col];
- }
-
- public boolean isWall(int row, int col) {
- return maze[row][col] == WALL;
- }
-
- public void setVisited(int row, int col, boolean value) {
- visited[row][col] = value;
- }
-
- public boolean isValidLocation(int row, int col) {
- if (row < 0 || row >= getHeight() || col < 0 || col >= getWidth()) {
- return false;
- }
- return true;
- }
-
- public void printPath(List path) {
- int[][] tempMaze = Arrays.stream(maze)
- .map(int[]::clone)
- .toArray(int[][]::new);
- for (Coordinate coordinate : path) {
- if (isStart(coordinate.getX(), coordinate.getY()) || isExit(coordinate.getX(), coordinate.getY())) {
- continue;
- }
- tempMaze[coordinate.getX()][coordinate.getY()] = PATH;
- }
- System.out.println(toString(tempMaze));
- }
-
- public String toString(int[][] maze) {
- StringBuilder result = new StringBuilder(getWidth() * (getHeight() + 1));
- for (int row = 0; row < getHeight(); row++) {
- for (int col = 0; col < getWidth(); col++) {
- if (maze[row][col] == ROAD) {
- result.append(' ');
- } else if (maze[row][col] == WALL) {
- result.append('#');
- } else if (maze[row][col] == START) {
- result.append('S');
- } else if (maze[row][col] == EXIT) {
- result.append('E');
- } else {
- result.append('.');
- }
- }
- result.append('\n');
- }
- return result.toString();
- }
-
- public void reset() {
- for (int i = 0; i < visited.length; i++)
- Arrays.fill(visited[i], false);
- }
-}
+package com.baeldung.algorithms.maze.solver;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+
+public class Maze {
+ private static final int ROAD = 0;
+ private static final int WALL = 1;
+ private static final int START = 2;
+ private static final int EXIT = 3;
+ private static final int PATH = 4;
+
+ private int[][] maze;
+ private boolean[][] visited;
+ private Coordinate start;
+ private Coordinate end;
+
+ public Maze(File maze) throws FileNotFoundException {
+ String fileText = "";
+ try (Scanner input = new Scanner(maze)) {
+ while (input.hasNextLine()) {
+ fileText += input.nextLine() + "\n";
+ }
+ }
+ initializeMaze(fileText);
+ }
+
+ private void initializeMaze(String text) {
+ if (text == null || (text = text.trim()).length() == 0) {
+ throw new IllegalArgumentException("empty lines data");
+ }
+
+ String[] lines = text.split("[\r]?\n");
+ maze = new int[lines.length][lines[0].length()];
+ visited = new boolean[lines.length][lines[0].length()];
+
+ for (int row = 0; row < getHeight(); row++) {
+ if (lines[row].length() != getWidth()) {
+ throw new IllegalArgumentException("line " + (row + 1) + " wrong length (was " + lines[row].length() + " but should be " + getWidth() + ")");
+ }
+
+ for (int col = 0; col < getWidth(); col++) {
+ if (lines[row].charAt(col) == '#')
+ maze[row][col] = WALL;
+ else if (lines[row].charAt(col) == 'S') {
+ maze[row][col] = START;
+ start = new Coordinate(row, col);
+ } else if (lines[row].charAt(col) == 'E') {
+ maze[row][col] = EXIT;
+ end = new Coordinate(row, col);
+ } else
+ maze[row][col] = ROAD;
+ }
+ }
+ }
+
+ public int getHeight() {
+ return maze.length;
+ }
+
+ public int getWidth() {
+ return maze[0].length;
+ }
+
+ public Coordinate getEntry() {
+ return start;
+ }
+
+ public Coordinate getExit() {
+ return end;
+ }
+
+ public boolean isExit(int x, int y) {
+ return x == end.getX() && y == end.getY();
+ }
+
+ public boolean isStart(int x, int y) {
+ return x == start.getX() && y == start.getY();
+ }
+
+ public boolean isExplored(int row, int col) {
+ return visited[row][col];
+ }
+
+ public boolean isWall(int row, int col) {
+ return maze[row][col] == WALL;
+ }
+
+ public void setVisited(int row, int col, boolean value) {
+ visited[row][col] = value;
+ }
+
+ public boolean isValidLocation(int row, int col) {
+ if (row < 0 || row >= getHeight() || col < 0 || col >= getWidth()) {
+ return false;
+ }
+ return true;
+ }
+
+ public void printPath(List path) {
+ int[][] tempMaze = Arrays.stream(maze)
+ .map(int[]::clone)
+ .toArray(int[][]::new);
+ for (Coordinate coordinate : path) {
+ if (isStart(coordinate.getX(), coordinate.getY()) || isExit(coordinate.getX(), coordinate.getY())) {
+ continue;
+ }
+ tempMaze[coordinate.getX()][coordinate.getY()] = PATH;
+ }
+ System.out.println(toString(tempMaze));
+ }
+
+ public String toString(int[][] maze) {
+ StringBuilder result = new StringBuilder(getWidth() * (getHeight() + 1));
+ for (int row = 0; row < getHeight(); row++) {
+ for (int col = 0; col < getWidth(); col++) {
+ if (maze[row][col] == ROAD) {
+ result.append(' ');
+ } else if (maze[row][col] == WALL) {
+ result.append('#');
+ } else if (maze[row][col] == START) {
+ result.append('S');
+ } else if (maze[row][col] == EXIT) {
+ result.append('E');
+ } else {
+ result.append('.');
+ }
+ }
+ result.append('\n');
+ }
+ return result.toString();
+ }
+
+ public void reset() {
+ for (int i = 0; i < visited.length; i++)
+ Arrays.fill(visited[i], false);
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java
index 60263deba3..a47c3c8581 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/maze/solver/MazeDriver.java
@@ -1,34 +1,34 @@
-package com.baeldung.algorithms.maze.solver;
-
-import java.io.File;
-import java.util.List;
-
-public class MazeDriver {
- public static void main(String[] args) throws Exception {
- File maze1 = new File("src/main/resources/maze/maze1.txt");
- File maze2 = new File("src/main/resources/maze/maze2.txt");
-
- execute(maze1);
- execute(maze2);
- }
-
- private static void execute(File file) throws Exception {
- Maze maze = new Maze(file);
- dfs(maze);
- bfs(maze);
- }
-
- private static void bfs(Maze maze) {
- BFSMazeSolver bfs = new BFSMazeSolver();
- List path = bfs.solve(maze);
- maze.printPath(path);
- maze.reset();
- }
-
- private static void dfs(Maze maze) {
- DFSMazeSolver dfs = new DFSMazeSolver();
- List path = dfs.solve(maze);
- maze.printPath(path);
- maze.reset();
- }
-}
+package com.baeldung.algorithms.maze.solver;
+
+import java.io.File;
+import java.util.List;
+
+public class MazeDriver {
+ public static void main(String[] args) throws Exception {
+ File maze1 = new File("src/main/resources/maze/maze1.txt");
+ File maze2 = new File("src/main/resources/maze/maze2.txt");
+
+ execute(maze1);
+ execute(maze2);
+ }
+
+ private static void execute(File file) throws Exception {
+ Maze maze = new Maze(file);
+ dfs(maze);
+ bfs(maze);
+ }
+
+ private static void bfs(Maze maze) {
+ BFSMazeSolver bfs = new BFSMazeSolver();
+ List path = bfs.solve(maze);
+ maze.printPath(path);
+ maze.reset();
+ }
+
+ private static void dfs(Maze maze) {
+ DFSMazeSolver dfs = new DFSMazeSolver();
+ List path = dfs.solve(maze);
+ maze.printPath(path);
+ maze.reset();
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
new file mode 100644
index 0000000000..e1c41f9518
--- /dev/null
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
@@ -0,0 +1,22 @@
+package com.baeldung.algorithms.mercator;
+
+class EllipticalMercator extends Mercator {
+
+ @Override
+ double yAxisProjection(double input) {
+
+ input = Math.min(Math.max(input, -89.5), 89.5);
+ double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2);
+
+ double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input));
+
+ inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized));
+ double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj;
+ return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized);
+ }
+
+ @Override
+ double xAxisProjection(double input) {
+ return RADIUS_MAJOR * Math.toRadians(input);
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
new file mode 100644
index 0000000000..b289b1839d
--- /dev/null
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
@@ -0,0 +1,10 @@
+package com.baeldung.algorithms.mercator;
+
+abstract class Mercator {
+ final static double RADIUS_MAJOR = 6378137.0;
+ final static double RADIUS_MINOR = 6356752.3142;
+
+ abstract double yAxisProjection(double input);
+
+ abstract double xAxisProjection(double input);
+}
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
new file mode 100644
index 0000000000..1be976d82e
--- /dev/null
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
@@ -0,0 +1,14 @@
+package com.baeldung.algorithms.mercator;
+
+public class SphericalMercator extends Mercator {
+
+ @Override
+ double xAxisProjection(double input) {
+ return Math.toRadians(input) * RADIUS_MAJOR;
+ }
+
+ @Override
+ double yAxisProjection(double input) {
+ return Math.log(Math.tan(Math.PI / 4 + Math.toRadians(input) / 2)) * RADIUS_MAJOR;
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/numberwordconverter/NumberWordConverter.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java
index ab0922ecf4..acd275e609 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanArabicConverter.java
@@ -1,52 +1,52 @@
-package com.baeldung.algorithms.romannumerals;
-
-import java.util.List;
-
-class RomanArabicConverter {
-
- public static int romanToArabic(String input) {
- String romanNumeral = input.toUpperCase();
- int result = 0;
-
- List romanNumerals = RomanNumeral.getReverseSortedValues();
-
- int i = 0;
-
- while ((romanNumeral.length() > 0) && (i < romanNumerals.size())) {
- RomanNumeral symbol = romanNumerals.get(i);
- if (romanNumeral.startsWith(symbol.name())) {
- result += symbol.getValue();
- romanNumeral = romanNumeral.substring(symbol.name().length());
- } else {
- i++;
- }
- }
- if (romanNumeral.length() > 0) {
- throw new IllegalArgumentException(input + " cannot be converted to a Roman Numeral");
- }
-
- return result;
- }
-
- public static String arabicToRoman(int number) {
- if ((number <= 0) || (number > 4000)) {
- throw new IllegalArgumentException(number + " is not in range (0,4000]");
- }
-
- List romanNumerals = RomanNumeral.getReverseSortedValues();
-
- int i = 0;
- StringBuilder sb = new StringBuilder();
-
- while (number > 0 && i < romanNumerals.size()) {
- RomanNumeral currentSymbol = romanNumerals.get(i);
- if (currentSymbol.getValue() <= number) {
- sb.append(currentSymbol.name());
- number -= currentSymbol.getValue();
- } else {
- i++;
- }
- }
- return sb.toString();
- }
-}
+package com.baeldung.algorithms.romannumerals;
+
+import java.util.List;
+
+class RomanArabicConverter {
+
+ public static int romanToArabic(String input) {
+ String romanNumeral = input.toUpperCase();
+ int result = 0;
+
+ List romanNumerals = RomanNumeral.getReverseSortedValues();
+
+ int i = 0;
+
+ while ((romanNumeral.length() > 0) && (i < romanNumerals.size())) {
+ RomanNumeral symbol = romanNumerals.get(i);
+ if (romanNumeral.startsWith(symbol.name())) {
+ result += symbol.getValue();
+ romanNumeral = romanNumeral.substring(symbol.name().length());
+ } else {
+ i++;
+ }
+ }
+ if (romanNumeral.length() > 0) {
+ throw new IllegalArgumentException(input + " cannot be converted to a Roman Numeral");
+ }
+
+ return result;
+ }
+
+ public static String arabicToRoman(int number) {
+ if ((number <= 0) || (number > 4000)) {
+ throw new IllegalArgumentException(number + " is not in range (0,4000]");
+ }
+
+ List romanNumerals = RomanNumeral.getReverseSortedValues();
+
+ int i = 0;
+ StringBuilder sb = new StringBuilder();
+
+ while (number > 0 && i < romanNumerals.size()) {
+ RomanNumeral currentSymbol = romanNumerals.get(i);
+ if (currentSymbol.getValue() <= number) {
+ sb.append(currentSymbol.name());
+ number -= currentSymbol.getValue();
+ } else {
+ i++;
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java
similarity index 96%
rename from algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java
index 219f0b5090..2ee5bb6d75 100644
--- a/algorithms/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/romannumerals/RomanNumeral.java
@@ -1,26 +1,26 @@
-package com.baeldung.algorithms.romannumerals;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-enum RomanNumeral {
- I(1), IV(4), V(5), IX(9), X(10), XL(40), L(50), XC(90), C(100), CD(400), D(500), CM(900), M(1000);
-
- private int value;
-
- RomanNumeral(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static List getReverseSortedValues() {
- return Arrays.stream(values())
- .sorted(Comparator.comparing((RomanNumeral e) -> e.value).reversed())
- .collect(Collectors.toList());
- }
-}
+package com.baeldung.algorithms.romannumerals;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+enum RomanNumeral {
+ I(1), IV(4), V(5), IX(9), X(10), XL(40), L(50), XC(90), C(100), CD(400), D(500), CM(900), M(1000);
+
+ private int value;
+
+ RomanNumeral(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public static List getReverseSortedValues() {
+ return Arrays.stream(values())
+ .sorted(Comparator.comparing((RomanNumeral e) -> e.value).reversed())
+ .collect(Collectors.toList());
+ }
+}
diff --git a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
similarity index 90%
rename from algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
index f5024c227d..333019e294 100644
--- a/algorithms/roundUpToHundred/src/com/java/src/RoundUpToHundred.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
@@ -1,20 +1,20 @@
-package com.java.src;
-
-import java.util.Scanner;
-
-public class RoundUpToHundred {
-
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double input = scanner.nextDouble();
- scanner.close();
-
- RoundUpToHundred.round(input);
- }
-
- static long round(double input) {
- long i = (long) Math.ceil(input);
- return ((i + 99) / 100) * 100;
- };
-
-}
+package com.baeldung.algorithms.roundedup;
+
+import java.util.Scanner;
+
+public class RoundUpToHundred {
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ double input = scanner.nextDouble();
+ scanner.close();
+
+ RoundUpToHundred.round(input);
+ }
+
+ static long round(double input) {
+ long i = (long) Math.ceil(input);
+ return ((i + 99) / 100) * 100;
+ };
+
+}
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/slope_one/InputData.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/InputData.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/slope_one/InputData.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/InputData.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/slope_one/Item.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/Item.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/slope_one/Item.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/Item.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/slope_one/User.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/User.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/slope_one/User.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/User.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/sudoku/BacktrackingAlgorithm.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/BacktrackingAlgorithm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/sudoku/BacktrackingAlgorithm.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/BacktrackingAlgorithm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/sudoku/ColumnNode.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/ColumnNode.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/sudoku/ColumnNode.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/ColumnNode.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingLinks.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingLinks.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingLinks.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingLinks.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingLinksAlgorithm.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingLinksAlgorithm.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingLinksAlgorithm.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingLinksAlgorithm.java
diff --git a/algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingNode.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingNode.java
similarity index 100%
rename from algorithms/src/main/java/com/baeldung/algorithms/sudoku/DancingNode.java
rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/sudoku/DancingNode.java
diff --git a/apache-cayenne/src/main/resources/logback.xml b/algorithms-miscellaneous-2/src/main/resources/logback.xml
similarity index 100%
rename from apache-cayenne/src/main/resources/logback.xml
rename to algorithms-miscellaneous-2/src/main/resources/logback.xml
diff --git a/algorithms/src/main/resources/maze/maze1.txt b/algorithms-miscellaneous-2/src/main/resources/maze/maze1.txt
similarity index 92%
rename from algorithms/src/main/resources/maze/maze1.txt
rename to algorithms-miscellaneous-2/src/main/resources/maze/maze1.txt
index 0a6309d25b..8b48c325d2 100644
--- a/algorithms/src/main/resources/maze/maze1.txt
+++ b/algorithms-miscellaneous-2/src/main/resources/maze/maze1.txt
@@ -1,12 +1,12 @@
-S ########
-# #
-# ### ## #
-# # # #
-# # # # #
-# ## #####
-# # #
-# # # # #
-##### ####
-# # E
-# # # #
+S ########
+# #
+# ### ## #
+# # # #
+# # # # #
+# ## #####
+# # #
+# # # # #
+##### ####
+# # E
+# # # #
##########
\ No newline at end of file
diff --git a/algorithms/src/main/resources/maze/maze2.txt b/algorithms-miscellaneous-2/src/main/resources/maze/maze2.txt
similarity index 96%
rename from algorithms/src/main/resources/maze/maze2.txt
rename to algorithms-miscellaneous-2/src/main/resources/maze/maze2.txt
index 22e6d0382a..df5b6bc66b 100644
--- a/algorithms/src/main/resources/maze/maze2.txt
+++ b/algorithms-miscellaneous-2/src/main/resources/maze/maze2.txt
@@ -1,22 +1,22 @@
-S ##########################
-# # # #
-# # #### ############### #
-# # # # # #
-# # #### # # ###############
-# # # # # # #
-# # # #### ### ########### #
-# # # # # #
-# ################## #
-######### # # # # #
-# # #### # ####### # #
-# # ### ### # # # # #
-# # ## # ##### # #
-##### ####### # # # # #
-# # ## ## #### # #
-# ##### ####### # #
-# # ############
-####### ######### # #
-# # ######## #
-# ####### ###### ## # E
-# # # ## #
+S ##########################
+# # # #
+# # #### ############### #
+# # # # # #
+# # #### # # ###############
+# # # # # # #
+# # # #### ### ########### #
+# # # # # #
+# ################## #
+######### # # # # #
+# # #### # ####### # #
+# # ### ### # # # # #
+# # ## # ##### # #
+##### ####### # # # # #
+# # ## ## #### # #
+# ##### ####### # #
+# # ############
+####### ######### # #
+# # ######## #
+# ####### ###### ## # E
+# # # ## #
############################
\ No newline at end of file
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java
rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/conversion/ByteArrayConverterUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/conversion/ByteArrayConverterUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/conversion/ByteArrayConverterUnitTest.java
rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/conversion/ByteArrayConverterUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
similarity index 100%
rename from algorithms/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
diff --git a/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java
similarity index 96%
rename from algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java
rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java
index 89bd871616..d11da61191 100644
--- a/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java
+++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceDataProvider.java
@@ -1,21 +1,21 @@
-package com.baeldung.algorithms.editdistance;
-
-import org.junit.runners.Parameterized.Parameters;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-public class EditDistanceDataProvider {
-
- @Parameters
- public static Collection