List of usage examples for java.lang Enum name
String name
To view the source code for java.lang Enum name.
Click Source Link
From source file:adalid.commons.velocity.VelocityAid.java
public static Enum valueOf(Class<?> clazz, String name) { if (clazz == null || name == null) { return null; }/*from w ww . j av a 2 s .c om*/ Object object = values(clazz); if (object instanceof Enum[]) { Enum[] values = (Enum[]) object; for (Enum e : values) { if (name.equals(e.name())) { return e; } } } return null; }
From source file:org.agiso.core.i18n.util.I18nUtils.java
public static String getCode(Enum<?> e) { try {//from w ww . j a v a 2s .c om return getCode(e.getClass().getField(e.name())); } catch (SecurityException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } catch (NoSuchFieldException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } return e.getDeclaringClass().getName() + CODE_SEPARATOR + e.name(); }
From source file:org.andromda.presentation.gui.JsfUtils.java
/** * Returns an array of SelectItem from the values/names of the enumeration * @param prefix a String prefix to be used to load the name from the messages * @param enumClassName the enumeration class name * @return the array of SelectItem/*from ww w . ja v a2s . c o m*/ */ @SuppressWarnings("rawtypes") public static SelectItem[] getEnumSelectItems(final String prefix, final String enumClassName) { try { final SelectItem[] result; final Class<?> enumClass = JsfUtils.class.getClassLoader().loadClass(enumClassName); if (enumClass.isEnum()) { final Enum[] values = (Enum[]) enumClass.getMethod("values", (Class<?>[]) null).invoke(null, (Object[]) null); result = new SelectItem[values.length]; int i = 0; for (final Enum value : values) { result[i] = new SelectItem(value, Messages.get(prefix + value.name())); i++; } } else { final List values = (List) enumClass.getMethod("values", (Class<?>[]) null).invoke(null, (Object[]) null); final int sz = values.size(); final List names = (List) enumClass.getMethod("names", (Class<?>[]) null).invoke(null, (Object[]) null); result = new SelectItem[sz]; for (int i = 0; i < sz; i++) { result[i] = new SelectItem(values.get(i), Messages.get(prefix + names.get(i))); } } return result; } catch (Exception e) { throw new RuntimeException(enumClassName + " is not an Andromda generated enumeration.", e); } }
From source file:org.jnetstream.protocol.ProtocolRegistry.java
/** * @param protocol//from ww w . jav a2 s . co m */ private static void fillInFromClassInfo(DefaultProtocolEntry entry, Protocol protocol) { Class<? extends Protocol> c = protocol.getClass(); if (c.isEnum() == false) { return; } Enum<?> constant = null; for (Enum<?> e : (Enum[]) c.getEnumConstants()) { if (e == protocol) { constant = e; } } Package pkg = c.getPackage(); String suite = c.getSimpleName(); String name = constant.name(); String headeri = pkg.getName() + "." + name; String headerc = pkg.getName() + "." + name + "Header"; String headercdc = pkg.getName() + "." + name + "Codec"; // System.out.printf("suite=%s,\n name=%s,\n headeri=%s,\n headerc=%s\n", // suite, name, headeri, headerc); entry.setSuite(suite); entry.setName(name); try { entry.setProtocolClass((Class<? extends Header>) Class.forName(headeri)); } catch (Exception e) { logger.warn("missing header: " + headeri); logger.debug(e); } try { entry.setCodec((Class<HeaderCodec<? extends Header>>) Class.forName(headercdc)); HeaderCodec<? extends Header> codec = entry.getCodecClass().newInstance(); entry.setCodec(codec); } catch (Exception e) { logger.warn("missing codec: " + headercdc); logger.debug(e); } }
From source file:gov.nih.nci.caarray.plugins.illumina.IlluminaCsvDesignHandler.java
@SuppressWarnings("PMD.ExcessiveParameterList") static void validateFieldLength(String value, Enum header, FileValidationResult result, int lineNumber, int expectedLength, int col) { if (value.length() != expectedLength) { final ValidationMessage error = result.addMessage(ValidationMessage.Type.ERROR, "Expected size of field for " + header.name() + " to be " + expectedLength + " but was " + value.length()); error.setLine(lineNumber);/*from www . j a v a 2 s .co m*/ error.setColumn(col); } }
From source file:org.fenixedu.academic.util.phd.PhdBundleUtil.java
@Deprecated public static String getEnumName(final Enum<?> enumeration, final String moduleName) { String enumFullName = enumeration.getClass().getName(); if (enumFullName.indexOf('$') > -1) { enumFullName = enumFullName.substring(0, enumFullName.indexOf('$')); }/*from w w w . j ava 2 s .c o m*/ String enumSimpleName = enumeration.getClass().getSimpleName(); if (enumSimpleName.isEmpty()) { enumSimpleName = enumFullName.substring(enumFullName.lastIndexOf('.') + 1); } enumFullName = enumFullName + "." + enumeration.name(); enumSimpleName = enumSimpleName + "." + enumeration.name(); try { return getResourceBundleByModuleName(moduleName).getString(enumFullName); } catch (MissingResourceException e) { try { return getResourceBundleByModuleName(moduleName).getString(enumSimpleName); } catch (MissingResourceException ex) { try { return getResourceBundleByModuleName(moduleName).getString(enumeration.name()); } catch (MissingResourceException exc) { return enumFullName; } } } }
From source file:org.totschnig.myexpenses.dialog.HelpDialogFragment.java
public static HelpDialogFragment newInstance(String context, Enum<?> variant) { HelpDialogFragment dialogFragment = new HelpDialogFragment(); Bundle args = new Bundle(); args.putString(KEY_CONTEXT, context); if (variant != null) args.putString(KEY_VARIANT, variant.name()); dialogFragment.setArguments(args);/* w ww. ja v a 2s . c o m*/ return dialogFragment; }
From source file:com.netflix.simianarmy.aws.AWSResource.java
private static void putToMapIfNotNull(Map<String, String> map, String key, Enum<?> value) { Validate.notNull(map);//from w w w .j a v a2 s. c om Validate.notNull(key); if (value != null) { map.put(key, value.name()); } }
From source file:net.sourceforge.fenixedu.util.BundleUtil.java
@Deprecated // remove on move to major version 4.0.0 public static String getEnumName(final Enum<?> enumeration, final String moduleName) { String enumFullName = enumeration.getClass().getName(); if (enumFullName.indexOf('$') > -1) { enumFullName = enumFullName.substring(0, enumFullName.indexOf('$')); }/*from www . j ava2 s .c o m*/ String enumSimpleName = enumeration.getClass().getSimpleName(); if (enumSimpleName.isEmpty()) { enumSimpleName = enumFullName.substring(enumFullName.lastIndexOf('.') + 1); } enumFullName = enumFullName + "." + enumeration.name(); enumSimpleName = enumSimpleName + "." + enumeration.name(); try { return getResourceBundleByModuleName(moduleName).getString(enumFullName); } catch (MissingResourceException e) { try { return getResourceBundleByModuleName(moduleName).getString(enumSimpleName); } catch (MissingResourceException ex) { try { return getResourceBundleByModuleName(moduleName).getString(enumeration.name()); } catch (MissingResourceException exc) { return enumFullName; } } } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.delegates.DelegatesManagementDispatchAction.java
protected static String getEnumName(Enum<?> enumeration) { return BundleUtil.getString(Bundle.ENUMERATION, enumeration.name()); }