From 8c68ea4844369d56f6d835590136edcca794dda0 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 30 Sep 2020 22:29:06 +0200 Subject: [PATCH] Refactor Directions. --- src/main/java/ch/fritteli/labyrinth/Tile.java | 4 ++-- .../labyrinth/{Directions.java => Walls.java} | 23 ++++--------------- 2 files changed, 6 insertions(+), 21 deletions(-) rename src/main/java/ch/fritteli/labyrinth/{Directions.java => Walls.java} (68%) diff --git a/src/main/java/ch/fritteli/labyrinth/Tile.java b/src/main/java/ch/fritteli/labyrinth/Tile.java index f631592..20695f7 100644 --- a/src/main/java/ch/fritteli/labyrinth/Tile.java +++ b/src/main/java/ch/fritteli/labyrinth/Tile.java @@ -11,7 +11,7 @@ import lombok.experimental.FieldDefaults; public class Tile { // FIXME remove me; only for debugging @Getter - final Directions walls = new Directions(); + final Walls walls = new Walls(); @Getter boolean visited = false; @@ -44,7 +44,7 @@ public class Tile { } public Option getRandomAvailableDirection() { - return Stream.ofAll(this.walls.getSet(true)).shuffle().headOption(); + return Stream.ofAll(this.walls.getUnhardenedSet()).shuffle().headOption(); } public boolean hasWallAt(@NonNull final Direction direction) { diff --git a/src/main/java/ch/fritteli/labyrinth/Directions.java b/src/main/java/ch/fritteli/labyrinth/Walls.java similarity index 68% rename from src/main/java/ch/fritteli/labyrinth/Directions.java rename to src/main/java/ch/fritteli/labyrinth/Walls.java index 145d203..fdf7c23 100644 --- a/src/main/java/ch/fritteli/labyrinth/Directions.java +++ b/src/main/java/ch/fritteli/labyrinth/Walls.java @@ -1,17 +1,14 @@ package ch.fritteli.labyrinth; import io.vavr.collection.Stream; -import lombok.Getter; import lombok.NonNull; import java.util.EnumSet; import java.util.HashSet; import java.util.Set; -public class Directions { +public class Walls { private final Set directions = new HashSet<>(); - // FIXME remove getter, only for debugging - @Getter private final Set hardened = new HashSet<>(); public boolean set(@NonNull final Direction direction) { @@ -29,25 +26,13 @@ public class Directions { return this.directions.remove(direction); } - public void clearAll() { - this.directions.clear(); - this.directions.addAll(this.hardened); - } - public boolean isSet(@NonNull final Direction direction) { return this.directions.contains(direction); } - public Iterable getSet() { - return this.getSet(false); - } - - public Iterable getSet(final boolean onlyBrittleWalls) { - if (onlyBrittleWalls) { - return Stream.ofAll(this.directions) - .removeAll(this.hardened); - } - return Stream.ofAll(this.directions); + public Iterable getUnhardenedSet() { + return Stream.ofAll(this.directions) + .removeAll(this.hardened); } public void harden(@NonNull final Direction direction) {