55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
package ch.fritteli.maze.generator.model;
|
|
|
|
import io.vavr.collection.Stream;
|
|
import lombok.EqualsAndHashCode;
|
|
import lombok.NonNull;
|
|
import lombok.ToString;
|
|
|
|
import java.util.EnumSet;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
import java.util.SortedSet;
|
|
import java.util.TreeSet;
|
|
|
|
@EqualsAndHashCode
|
|
@ToString
|
|
public class Walls {
|
|
private final SortedSet<Direction> directions = new TreeSet<>();
|
|
private final Set<Direction> hardened = new HashSet<>();
|
|
|
|
public void set(@NonNull final Direction direction) {
|
|
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 boolean isSet(@NonNull final Direction direction) {
|
|
return this.directions.contains(direction);
|
|
}
|
|
|
|
public Stream<Direction> getUnhardenedSet() {
|
|
return Stream.ofAll(this.directions)
|
|
.removeAll(this.hardened);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|