I have several switch statements which test an enum. All enum values must be handled in the switch statements by a case s
The Enum Mapper project provides an an annotation processor which will make sure at compile-time that all enum constants are handled.
Moreover it supports reverse lookup and paritial mappers.
Usage example:
@EnumMapper
public enum Seasons {
SPRING, SUMMER, FALL, WINTER
}
The annotation processor will generate a java class Seasons_MapperFull, which can be used to map all enum constants to arbitrary values.
Here is an example use where we map each enum constant to a string.
EnumMapperFull germanSeasons = Seasons_MapperFull
.setSPRING("Fruehling")
.setSUMMER("Sommer")
.setFALL("Herbst")
.setWINTER("Winter");
You can now use the mapper to get the values, or do reverse lookup
String germanSummer = germanSeasons.getValue(Seasons.SUMMER); // returns "Sommer"
ExtremeSeasons.getEnumOrNull("Sommer"); // returns the enum-constant SUMMER
ExtremeSeasons.getEnumOrRaise("Fruehling"); // throws an IllegalArgumentException