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.synopsys.integration.util.EnumUtils.java
public static <T extends Enum<T>> List<T> parseCommaDelimitted(String commaDelimittedEnumString, Class<T> enumClass) { return Arrays.stream(commaDelimittedEnumString.split(",")).map(String::trim).filter(StringUtils::isNotBlank) .map(token -> Enum.valueOf(enumClass, token)).collect(Collectors.toList()); }
From source file:ch.digitalfondue.npjt.mapper.EnumMapper.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Object toEnum(String res, Class<?> paramType) { Class<? extends Enum> enumType = (Class<? extends Enum<?>>) paramType; return res == null ? null : Enum.valueOf(enumType, res.trim()); }
From source file:fr.landel.utils.commons.EnumUtils.java
/** * Get the enumeration if name is not empty and null otherwise. * /*from ww w . j a va 2s. co m*/ * @param enumType * The type of the enumeration * @param name * The string to check, may be null * @param <T> * Type of the enumeration * @return The enumeration object or null */ public static <T extends Enum<T>> T getNullIfEmpty(final Class<T> enumType, final String name) { if (StringUtils.isNotEmpty(name) && enumType != null) { try { return Enum.valueOf(enumType, name); } catch (IllegalArgumentException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( StringUtils.concat("Name parameter '", name, "' not found in enumeration: ", enumType), e); } } } return null; }
From source file:org.reficio.cougar.domain.Command.java
public static Command getCommand(String value) { if (StringUtils.isBlank(value)) { return null; }// w ww . ja v a 2 s .c o m try { return Enum.valueOf(Command.class, value); } catch (IllegalArgumentException ex) { return null; } }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException { if (type.equals(String.class)) { return (T) stringValue; }//from www. j a v a2 s . co m if (type.equals(Boolean.class) || type.equals(boolean.class)) { return (T) Boolean.valueOf(stringValue); } try { if (type.equals(Integer.class) || type.equals(int.class)) { return (T) Integer.valueOf(stringValue); } if (type.equals(Long.class) || type.equals(long.class)) { return (T) Long.valueOf(stringValue); } if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringValue); } if (type.equals(Byte.class) || type.equals(byte.class)) { return (T) Byte.valueOf(stringValue); } if (type.equals(Double.class) || type.equals(double.class)) { return (T) Double.valueOf(stringValue); } if (type.equals(Float.class) || type.equals(float.class)) { return (T) Float.valueOf(stringValue); } if (type.equals(File.class)) { return (T) new File(stringValue); } } catch (final NumberFormatException e) { throw new IllegalArgumentException(e.getMessage(), e); } if (type.isEnum()) { @SuppressWarnings("rawtypes") final Class enumType = type; return (T) Enum.valueOf(enumType, stringValue); } throw new IllegalArgumentException("Can't handle type " + type); }
From source file:com.lingxiang2014.EnumConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Object convertToType(Class type, Object value) { String stringValue = value.toString().trim(); return Enum.valueOf(type, stringValue); }
From source file:com.synopsys.integration.util.EnumUtils.java
public static <T extends Enum<T>> List<T> convert(List<String> values, Class<T> enumClass) { return values.stream().map(String::trim).filter(StringUtils::isNotBlank) .map(token -> Enum.valueOf(enumClass, token)).collect(Collectors.toList()); }
From source file:edu.duke.cabig.c3pr.utils.web.propertyeditors.EnumByNameEditor.java
@Override public void setAsText(String text) throws IllegalArgumentException { if (text == null || StringUtils.isBlank(text)) { setValue(null);//from ww w . j av a2 s . com } else { setValue(Enum.valueOf(enumClass, text)); } }
From source file:org.dozer.converters.EnumConverter.java
public Object convert(Class destClass, Object srcObj) { try {//from www . j av a2s.c o m return Enum.valueOf(destClass, srcObj.toString()); } catch (Exception e) { MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e); } return srcObj; }
From source file:com.ocpsoft.pretty.faces.config.convert.CaseConverter.java
@SuppressWarnings("rawtypes") public Object convert(final Class type, final Object value) { if (value instanceof String) { return Enum.valueOf(Case.class, ((String) value).toUpperCase()); }//from w w w . j a va2 s. c o m throw new ConversionException("Could not convert value: [" + value + "] to Case type."); }