/** * Get the first enum item in enum class E which EnumValue value is equal to value * @param <E> type of the enum * @param value * @param enumClass * @return first enum item with matching value, null if there is no matching enum item */ public static <E extends Enum<E>> E getEnum(long value, Class<E> enumClass) { return getCache(enumClass).enumsByValue.get(value); }
/** * Get the integer value associated with an enum item * @see EnumValue * @param enumItem * @return the numeric value of the enum */ @SuppressWarnings("unchecked") public static <E extends Enum<?>> long getValue(E enumItem) { return getCache((Class<E>) enumItem.getDeclaringClass()).valuesByEnum.get(enumItem); }
/** * Get the set of all the enum item in enum class E which EnumValue value flags are all present in value * @param <E> type of the enum * @param value * @param enumClass * @return enum items with matching value flags */ public static <E extends Enum<E>> EnumSet<E> getEnumSet(long value, Class<E> enumClass) { EnumSet<E> set = EnumSet.noneOf(enumClass); for (Map.Entry<Long, E> pair : getCache(enumClass).enumsByValue.entrySet()) { long ev = pair.getKey(); if ((ev & value) == ev) { set.add(pair.getValue()); } } return set; }