List of usage examples for java.lang Enum valueOf
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
From source file:cn.hxh.springside.orm.PropertyFilter.java
/** * @param filterName ,???. //ww w .ja v a2s .c om * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ObjectMapper.convertToObject(value, propertyClass); }
From source file:com.dosport.hibernate.utils.PropertyFilter.java
/** * @param filterName/*from w w w. j a va 2 s .co m*/ * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }
From source file:org.lilyproject.cli.OptionUtil.java
public static <T extends Enum<T>> T getEnum(CommandLine cmd, Option option, Class<T> enumClass) { String value = getStringOption(cmd, option); try {/*from w w w.ja v a 2 s.c o m*/ return Enum.valueOf(enumClass, value.toUpperCase()); } catch (IllegalArgumentException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + value); } }
From source file:com.funtl.framework.smoke.core.modules.act.utils.Variable.java
@JsonIgnore public Map<String, Object> getVariableMap() { ConvertUtils.register(new DateConverter(), java.util.Date.class); if (StringUtils.isBlank(keys)) { return map; }// w w w .j av a 2 s. co m String[] arrayKey = keys.split(","); String[] arrayValue = values.split(","); String[] arrayType = types.split(","); for (int i = 0; i < arrayKey.length; i++) { String key = arrayKey[i]; String value = arrayValue[i]; String type = arrayType[i]; Class<?> targetType = Enum.valueOf(PropertyType.class, type).getValue(); Object objectValue = ConvertUtils.convert(value, targetType); map.put(key, objectValue); } return map; }
From source file:cn.newtouch.util.orm.PropertyFilter.java
/** * @param filterName// w ww.j a v a 2s . c o m * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { this.matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { this.propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); this.propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, this.propertyClass); }
From source file:com.bjwg.back.util.PropertyFilter.java
/** * eg. LIKES_NAME_OR_LOGIN_NAME * @param value/*from ww w.ja v a2 s .com*/ */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException(filterName, e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException(filterName, e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), filterName); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ObjectMapper.convertToObject(value, propertyClass); }
From source file:org.apache.bval.jsr.util.EnumerationConverter.java
/** * {@inheritDoc}//from ww w .ja v a 2s . c o m */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Object convert(Class type, Object value) { if (!type.isEnum()) { throw new RuntimeException("Only enum types supported in this version!"); } if (value == null) { throw new RuntimeException("Null values not supported in this version!"); } if (String.class != value.getClass()) { throw new RuntimeException("Only java.lang.String values supported in this version!"); } String stringValue = (String) value; final Class<Enum> enumClass = (Class<Enum>) type; return Enum.valueOf(enumClass, stringValue); }
From source file:be.fedict.eid.pkira.portal.util.TypeMapper.java
public Contract map(ContractWS contractWS) { Contract contract = new Contract(); contract.setId(contractWS.getContractId()); contract.setCertificateDomainName(contractWS.getCertificateDomainName()); if (contractWS.getCertificateType() != null) { contract.setCertificateType(/*from w w w . ja v a 2s . c o m*/ Enum.valueOf(CertificateType.class, contractWS.getCertificateType().name())); } contract.setContractType(map(contractWS.getContractType())); contract.setCreationDate(contractWS.getCreationDate().toGregorianCalendar().getTime()); contract.setDnExpression(contractWS.getDnExpression()); contract.setCertificateId(contractWS.getCertificateId()); contract.setRequesterName(contractWS.getRequesterName()); contract.setResult(contractWS.getResult()); contract.setResultMessage(contractWS.getResultMessage()); return contract; }
From source file:org.restlet.ext.oauth.OAuthException.java
public static OAuthException toOAuthException(Form params) { OAuthError error = Enum.valueOf(OAuthError.class, params.getFirstValue(OAuthResourceDefs.ERROR)); OAuthException ex = new OAuthException(error); ex.description = params.getFirstValue(OAuthResourceDefs.ERROR_DESC); ex.errorUri = params.getFirstValue(OAuthResourceDefs.ERROR_URI); return ex;/*from ww w .j ava2 s . co m*/ }