Compare commits

..

No commits in common. "feature/algorithms" and "master" have entirely different histories.

5 changed files with 4 additions and 62 deletions

View file

@ -4,9 +4,4 @@ COPY target/maze-server-*.jar /app/
RUN rm /app/*-sources.jar
RUN mv /app/*.jar /app/app.jar
CMD java \
-Dfritteli.maze.server.host=0.0.0.0 \
-Dfritteli.maze.server.port=80 \
-Dfritteli.maze.maxheight=256 \
-Dfritteli.maze.maxwidth=256 \
-jar /app/app.jar
CMD java -Dfritteli.maze.server.host=0.0.0.0 -Dfritteli.maze.server.port=80 -jar /app/app.jar

View file

@ -56,7 +56,7 @@
</distributionManagement>
<properties>
<maze-generator.version>0.2.2-SNAPSHOT</maze-generator.version>
<maze-generator.version>0.2.1</maze-generator.version>
<maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version>
<undertow.version>2.3.18.Final</undertow.version>
</properties>

View file

@ -1,45 +0,0 @@
package ch.fritteli.maze.server;
import ch.fritteli.maze.generator.algorithm.MazeGeneratorAlgorithm;
import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
import ch.fritteli.maze.generator.algorithm.Wilson;
import ch.fritteli.maze.generator.model.Maze;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import io.vavr.control.Option;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
public enum Algorithm {
RANDOM_DEPTH_FIRST(RandomDepthFirst::new, "random", "random-depth-first"),
WILSON(Wilson::new, "wilson");
@NotNull
private final Function<Maze, MazeGeneratorAlgorithm> creator;
@Getter
@NotNull
private final List<String> names;
Algorithm(@NotNull final Function<Maze, MazeGeneratorAlgorithm> creator,
@NotNull final String... names) {
this.creator = creator;
this.names = List.of(names);
}
@NotNull
public static Option<Algorithm> ofString(@Nullable final String name) {
return Option.of(name)
.map(String::toLowerCase)
.flatMap(nameLC -> Stream.of(values())
.find(algorithm -> algorithm.getNames().contains(nameLC)));
}
@NotNull
public MazeGeneratorAlgorithm createAlgorithm(@NotNull final Maze maze) {
return this.creator.apply(maze);
}
}

View file

@ -3,7 +3,6 @@ package ch.fritteli.maze.server.handler;
import ch.fritteli.maze.generator.algorithm.RandomDepthFirst;
import ch.fritteli.maze.generator.model.Maze;
import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.maze.server.Algorithm;
import ch.fritteli.maze.server.InvalidRequestParameterException;
import ch.fritteli.maze.server.OutputType;
import io.vavr.collection.Stream;
@ -34,7 +33,6 @@ class ParametersToMazeExtractor {
final Option<Long> id = getParameterValue(RequestParameter.ID);
final Option<Position> start = getParameterValue(RequestParameter.START);
final Option<Position> end = getParameterValue(RequestParameter.END);
final Option<Algorithm> algorithm = getParameterValue(RequestParameter.ALGORITHM);
if (output.isEmpty()) {
return Try.failure(new InvalidRequestParameterException("Path parameter %s is required and must be one of: %s".formatted(
@ -79,10 +77,7 @@ class ParametersToMazeExtractor {
} else {
maze = new Maze(desiredWidth, desiredHeight, id.getOrElse(() -> new Random().nextLong()));
}
algorithm.getOrElse(Algorithm.RANDOM_DEPTH_FIRST)
.createAlgorithm(maze)
.run();
new RandomDepthFirst(maze).run();
return new GeneratedMaze(maze, output.get(), RandomDepthFirst.class.getSimpleName());
});
}

View file

@ -1,7 +1,6 @@
package ch.fritteli.maze.server.handler;
import ch.fritteli.maze.generator.model.Position;
import ch.fritteli.maze.server.Algorithm;
import ch.fritteli.maze.server.OutputType;
import io.vavr.Tuple2;
import io.vavr.collection.HashMap;
@ -45,9 +44,7 @@ enum RequestParameter {
return new Position(x, y);
})
.toOption()
.onEmpty(() -> log.debug("Unparseable value for parameter 'end': '{}'", p)), "e", "end"),
ALGORITHM(p -> Algorithm.ofString(p)
.onEmpty(() -> log.debug("Unparseable value for parameter 'algorithm': '{}'", p)), "a", "algorithm");
.onEmpty(() -> log.debug("Unparseable value for parameter 'end': '{}'", p)), "e", "end");
@NotNull
private final Function<String, Option<?>> extractor;
@Getter