Example usage for java.lang Enum valueOf

List of usage examples for java.lang Enum valueOf

Introduction

In this page you can find the example usage for java.lang Enum valueOf.

Prototype

public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) 

Source Link

Document

Returns the enum constant of the specified enum type with the specified name.

Usage

From source file:bear.session.Variables.java

public static <T extends Enum<T>> Function<String, T> toEnum(final Class<T> tClass) {
    return new Function<String, T>() {
        @Override//from w w  w.  j  ava  2s .  co m
        public T apply(String input) {
            return Enum.valueOf(tClass, input);
        }
    };
}

From source file:com.iterzp.momo.utils.EnumConverterUtils.java

/**
 * ?//from  w  w  w.  j a v a 2 s  .  co  m
 * 
 * @param type
 *            
 * @param value
 *            
 * @return 
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object convertToType(Class type, Object value) {
    String stringValue = value.toString().trim();
    return Enum.valueOf(type, stringValue);
}

From source file:hudson.util.EnumConverter.java

public Object convert(Class aClass, Object object) {
    return Enum.valueOf(aClass, object.toString());
}

From source file:io.freeswitch.event.ChannelHangupComplete.java

/**
 * Gets the hangup cause.// ww w . j  a  va  2 s  .  com
 *
 * @return HangupCause value of the hangup cause.
 */
public HangupCauses reason() {
    if (_event.eventHeaders().containsKey("Hangup-Cause")) {
        String cause = _event.eventHeaders().get("Hangup-Cause");
        return Enum.valueOf(HangupCauses.class, cause);
    }

    return HangupCauses.NONE;
}

From source file:au.com.jwatmuff.eventmanager.util.EnumConvertingWrapDynaBean.java

@SuppressWarnings("unchecked")
@Override//  w  w w  . j a  v a2s  .  c  om
public void set(String name, Object value) {
    Class clazz = getDynaProperty(name).getType();
    if ((clazz != null) && clazz.isEnum() && (value instanceof String)) {
        try {
            value = Enum.valueOf(clazz, (String) value);
        } catch (Exception e) {
            value = null;
        }
    }
    super.set(name, value);
}

From source file:org.bitsofinfo.util.address.usps.ais.loader.GenericEnumConverter.java

@Override
public Object convert(Class clazz, Object value) {

    if (clazz.isEnum() && value instanceof String) {
        String toParse = (String) value;
        if (toParse != null && toParse.trim().length() > 0) {
            try {
                return Enum.valueOf(clazz, toParse);
            } catch (Exception e) {
                System.out.println("error parsing..." + toParse);
                return null;

            }//from w ww .  java2 s  .  c o  m
        }
    }

    return null;
}

From source file:com.flexive.faces.converter.EnumConverter.java

@SuppressWarnings({ "unchecked" })
public static Enum getValue(String value) {
    if (StringUtils.isBlank(value) || "-1".equals(value)) {
        return null;
    }/*from   w w  w. j av a  2 s .co  m*/
    String[] values = value.split("::");
    if (values.length != 2) {
        throw new IllegalArgumentException("Invalid argument for enum converter: " + value);
    }
    try {
        return Enum.valueOf((Class<? extends Enum>) Class.forName(values[0]), values[1]);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.jdto.impl.ValueConversionHelper.java

/**
 * Safely, try to read an enum constant and if it is not possible, then
 * return the original value./*from w w  w  . ja v a  2s.co m*/
 * @param targetValue the enum constant string.
 * @param targetType the enum type.
 * @return the enum literal or null
 */
private static Object readEnumConstant(String targetValue, Class targetType) {
    try {
        return Enum.valueOf(targetType, targetValue);
    } catch (Exception ex) {
        return targetValue;
    }
}

From source file:org.restlet.ext.oauth.OAuthException.java

public static OAuthException toOAuthException(JSONObject result) throws JSONException {
    OAuthError error = Enum.valueOf(OAuthError.class, result.getString(OAuthResourceDefs.ERROR));
    OAuthException ex = new OAuthException(error);
    if (result.has(OAuthResourceDefs.ERROR_DESC)) {
        ex.description = result.getString(OAuthResourceDefs.ERROR_DESC);
    }/*from w  ww .  ja  va2  s.  co m*/
    if (result.has(OAuthResourceDefs.ERROR_URI)) {
        ex.errorUri = result.getString(OAuthResourceDefs.ERROR_URI);
    }
    return ex;
}

From source file:org.LexGrid.LexBIG.caCore.hibernate.types.EnumUserType.java

public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
        throws HibernateException, SQLException {
    String name = resultSet.getString(names[0]);

    Object result = null;//from   w w w  . jav  a2s .  c  o m
    //Only process if there is something to process -- skip if just whitespace.
    if (StringUtils.isNotBlank(name)) {
        if (!resultSet.wasNull()) {
            result = Enum.valueOf(enumClass, name.toUpperCase());
        }
    }
    return result;
}