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:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java
/** * Retrieves a message from a resource bundle from its key. * <p>/*from w w w . j av a 2 s . co m*/ * @param key Resource key to retrieve. * @param parameters Parameters to inject while formatting the message. * @return The formatted message. */ @SuppressWarnings("nls") private static final String retrieve(final Enum<? extends IBundle> key, final Object... parameters) { if (!isInitialized) { initialize(); } final Class<? extends IBundle> bundleClass = key.getDeclaringClass(); if (BUNDLES.containsKey(bundleClass)) { try { return MessageFormat.format(BUNDLES.get(bundleClass).getString(((IBundle) key).getKey()), parameters); } catch (MissingResourceException e) { throw new ResourceBundleException(BundleAthenaBase.ResourceBundleInvalidKey, bundleClass.getSimpleName(), key.name(), bundleClass.getEnumConstants()[0].getKey(), getLocale(), e); } } return "Resource bundle key cannot be found [bundle=" + bundleClass.getName() + ", key=" + key.name() + "]"; }
From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java
/** * Retrieves a message from a resource bundle from its key. * <p>/*from www . j a va 2s .c o m*/ * @param key Resource key to retrieve. * @param parameters Parameters to inject while formatting the message. * @return The formatted message. */ @SuppressWarnings("nls") private static final String retrieve(final Enum<? extends IBundle> key, final Object... parameters) { if (!isInitialized) { initialize(); } final Class<? extends IBundle> bundleClass = key.getDeclaringClass(); if (BUNDLES.containsKey(bundleClass)) { try { return MessageFormat.format(BUNDLES.get(bundleClass).getString(((IBundle) key).getKey()), parameters); } catch (MissingResourceException e) { throw new ResourceBundleException(BundleDemeterBase.ResourceBundleInvalidKey, bundleClass.getSimpleName(), key.name(), bundleClass.getEnumConstants()[0].getKey(), getLocale(), e); } } return "Resource bundle key cannot be found [bundle=" + bundleClass.getName() + ", key=" + key.name() + "]"; }
From source file:com.joyent.manta.util.MantaUtils.java
/** * Serializes a specified value to a {@link String}. * @param value the value to be serialized * @return a serialized value as a {@link String} *//*from w w w. j av a 2s. c om*/ public static String asString(final Object value) { if (value == null) { return null; } else if (value instanceof Enum<?>) { Enum<?> enumValue = (Enum<?>) value; try { /* In this case, we actually want the subclass of the enum type * because we are trying to read a property from it via * reflection. */ @SuppressWarnings("GetClassOnEnum") Field field = enumValue.getClass().getField(enumValue.name()); Validate.notNull(field, "A non-null field should always be returned. " + "Enum constant missing @Value or @NullValue annotation: %s", enumValue); } catch (NoSuchFieldException e) { String msg = String.format("Could not find name field for enum: %s", value); LOGGER.warn(msg, e); return null; } } else if (value instanceof Iterable<?>) { StringBuilder sb = new StringBuilder(); Iterator<?> itr = ((Iterable<?>) value).iterator(); while (itr.hasNext()) { Object next = itr.next(); if (next != null) { sb.append(next.toString()); } if (itr.hasNext()) { sb.append(","); } } return sb.toString(); } else if (value.getClass().isArray()) { Object[] array = (Object[]) value; StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { Object next = array[i]; if (next != null) { sb.append(next.toString()); } if (i < array.length - 1) { sb.append(", "); } } return sb.toString(); } return value.toString(); }
From source file:com.android.aft.AFNotificator.AFNotificatorEmitter.java
public void connect(Object receiver, Enum<?> event) { dbg.d("Connect to " + receiver + " for event " + event.name()); }
From source file:com.android.aft.AFNotificator.AFNotificatorEmitter.java
public void emit(Enum<?> e, Object... args) { dbg.d("Emit an event on " + e.name()); AFNotificatorEvent event = getEventByEnum(e); if (event == null) throw new AFNotificatorException("Cannot find event '" + e.name() + "' in events list"); if (event.args.length != args.length) throw new AFNotificatorException("Bad argument list for event '" + e.name() + "': expected size of " + event.args.length + " has " + args.length); Intent intent = new Intent(mActionName); intent.putExtra(EXTRA_PARAM_EVENT, event.name); for (int i = 0; i < args.length; ++i) { putExtraEventArgumentInIntent(intent, event, args, i); }//w w w. j a v a 2 s . c om mLbm.sendBroadcast(intent); }
From source file:org.polymap.wbv.ui.reports.SimpleDataSource.java
public SimpleDataSource put(Enum columnName, int rowIndex, Object value) { return put(columnName.name(), rowIndex, value); }
From source file:org.neo4j.ogm.typeconversion.EnumStringConverter.java
@Override public String toGraphProperty(Enum value) { if (value == null) return null; return value.name(); }
From source file:com.ejisto.modules.factory.impl.EnumFactory.java
@Override public Enum<T> create(MockedField m, Enum<T> actualValue) { try {/*w w w . j a v a 2 s. c om*/ String name = m.getFieldValue(); if (StringUtils.isEmpty(name)) { return actualValue; } @SuppressWarnings("unchecked") Class<Enum<T>> clazz = (Class<Enum<T>>) Class.forName(m.getFieldType()); if (!clazz.isEnum()) { return actualValue; } Enum<T>[] enums = clazz.getEnumConstants(); for (Enum<T> en : enums) { if (en.name().equals(name)) { return en; } } if (actualValue != null) { return actualValue; } return enums.length > 0 ? enums[0] : null; } catch (Exception ex) { log.warn(String.format("enum value not found for %s.", m), ex); } return actualValue; }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ??/*from ww w. j a v a 2 s .c om*/ * @param context * @param request * @param requestParams ??null???????? * @return ? */ @SuppressWarnings("unchecked") public static RequestParams parseRequestParams(Context context, Request request, RequestParams requestParams) { if (requestParams == null) { requestParams = new RequestParams(); } String requestParamName; String requestParamValue; Object requestParamValueObject = null; for (Field field : getFields(request.getClass(), true, true, true)) { // ???? if (!field.isAnnotationPresent(Param.class)) { continue; } // ???? requestParamName = parseParamAnnotation(context, field); if (requestParamName == null) { requestParamName = field.getName(); } // ?ValueValue? if (field.isAnnotationPresent(Value.class)) { String value = parseValueAnnotation(context, field); if (value != null) { requestParams.put(requestParamName, value); continue; } } try { field.setAccessible(true); requestParamValueObject = field.get(request); } catch (Exception e) { e.printStackTrace(); } // ?null? if (requestParamValueObject == null) { continue; } // ?Map??? if (Map.class.isAssignableFrom(field.getType())) { for (java.util.Map.Entry<Object, Object> entry : ((Map<Object, Object>) requestParamValueObject) .entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); if (key != null && !"".equals(key) && value != null && !"".equals(value)) { requestParams.put(key, value); } } } continue; } // ?File? if (File.class.isAssignableFrom(field.getType())) { try { requestParams.put(requestParamName, (File) requestParamValueObject); } catch (FileNotFoundException e) { e.printStackTrace(); } continue; } // ?ArrayListArrayList? if (ArrayList.class.isAssignableFrom(field.getType())) { requestParams.put(requestParamName, (ArrayList<String>) requestParamValueObject); continue; } // ?boolean if (Boolean.class.isAssignableFrom(field.getType())) { if ((Boolean) requestParamValueObject) { requestParamValue = parseTrueAnnotation(context, field); if (requestParamValue == null) { requestParamValue = DEFAULT_VALUE_TRUE; } } else { requestParamValue = parseFalseAnnotation(context, field); if (requestParamValue == null) { requestParamValue = DEFAULT_VALUE_FALSE; } } requestParams.put(requestParamName, requestParamValue); continue; } // ? if (Enum.class.isAssignableFrom(field.getType())) { Enum<?> enumObject = (Enum<?>) requestParamValueObject; requestParamValue = parseValueAnnotationFromEnum(context, enumObject); if (requestParamValue == null) { requestParamValue = enumObject.name(); } requestParams.put(requestParamName, requestParamValue); continue; } // ??? requestParamValue = requestParamValueObject.toString(); if (requestParamValue != null && !"".equals(requestParamValue)) { requestParams.put(requestParamName, requestParamValue); } } return requestParams; }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ??/*from ww w .j a v a 2s.com*/ * @param context * @param requestClass class??class?????? * @param requestParams ??null???????? * @return ? */ @SuppressWarnings("unchecked") public static RequestParams parseRequestParams(Context context, Class<? extends Request> requestClass, RequestParams requestParams) { if (requestParams == null) { requestParams = new RequestParams(); } String requestParamName; String requestParamValue; Object requestParamValueObject = null; for (Field field : getFields(requestClass, true, true, true)) { // ??????? if (!field.isAnnotationPresent(Param.class) || !Modifier.isStatic(field.getModifiers())) { continue; } // ???? requestParamName = parseParamAnnotation(context, field); if (requestParamName == null) { requestParamName = field.getName(); } // ?ValueValue? if (field.isAnnotationPresent(Value.class)) { String value = parseValueAnnotation(context, field); if (value != null) { requestParams.put(requestParamName, value); continue; } } try { field.setAccessible(true); requestParamValueObject = field.get(null); } catch (Exception e) { e.printStackTrace(); } // ?null? if (requestParamValueObject == null) { continue; } // ?Map??? if (Map.class.isAssignableFrom(field.getType())) { for (java.util.Map.Entry<Object, Object> entry : ((Map<Object, Object>) requestParamValueObject) .entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); if (key != null && !"".equals(key) && value != null && !"".equals(value)) { requestParams.put(key, value); } } } continue; } // ?File? if (File.class.isAssignableFrom(field.getType())) { try { requestParams.put(requestParamName, (File) requestParamValueObject); } catch (FileNotFoundException e) { e.printStackTrace(); } continue; } // ?ArrayListArrayList? if (ArrayList.class.isAssignableFrom(field.getType())) { requestParams.put(requestParamName, (ArrayList<String>) requestParamValueObject); continue; } // ?boolean if (Boolean.class.isAssignableFrom(field.getType())) { if ((Boolean) requestParamValueObject) { requestParamValue = parseTrueAnnotation(context, field); if (requestParamValue == null) { requestParamValue = DEFAULT_VALUE_TRUE; } } else { requestParamValue = parseFalseAnnotation(context, field); if (requestParamValue == null) { requestParamValue = DEFAULT_VALUE_FALSE; } } requestParams.put(requestParamName, requestParamValue); continue; } // ? if (Enum.class.isAssignableFrom(field.getType())) { Enum<?> enumObject = (Enum<?>) requestParamValueObject; requestParamValue = parseValueAnnotationFromEnum(context, enumObject); if (requestParamValue == null) { requestParamValue = enumObject.name(); } requestParams.put(requestParamName, requestParamValue); continue; } // ??? requestParamValue = requestParamValueObject.toString(); if (requestParamValue != null && !"".equals(requestParamValue)) { requestParams.put(requestParamName, requestParamValue); } } return requestParams; }