Hey all. So I have a set of enums and a db with integers corresponding to those enums. Something like this, for example:
public static enum Day {
SUNDAY(1), MONDAY(2), TUESDAY(3), WEDNESDAY(4), THURSDAY(5), FRIDAY(6), SATURDAY(7);
public final int fId;
private Day(int id) {
this.fId = id;
}
}
I also have a database which only refers to these days by integers, which correspond to their int in the enum set above. What I am looking to do is query a database, which will return an integer, and then set an enumerator to an object based on that integer returned from the db. I could do something like this:
public static Day getDay(int i) {
switch(i) {
case 1:
return Day.SUNDAY;
case 2:
return Day.MONDAY;
//And so on
}
}
But for an enum set with over 100 enums inside this doesn't seem very practical.
So is there a way to do this? Again my goal is to simply insert an int value and get back an enumerator without having to create a new method for the many enums in this set. Maybe I should just make this its own class rather than an enumerator, but I was hoping to do it this way. Thanks!