64 lines
1.7 KiB
Java
64 lines
1.7 KiB
Java
package 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 {
|
|
private final Set<Direction> directions = new HashSet<>();
|
|
// FIXME remove getter, only for debugging
|
|
@Getter
|
|
private final Set<Direction> hardened = new HashSet<>();
|
|
|
|
public boolean set(@NonNull final Direction direction) {
|
|
return this.directions.add(direction);
|
|
}
|
|
|
|
public void setAll() {
|
|
this.directions.addAll(EnumSet.allOf(Direction.class));
|
|
}
|
|
|
|
public boolean clear(@NonNull final Direction direction) {
|
|
if (this.hardened.contains(direction)) {
|
|
return false;
|
|
}
|
|
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<Direction> getSet() {
|
|
return this.getSet(false);
|
|
}
|
|
|
|
public Iterable<Direction> getSet(final boolean onlyBrittleWalls) {
|
|
if (onlyBrittleWalls) {
|
|
return Stream.ofAll(this.directions)
|
|
.removeAll(this.hardened);
|
|
}
|
|
return Stream.ofAll(this.directions);
|
|
}
|
|
|
|
public void harden(@NonNull final Direction direction) {
|
|
if (!this.directions.contains(direction)) {
|
|
throw new IllegalStateException("Trying to harden cleared Direction: " + direction);
|
|
}
|
|
this.hardened.add(direction);
|
|
}
|
|
|
|
public void unharden(@NonNull final Direction direction) {
|
|
this.hardened.remove(direction);
|
|
}
|
|
}
|