33 lines
1006 B
Java
33 lines
1006 B
Java
package com.github.dtschust.zork.types;
|
|
|
|
import java.util.EnumSet;
|
|
import java.util.Optional;
|
|
|
|
public enum ZorkDirection {
|
|
NORTH("north", "n"),
|
|
EAST("east", "e"),
|
|
SOUTH("south", "s"),
|
|
WEST("west", "w");
|
|
|
|
private final String longName;
|
|
private final String shortName;
|
|
|
|
ZorkDirection(final String longName, final String shortName) {
|
|
this.longName = longName;
|
|
this.shortName = shortName;
|
|
}
|
|
|
|
public static Optional<ZorkDirection> fromShort(final String shortName) {
|
|
return EnumSet.allOf(ZorkDirection.class).stream()
|
|
.filter(e -> e.shortName.equals(shortName))
|
|
.findFirst();
|
|
}
|
|
|
|
public static ZorkDirection fromLong(final String longName) {
|
|
return EnumSet.allOf(ZorkDirection.class).stream()
|
|
.filter(e -> e.longName.equals(longName))
|
|
.findFirst()
|
|
.orElseThrow(() -> new IllegalArgumentException(longName + " is not a valid direction long name"));
|
|
}
|
|
}
|