Exemplo n.º 1
0
 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()]));
 }
Exemplo n.º 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;
  }
Exemplo n.º 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;
  }