List of usage examples for java.lang Class getEnumConstants
public T[] getEnumConstants()
From source file:com.omertron.themoviedbapi.TestSuite.java
/** * Test the AppendToResponse method/* w w w . jav a 2s. c o m*/ * * @param <T> * @param test * @param methodClass * @param skip Any methods to skip */ public static <T extends AppendToResponseMethod> void testATR(AppendToResponse<T> test, Class<T> methodClass, T skip) { for (T method : methodClass.getEnumConstants()) { if (skip != null && method != skip) { assertTrue(test.getClass().getSimpleName() + ": Does not have " + method.getPropertyString(), test.hasMethod(method)); } } }
From source file:org.ovirt.engine.api.common.util.EnumValidator.java
private static <E extends Enum<E>> String getPossibleValues(Class<E> clz) { StringBuilder builder = new StringBuilder(". Possible values for " + clz.getSimpleName() + " are:"); for (E enumValue : clz.getEnumConstants()) { builder.append(" ").append(enumValue.name().toLowerCase()).append(","); }/*from w ww . j a v a 2s. com*/ return builder.toString().substring(0, builder.toString().length() - 1); }
From source file:com.github.horrorho.inflatabledonkey.args.ArgsFactory.java
static <E extends Enum<E>> String values(Class<E> e) { return Arrays.asList(e.getEnumConstants()).stream().map(Object::toString).collect(Collectors.joining(" ")); }
From source file:edu.utah.further.core.api.discrete.EnumUtil.java
/** * Create an enumerated type from string representation (factory method). * * @param enumType// www . j av a 2s . co m * the Class object of the enum type from which to return a constant * @param s * string to match * @return enum constant whose <code>toString()</code> matches s * @see {link Enum.valueOf} */ public static <E extends Enum<E>> E createFromString(final Class<E> enumType, final String s) { if (s == null) { return null; } for (final E t : enumType.getEnumConstants()) { if (s.equals(t.toString())) { return t; } } return null; }
From source file:org.dozer.util.ProtoUtils.java
public static Object unwrapEnums(Object value) { if (value instanceof Descriptors.EnumValueDescriptor) { Descriptors.EnumValueDescriptor descriptor = (Descriptors.EnumValueDescriptor) value; Class<? extends Enum> enumClass = getEnumClassByEnumDescriptor(descriptor.getType()); Enum[] enumValues = enumClass.getEnumConstants(); for (Enum enumValue : enumValues) { if (((Descriptors.EnumValueDescriptor) value).getName().equals(enumValue.name())) return enumValue; }/*w ww .ja v a2s.c o m*/ return null; } if (value instanceof Collection) { List modifiedList = new ArrayList(((List) value).size()); for (Object element : (List) value) { modifiedList.add(unwrapEnums(element)); } return modifiedList; } return value; }
From source file:com.yahoo.flowetl.core.util.EnumUtils.java
/** * Attempts to convert a string that represents an enumeration of a given * class into the actual enum object.//from w w w .jav a2 s .c om * * @param <T> * the generic type of the enum class to use * * @param enumKlass * the enum class that has the enumerations to select from * * @param enumStr * the enum string we will attempt to match * * @param caseSensitive * whether to compare case sensitive or not * * @return the enum object or null if not found/invalid... */ @SuppressWarnings("unchecked") public static <T extends Enum> T fromString(Class<T> enumKlass, String enumStr, boolean caseSensitive) { if (StringUtils.isEmpty(enumStr) || enumKlass == null) { // not valid return null; } Object[] types = enumKlass.getEnumConstants(); if (types == null) { // not an enum return null; } Object enumInstance = null; for (int i = 0; i < types.length; i++) { enumInstance = types[i]; if (caseSensitive == false) { if (StringUtils.equalsIgnoreCase(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } else { if (StringUtils.equals(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } } // not found throw new IllegalArgumentException( "Unknown enumeration [" + enumStr + "] for enum class [" + enumKlass + "]"); }
From source file:org.evosuite.executionmode.ListParameters.java
public static Object execute() { List<Row> rows = new ArrayList<Row>(); /*// ww w .j a va 2s . c om * This is necessary, as reading from evosuite-files properties * can change the defaults */ Properties.getInstance().resetToDefaults(); for (Field f : Properties.class.getFields()) { if (f.isAnnotationPresent(Parameter.class)) { Parameter p = f.getAnnotation(Parameter.class); String description = p.description(); Class<?> type = f.getType(); if (type.isEnum()) { description += " (Values: " + Arrays.toString(type.getEnumConstants()) + ")"; } String def; try { Object obj = f.get(null); if (obj == null) { def = ""; } else { if (type.isArray()) { def = Arrays.toString((Object[]) obj); } else { def = obj.toString(); } } } catch (Exception e) { def = ""; } rows.add(new Row(p.key(), type.getSimpleName(), description, def)); } } Collections.sort(rows); String name = "Name"; String type = "Type"; String defaultValue = "Default"; String description = "Description"; String space = " "; int maxName = Math.max(name.length(), getMaxNameLength(rows)); int maxType = Math.max(type.length(), getMaxTypeLength(rows)); int maxDefault = Math.max(defaultValue.length(), getMaxDefaultLength(rows)); LoggingUtils.getEvoLogger().info(name + getGap(name, maxName) + space + type + getGap(type, maxType) + space + defaultValue + getGap(defaultValue, maxDefault) + space + description); for (Row row : rows) { LoggingUtils.getEvoLogger() .info(row.name + getGap(row.name, maxName) + space + row.type + getGap(row.type, maxType) + space + row.defaultValue + getGap(row.defaultValue, maxDefault) + space + row.description); } return null; }
From source file:net.di2e.ecdr.commons.util.SearchUtils.java
public static <T extends Enum<?>> T enumEqualsIgnoreCase(Class<T> enumeration, String search) { for (T each : enumeration.getEnumConstants()) { if (StringUtils.equalsIgnoreCase(each.name(), search)) { return each; }// w ww. java2 s .co m } return null; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.util.VisualVariableHelper.java
/** * Sets the value of a given visual variable to a beanMap. If no such variable exists or the variable is null, then no value is set. * @param target the beanMap to which the variable should be set. * @param source the instance holding the values of the visual variables. * @param vv the visual variable to set to the beanMap. *//*from w w w. j a va 2s . co m*/ @SuppressWarnings("unchecked") public static void setVisualVariableValue(BeanMap target, EObject source, EAttribute vv) { if (source.eIsSet(vv) && source.eGet(vv) != null && target.containsKey(vv.getName())) { Object value = source.eGet(vv); //TODO handle multivalued attributes here if (vv.getEAttributeType() instanceof EEnum) { Class<Enum<?>> enumType = (Class<Enum<?>>) ((EEnum) vv.getEAttributeType()).getInstanceClass(); for (Enum<?> ec : enumType.getEnumConstants()) { if (ec.name().equals(((EEnumLiteral) value).getName())) { value = ec; } } } target.put(vv.getName(), value); } }
From source file:com.github.dactiv.fear.service.commons.Configs.java
/** * {@link ValueEnum} ?? class ???//from w w w . jav a 2s. c o m * * @param enumClass class * @param ignore ? * * @return key value ? Map ? */ public static List<Map<String, Object>> find(Class<? extends Enum<? extends ValueEnum<?>>> enumClass, List ignore) { List<Map<String, Object>> result = Lists.newArrayList(); Enum<? extends ValueEnum<?>>[] values = enumClass.getEnumConstants(); for (Enum<? extends ValueEnum<?>> o : values) { ValueEnum<?> ve = (ValueEnum<?>) o; Object value = ve.getValue(); if (ignore != null && !ignore.contains(value)) { Map<String, Object> dictionary = Maps.newHashMap(); dictionary.put(DEFAULT_VALUE_NAME, value); dictionary.put(DEFAULT_KEY_NAME, ve.getName()); result.add(dictionary); } } return result; }