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.microsoft.aad.adal.example.userappwithbroker.AcquireTokenFragment.java
void bindSpinnerChoice(final Spinner spinner, final Class<? extends Enum> spinnerChoiceClass) { final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, new ArrayList<String>() { {/*from w w w. java 2 s . c o m*/ for (Enum choice : spinnerChoiceClass.getEnumConstants()) add(choice.name()); } }); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); }
From source file:org.apache.atlas.repository.graph.FullTextMapperV2.java
private void mapAttribute(Object value, AtlasEntityExtInfo entityExtInfo, StringBuilder sb, Set<String> processedGuids) throws AtlasBaseException { if (value instanceof AtlasObjectId) { if (followReferences) { AtlasObjectId objectId = (AtlasObjectId) value; AtlasEntity entity = entityExtInfo.getEntity(objectId.getGuid()); if (entity != null) { map(entity, entityExtInfo, sb, processedGuids); }/*from w w w . j a v a 2 s. c om*/ } } else if (value instanceof List) { List valueList = (List) value; for (Object listElement : valueList) { mapAttribute(listElement, entityExtInfo, sb, processedGuids); } } else if (value instanceof Map) { Map valueMap = (Map) value; for (Object key : valueMap.keySet()) { mapAttribute(key, entityExtInfo, sb, processedGuids); mapAttribute(valueMap.get(key), entityExtInfo, sb, processedGuids); } } else if (value instanceof Enum) { Enum enumValue = (Enum) value; sb.append(enumValue.name()).append(FULL_TEXT_DELIMITER); } else if (value instanceof AtlasStruct) { AtlasStruct atlasStruct = (AtlasStruct) value; for (Map.Entry<String, Object> entry : atlasStruct.getAttributes().entrySet()) { sb.append(entry.getKey()).append(FULL_TEXT_DELIMITER); mapAttribute(entry.getValue(), entityExtInfo, sb, processedGuids); } } else { sb.append(String.valueOf(value)).append(FULL_TEXT_DELIMITER); } }
From source file:org.rhq.enterprise.server.search.assist.AbstractSearchAssistant.java
protected final List<String> filter(Class<? extends Enum<?>> enumType, String filter, boolean includeAnyOption) { List<String> results = new ArrayList<String>(); if (includeAnyOption && "any".contains(filter)) { results.add("any"); }/*from ww w . j a v a2s. c om*/ for (Enum<?> next : enumType.getEnumConstants()) { String enumName = next.name().toLowerCase(); if (filter == null || filter.equals("") || enumName.contains(filter)) { results.add(enumName); } } return Collections.unmodifiableList(results); }
From source file:be.fedict.eid.dss.model.bean.ConfigurationBean.java
/** * {@inheritDoc}/*ww w .ja v a 2s. co m*/ */ public void setValue(ConfigProperty configProperty, String index, Object value) { String propertyValue; if (null != value) { Class<?> expectedType = configProperty.getType(); Class<?> type = value.getClass(); if (!expectedType.isAssignableFrom(type)) { throw new IllegalArgumentException("value has incorrect type: " + type.getClass().getName()); } Object castedValue = expectedType.cast(value); if (expectedType.isEnum()) { Enum<?> enumValue = (Enum<?>) castedValue; propertyValue = enumValue.name(); } else { propertyValue = castedValue.toString(); if (propertyValue.trim().isEmpty()) { propertyValue = null; } } } else { propertyValue = null; } String propertyName = getPropertyName(configProperty, index); ConfigPropertyEntity configPropertyEntity = this.entityManager.find(ConfigPropertyEntity.class, propertyName); if (null == configPropertyEntity) { configPropertyEntity = new ConfigPropertyEntity(propertyName, propertyValue); this.entityManager.persist(configPropertyEntity); } else { configPropertyEntity.setValue(propertyValue); } }
From source file:org.structr.core.graph.NewIndexNodeCommand.java
private void init() { if (!initialized) { for (Enum indexName : (NodeService.NodeIndex[]) arguments.get("indices")) { indices.put(indexName.name(), (Index<Node>) arguments.get(indexName.name())); }/* w w w. ja va2 s .c o m*/ initialized = true; } }
From source file:com.github.jknack.handlebars.helper.DefaultHelperRegistry.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//w w w . j a va 2s. c o m public HelperRegistry registerHelpers(final Class<?> helperSource) { notNull(helperSource, "The helper source is required."); if (Enum.class.isAssignableFrom(helperSource)) { Enum[] helpers = ((Class<Enum>) helperSource).getEnumConstants(); for (Enum helper : helpers) { isTrue(helper instanceof Helper, "'%s' isn't a helper.", helper.name()); registerHelper(helper.name(), (Helper) helper); } } else { registerDynamicHelper(null, helperSource); } return this; }
From source file:io.apiman.manager.api.es.util.XContentBuilder.java
/** * @param fieldName//from w ww . ja v a 2 s . c o m * @param fieldValue * @throws IOException */ public XContentBuilder field(String fieldName, Enum<?> fieldValue) throws IOException { if (fieldValue != null) { json.writeStringField(fieldName, fieldValue.name()); } return this; }
From source file:org.logic2j.core.impl.DefaultTermAdapter.java
/** * Specific conversion of enums//from w ww .j ava 2 s.c om * @param theTerm The Prolog term * @param theTargetClass The target Java class * @param message * @param <T> * @return */ protected <T extends Enum> T fromEnum(Object theTerm, Class<T> theTargetClass, String message) { if (theTargetClass == Enum.class) { throw new IllegalArgumentException( message + ": converting to any Enum will require a custom TermAdapter, " + this + " cannot guess your intended Enum class"); } // For converting to Enum, we expect that theTerm will match the name() of the target Enum. // We will allow theTerm to be either the exact atom (eg 'VAL'), or // a struct/1 with any functor and the value, (eg my_enum_type_ignored('VAL')). // The reason is for consistency with the cases when the Prolog will return an enum value of a class that // Java cannot pre-determine. In that case user has to override this method in a dedicated TermAdapter, // and lookup the effective enum from the specified functor. final String effectiveEnumName; if (theTerm instanceof String) { effectiveEnumName = theTerm.toString(); } else if (theTerm instanceof Struct) { Struct s = (Struct) theTerm; if (s.getArity() != 1) { throw new IllegalArgumentException( message + ": if a Struct is passed, arity must be 1, was " + s.getArity()); } effectiveEnumName = s.getArg(0).toString(); } else { throw new IllegalArgumentException( message + ": converting to an Enum requires either an atom or a struct of arity=1"); } final Enum[] enumConstants = theTargetClass.getEnumConstants(); for (Enum c : enumConstants) { if (c.name().equals(effectiveEnumName)) { return (T) c; } } throw new IllegalArgumentException(message + ": no such enum value"); }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
/** * Converts an enum to a string, using the mapping dictionaries if * appropriate.//from w ww . j av a 2 s . co m * * @param value The enum value to be serialized * @return String representation of enum to be used in the protocol */ public static String serializeEnum(Object value) { String strValue = value.toString(); final Map<Class<?>, Map<String, String>> member = ENUM_TO_SCHEMA_DICTIONARIES.getMember(); final Map<String, String> enumToStringDict = member.get(value.getClass()); if (enumToStringDict != null) { final Enum<?> e = (Enum<?>) value; final String enumStr = enumToStringDict.get(e.name()); if (enumStr != null) { strValue = enumStr; } } return strValue; }
From source file:org.structr.core.graph.IndexRelationshipCommand.java
private void init() { for (Enum indexName : (RelationshipIndex[]) arguments.get("relationshipIndices")) { indices.put(indexName.name(), (Index<Relationship>) arguments.get(indexName.name())); }/*from ww w . j a v a 2 s. co m*/ }