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:com.newlandframework.rpc.spring.NettyRpcRegistery.java
public void afterPropertiesSet() throws Exception { MessageRecvExecutor ref = MessageRecvExecutor.getInstance(); ref.setServerAddress(ipAddr);// w w w .j a v a 2s. c o m ref.setSerializeProtocol(Enum.valueOf(RpcSerializeProtocol.class, protocol)); if (RpcSystemConfig.isMonitorServerSupport()) { context.register(ThreadPoolMonitorProvider.class); context.refresh(); } ref.start(); }
From source file:org.primeframework.mvc.parameter.convert.converters.EnumConverter.java
protected Object stringToObject(String value, Type convertTo, Map<String, String> attributes, String expression) throws ConversionException, ConverterStateException { if (emptyIsNull && StringUtils.isBlank(value)) { return null; }//ww w . jav a2 s . com try { return Enum.valueOf((Class<Enum>) convertTo, value); } catch (IllegalArgumentException e) { throw new ConversionException(e); } }
From source file:org.lilyproject.cli.OptionUtil.java
public static <T extends Enum<T>> T getEnum(CommandLine cmd, Option option, T defaultValue, Class<T> enumClass) { String value = getStringOption(cmd, option, null); if (value == null) { return defaultValue; }/*from w ww . j av a 2 s . co m*/ try { return Enum.valueOf(enumClass, value.toUpperCase()); } catch (IllegalArgumentException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + value); } }
From source file:com.bstek.dorado.data.provider.CriteriaDataType.java
private FilterOperator toFilterOperator(String s) { FilterOperator operator = null;/* ww w . j a v a 2 s. c o m*/ try { operator = Enum.valueOf(FilterOperator.class, s); } catch (Exception e) { for (FilterOperator op : FilterOperator.values()) { if (op.toString().equals(s)) { operator = op; break; } } } return operator; }
From source file:org.neo4j.ogm.typeconversion.EnumStringConverter.java
@Override public Enum toEntityAttribute(String value) { if (value == null || (lenient && StringUtils.isBlank(value))) { return null; }/*from w w w . j a va 2 s . co m*/ return Enum.valueOf(enumClass, value); }
From source file:org.springframework.social.google.api.impl.ApiEnumDeserializer.java
@Override public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String camelCase = jp.getText(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < camelCase.length(); i++) { char c = camelCase.charAt(i); if (Character.isUpperCase(c)) { sb.append('_').append(c); } else {/* w w w .ja v a 2s . co m*/ sb.append(Character.toUpperCase(c)); } } @SuppressWarnings({ "rawtypes", "unchecked" }) T value = (T) Enum.valueOf((Class) type, sb.toString()); return value; }
From source file:gov.nih.nci.caarray.plugins.illumina.AbstractCsvDesignHelper.java
/** * init headerIndex by looking at the order of the headers row. *//*w w w. j av a2 s . c o m*/ @SuppressWarnings("unchecked") void initHeaderIndex(List<String> headerValues) { EnumSet<? extends Enum> headers = EnumSet.allOf(headerEnumClass); headerIndex = new int[headers.size()]; for (int i = 0; i < headerValues.size(); i++) { Enum h = Enum.valueOf(headerEnumClass, headerValues.get(i).toUpperCase(Locale.getDefault())); headerIndex[h.ordinal()] = i; } }
From source file:com.formkiq.core.form.bean.CustomConvertUtilsBean.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from w w w .j a v a 2 s . c o m*/ public Object convert(final String value, final Class clazz) { if (clazz.isEnum()) { String val = Strings.extractLabelAndValue(value).getRight(); try { Method method = clazz.getMethod("find", String.class); Object result = method.invoke(method, val); if (result instanceof Optional) { Optional<Object> op = (Optional<Object>) result; if (op.isPresent()) { return op.get(); } } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // ignore error } return Enum.valueOf(clazz, val); } return super.convert(value, clazz); }
From source file:com.astamuse.asta4d.web.initialization.SimplePropertyFileInitializer.java
protected BeanUtilsBean retrieveBeanUtilsBean() { BeanUtilsBean bu = new BeanUtilsBean(new ConvertUtilsBean() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override// ww w . j a v a 2 s . c o m public Object convert(String value, Class clazz) { if (clazz.isEnum()) { return Enum.valueOf(clazz, value); } else if (clazz.equals(Class.class)) { try { return Class.forName(value); } catch (Exception e) { throw new RuntimeException(e); } } else if (expectInstance(clazz)) { try { return Class.forName(value).newInstance(); } catch (Exception e) { throw new RuntimeException(e); } } else { return super.convert(value, clazz); } } }); return bu; }
From source file:eionet.cr.dao.readers.StagingDatabaseDTOReader.java
@Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { StagingDatabaseDTO databaseDTO = new StagingDatabaseDTO(); databaseDTO.setId(rs.getInt("DATABASE_ID")); databaseDTO.setName(rs.getString("NAME")); databaseDTO.setCreator(rs.getString("CREATOR")); databaseDTO.setCreated(rs.getTimestamp("CREATED")); databaseDTO.setDescription(rs.getString("DESCRIPTION")); databaseDTO.setImportStatus(Enum.valueOf(ImportStatus.class, rs.getString("IMPORT_STATUS"))); databaseDTO.setImportLog(rs.getString("IMPORT_LOG")); try {/*from w w w. j a v a 2 s. c om*/ Blob blob = rs.getBlob("DEFAULT_QUERY"); String query = blob == null ? null : blob.length() == 0 ? "" : IOUtils.toString(blob.getBinaryStream()); databaseDTO.setDefaultQuery(query); } catch (Exception e) { LOGGER.warn("Failed to read column: DEFAULT_QUERY", e); } resultList.add(databaseDTO); }