List of usage examples for java.lang Class getEnumConstants
public T[] getEnumConstants()
From source file:com.dianping.lion.util.EnumUtils.java
/** * ?property??/*www . j a v a 2 s.c o m*/ * @param <T> * @param enumClass * @param property * @param propValue * @return */ public static <T extends Enum<T>> T fromEnumProperty(Class<T> enumClass, String property, Object propValue) { T[] enumConstants = enumClass.getEnumConstants(); for (T t : enumConstants) { Object constantPropValue; try { constantPropValue = BeanUtils.getDeclaredFieldValue(t, property); if (ObjectUtils.equals(constantPropValue, propValue)) { return t; } } catch (Exception e) { throw new RuntimeException(e); } } return null; }
From source file:springfox.documentation.schema.Enums.java
static List<String> getEnumValues(final Class<?> subject) { return transformUnique(subject.getEnumConstants(), new Function<Object, String>() { @Override/*from w w w . j a v a2s .com*/ public String apply(Object input) { Optional<String> jsonValue = findJsonValueAnnotatedMethod(input) .transform(evaluateJsonValue(input)); if (jsonValue.isPresent() && !isNullOrEmpty(jsonValue.get())) { return jsonValue.get(); } return input.toString(); } }); }
From source file:com.vrem.util.EnumUtils.java
public static <T extends Enum> Set<T> values(@NonNull Class<T> enumType) { return new HashSet<>(Arrays.asList(enumType.getEnumConstants())); }
From source file:com.vrem.util.EnumUtils.java
public static <T extends Enum> T find(@NonNull Class<T> enumType, int index, @NonNull T defaultValue) { T[] values = enumType.getEnumConstants(); if (index < 0 || index >= values.length) { return defaultValue; }/* ww w. java2 s . c om*/ return values[index]; }
From source file:org.jnap.core.bean.model.PersistentEnumFactory.java
/** * //from w w w .j a va 2 s.c om * @param value * @param enumType * @return */ public static <E extends Enum, V extends Serializable> E get(V value, Class<E> enumType) { Assert.isAssignable(PersistentEnum.class, enumType); E enumMatch = null; for (E enumValue : enumType.getEnumConstants()) { if (((PersistentEnum) enumValue).getValue().equals(value)) { enumMatch = enumValue; break; } } return enumMatch; }
From source file:org.zalando.problem.ProblemModule.java
@SafeVarargs private static <E extends Enum & StatusType> Map<Integer, StatusType> buildIndex( final Class<? extends E>... types) { final Map<Integer, StatusType> index = new HashMap<>(); for (Class<? extends E> type : types) { for (final E status : type.getEnumConstants()) { if (index.containsKey(status.getStatusCode())) { throw new IllegalArgumentException("Duplicate status codes are not allowed"); }/* w ww . j a v a2 s . com*/ index.put(status.getStatusCode(), status); } } return index; }
From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java
public static <E extends Enum> E someEnum(Class<E> enumClazz) { return someValue(enumClazz.getEnumConstants()); }
From source file:org.sejda.conversion.EnumUtils.java
private static <T extends Enum<?> & FriendlyNamed> Collection<String> findValidValues(Class<T> enumClass) { List<String> result = new ArrayList<>(); for (FriendlyNamed each : enumClass.getEnumConstants()) { result.add(each.getFriendlyName()); }/* w w w.java 2 s . c o m*/ Collections.sort(result); return result; }
From source file:org.kontalk.util.EncodingUtils.java
/** * Get an enum set by parsing an integer which represents a bit array. * Source: http://stackoverflow.com/questions/2199399/storing-enumset-in-a-database * @param <T> type of elements in enum set * @param enumClass enum class to determine the type * @param decoded integer decoded as/*from w w w. jav a 2 s .co m*/ * @return an enum set containing the enums specified by the integer */ public static <T extends Enum<T>> EnumSet<T> intToEnumSet(Class<T> enumClass, int decoded) { EnumSet<T> enumSet = EnumSet.noneOf(enumClass); T[] enums = enumClass.getEnumConstants(); while (decoded != 0) { int ordinal = Integer.numberOfTrailingZeros(decoded); enumSet.add(enums[ordinal]); decoded -= Integer.lowestOneBit(decoded); } return enumSet; }
From source file:org.ovirt.engine.api.common.util.EnumValidator.java
private static <E extends Enum<E>> String getPossibleValues(Class<E> clz, Set<String> allValues) { for (E enumValue : clz.getEnumConstants()) { allValues.add(enumValue.name().toLowerCase()); }// w ww . ja v a 2 s .co m return ". Possible values for " + clz.getSimpleName() + " and its extended configurable values are: " + StringUtils.join(allValues.toArray(), ", "); }