@Test public void testToEnumSet() { EnumSet<TestEnum> enums = EnumSet.of(TestEnum.value1, TestEnum.value2, TestEnum.value3); assertEquals(7, TestEnum.toLong(enums)); assertEquals(enums, TestEnum.toEnumSet(7)); }
public static <T extends Enum<T> & Identifiable<Long>> EnumSet<T> toEnumSet(long f, Class<T> cls) { EnumSet<T> result = EnumSet.noneOf(cls); for (T flag : cls.getEnumConstants()) { if ((f & flag.getId()) != 0) result.add(flag); } return result; }
EnumUtil { public static <T extends Enum<T> & Identifiable<Long>> EnumSet<T> toEnumSet(long f, Class<T> cls) { EnumSet<T> result = EnumSet.noneOf(cls); for (T flag : cls.getEnumConstants()) { if ((f & flag.getId()) != 0) result.add(flag); } return result; } }
EnumUtil { public static <T extends Enum<T> & Identifiable<Long>> EnumSet<T> toEnumSet(long f, Class<T> cls) { EnumSet<T> result = EnumSet.noneOf(cls); for (T flag : cls.getEnumConstants()) { if ((f & flag.getId()) != 0) result.add(flag); } return result; }  }
EnumUtil { public static <T extends Enum<T> & Identifiable<Long>> EnumSet<T> toEnumSet(long f, Class<T> cls) { EnumSet<T> result = EnumSet.noneOf(cls); for (T flag : cls.getEnumConstants()) { if ((f & flag.getId()) != 0) result.add(flag); } return result; }  static T getEnumById(Class<T> cls, K id, T defaultEnum); @SuppressWarnings({ "rawtypes", "unchecked" }) static T getEnumById(Class<T> cls, K id); static T getEnumByIdString(Class<T> cls, String id); static T valueOf(Class<T> cls, String name, T defaultValue); @SuppressWarnings({ "rawtypes", "unchecked" }) static T valueOf(Class<T> cls, String name); static Enum<?> getDefaultValue(Class<Enum<?>> cls); static EnumSet<T> toEnumSet(long f, Class<T> cls); static long toLong(EnumSet<T> enums); }
EnumUtil { public static <T extends Enum<T> & Identifiable<Long>> EnumSet<T> toEnumSet(long f, Class<T> cls) { EnumSet<T> result = EnumSet.noneOf(cls); for (T flag : cls.getEnumConstants()) { if ((f & flag.getId()) != 0) result.add(flag); } return result; }  static T getEnumById(Class<T> cls, K id, T defaultEnum); @SuppressWarnings({ "rawtypes", "unchecked" }) static T getEnumById(Class<T> cls, K id); static T getEnumByIdString(Class<T> cls, String id); static T valueOf(Class<T> cls, String name, T defaultValue); @SuppressWarnings({ "rawtypes", "unchecked" }) static T valueOf(Class<T> cls, String name); static Enum<?> getDefaultValue(Class<Enum<?>> cls); static EnumSet<T> toEnumSet(long f, Class<T> cls); static long toLong(EnumSet<T> enums);  }