Esempio n. 1
0
  public static <T extends Enum> T toEnum(Class<T> cls, int value) {

    T[] enumConstants = cls.getEnumConstants();
    for (T e : enumConstants) {
      if (e.ordinal() == value) {
        return e;
      }
    }
    return null;
  }
Esempio n. 2
0
  public static <T extends Enum> T toEnumOrDie(Class<T> cls, int value) {

    T[] enumConstants = cls.getEnumConstants();
    for (T e : enumConstants) {
      if (e.ordinal() == value) {
        return e;
      }
    }
    die("Can't convert ordinal value " + value + " into enum of type " + cls);
    return null;
  }