private static <T extends Enum> int[] toIntArray(Collection<T> collection) {
   List<Integer> c = new ArrayList<Integer>(collection.size());
   for (T t : collection) {
     c.add(t.ordinal());
   }
   return ArrayUtils.toPrimitive(c.toArray(new Integer[c.size()]));
 }
Exemple #2
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;
  }
Exemple #3
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;
  }