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:com.genentech.retrival.SDFExport.SDFSDFExporter.java

public static SDFSDFExporter createFromStatementStr(String selectStr, String paramTypes, String inFile,
        String outFile, String[] tagNames, boolean printIfNoRecord, String newLineReplacement) {
    String[] typeStr = paramTypes.split("\\s+");
    DADataType[] pTypes = new DADataType[typeStr.length];
    int i = 0;//from w  ww .  ja  va  2 s  .c  o  m
    for (String pStr : typeStr)
        pTypes[i++] = Enum.valueOf(DADataType.class, pStr.toUpperCase());

    i = 0;
    DAParameterUse[] usg = new DAParameterUse[pTypes.length];
    for (String pStr : typeStr)
        usg[i++] = DAParameterUse.IN;

    SQLStatement stmt = SQLStatement.createStatement(selectStr, pTypes, usg);

    return new SDFSDFExporter(stmt, inFile, outFile, tagNames, printIfNoRecord, newLineReplacement);
}

From source file:io.stallion.restfulEndpoints.RestEndpointBase.java

public RestEndpointBase setRole(String role) {
    this.role = Enum.valueOf(Role.class, role);
    return this;
}

From source file:com.thinkmore.framework.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from  www  .  j av a  2s  .  com
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtil.convertStringToObject(value, propertyType);
}

From source file:com.i5le.framwork.core.persistence.SearchFilter.java

/**
 * searchParamskey?LIKES_name//from ww  w  . j  a va  2 s. com
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();

        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }
        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2 && names.length != 3) {
            // throw new IllegalArgumentException(key +
            // " is not a valid search filter name");
            logger.warn(key + " is not a valid search filter name");
            continue;
        }

        Class<?> propertyClass = null;
        if (names.length == 3) {
            try {
                propertyClass = Enum.valueOf(PropertyType.class, names[2]).getValue();
                logger.debug(key + ":" + propertyClass.getName());
                if (propertyClass != null) {
                    if (propertyClass.getName().equals("java.util.Date")) {
                        String str = value.toString();
                        if (str.length() == 10) {
                            if (names[0].equals("GT") || names[0].equals("GTE")) {
                                str += " 00:00:00";
                            } else if (names[0].equals("LT") || names[0].equals("LTE")) {
                                str += " 23:59:59";
                            }
                        }
                        value = dateTimeFormat.parseObject(str);
                    } else {
                        //value = ConvertUtils.convert(value, propertyClass);
                    }

                }

            } catch (RuntimeException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            } catch (ParseException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            }
        }

        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:technology.tikal.customers.model.name.OrganizationNameIndexed.java

@Override
public String getIndex(String idIndex) {
    NamePriorityFilterValues type = Enum.valueOf(NamePriorityFilterValues.class, idIndex);
    if (type == NamePriorityFilterValues.Name || type == NamePriorityFilterValues.OrganizationName) {
        return this.normalizedOrganizationName;
    }/* w w w .j  ava  2s. c o m*/
    throw new IllegalArgumentException("tipo no soportado:" + type.toString());
}

From source file:com.manpowergroup.cn.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from w  w w  . j a  va2 s  .c  o  m
 *                   eg LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");

    this.propertyValue = value;
}

From source file:com.esofthead.mycollab.i18n.LocalizationHelper.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static String getMessage(Locale locale, Class cls, String option, Object... objects) {
    if (StringUtils.isBlank(option)) {
        return "";
    }/*w w  w  .j av  a2s . c o  m*/
    Enum key = Enum.valueOf(cls, option);
    try {
        IMessageConveyor messageConveyor = getMessageConveyor(locale);
        return messageConveyor.getMessage(key, objects);
    } catch (Exception e) {
        try {
            return defaultMessage.getMessage(key, objects);
        } catch (Exception e1) {
            LOG.error("Can not find resource key " + cls + "---" + option, e);
            return "Undefined";
        }
    }
}

From source file:ai.general.interbot.video.VideoInstruction.java

/**
 * Sets the instruction from the string representation of the instruction.
 * If the instruction is unsupported, it will be set to Undefined.
 *
 * @param instruction_name The string representation of the instruction.
 *///  ww  w  . j  a va  2  s.  c o  m
public void setInstruction(String instruction_name) {
    try {
        this.instruction_ = Enum.valueOf(Instruction.class, instruction_name);
    } catch (IllegalArgumentException e) {
        this.instruction_ = Instruction.Undefined;
    }
}

From source file:jp.ac.tokushima_u.is.ll.common.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from  ww w .  j av  a2s  .c  o  m
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtils.convertValue(value, propertyType);
}

From source file:org.guess.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*from   w ww .j  av a2s .  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 {
        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 = ConvertUtils.convertStringToObject(value, propertyClass);
}