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.switchfly.inputvalidation.RequestParameter.java

public <E extends Enum<E>> E toEnum(Class<E> type) {
    String value = toString();/*from w  ww.  jav a2  s  .c  o m*/
    try {
        return Enum.valueOf(type, value.toUpperCase());
    } catch (Exception e) {
        throw new InvalidRequestParameterException(getName(), value);
    }
}

From source file:com.bsi.summer.core.dao.PropertyFilter.java

/**
 * @param filterName ,???. //from   w  ww .ja  v a  2 s . c  om
 *                      FILTER_LIKES_NAME_OR_LOGIN_NAME
 *                   
 *                value "SYS_" ??? 
 * 
 * @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);
    } 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);
    if (StringUtils.split(value, "-").length == 1) {
        this.matchValue = getValue(value);
    } else {
        this.matchValue = getValue(StringUtils.split(value, "-")[0]);
        this.matchBetweenValue = getValue(StringUtils.split(value, "-")[1]);
    }
}

From source file:ch.qos.logback.ext.spring.DelegatingLogbackAppender.java

public void setCacheMode(String mode) {
    cacheMode = Enum.valueOf(EventCacheMode.class, mode.toUpperCase());
}

From source file:com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck.java

/**
 * Sets the line separator to one of 'crlf', 'lf','cr', 'lf_cr_crlf' or 'system'.
 *
 * @param lineSeparatorParam The line separator to set
 * @throws IllegalArgumentException If the specified line separator is not
 *         one of 'crlf', 'lf', 'cr', 'lf_cr_crlf' or 'system'
 */// w ww.j ava2s.co m
public void setLineSeparator(String lineSeparatorParam) {
    try {
        lineSeparator = Enum.valueOf(LineSeparatorOption.class,
                lineSeparatorParam.trim().toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException iae) {
        throw new ConversionException("unable to parse " + lineSeparatorParam, iae);
    }
}

From source file:org.rhq.enterprise.gui.ha.ListPartitionEventsUIBean.java

public PartitionEvent.ExecutionStatus getExecutionStatus() {
    String executionStatusName = getExecutionStatusFilter();
    if (executionStatusName != null) {
        return Enum.valueOf(PartitionEvent.ExecutionStatus.class, executionStatusName);
    }//  w  w w  .  ja  v a  2 s.  c  o m
    return null;
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java

public Object getDriver() {
    if (driver == null) {
        browser = Enum.valueOf(WebBrowser.class, BehaveConfig.getRunner_ScreenType());
        driver = browser.getWebDriver();
        if (BehaveConfig.getRunner_WindowMaximizeEnabled()) {
            driver.manage().window().maximize();
        }//from   w w w.j a  v  a  2s  .  co m
        logger.debug(message.getString("message-webdriver-started", browser.toString()));
        try {
            driver.manage().timeouts().pageLoadTimeout(BehaveConfig.getRunner_ScreenMaxWait(),
                    TimeUnit.MILLISECONDS);
            driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(),
                    TimeUnit.MILLISECONDS);
        } catch (UnsupportedCommandException e) {
            logger.error(message.getString("message-configure-timeout", browser.toString()), e);
        }
    }
    return driver;
}

From source file:edu.psu.iam.cpr.core.util.Utility.java

/**
 * This routine is used to convert a string to an enumerated type.
 *
 * @param enumClass   Contains the enumerated type's class.
 * @param stringValue Contains the string that will be used to convert to an enum.
 * @return will return the enumerated value if successful.
 *///from ww w  .  ja va2s.co m
public static <T extends Enum<T>> T getEnumFromString(final Class<T> enumClass, final String stringValue) {
    if (enumClass != null && stringValue != null) {
        try {
            return Enum.valueOf(enumClass, stringValue.trim().toUpperCase());
        } catch (final IllegalArgumentException ex) {
        }
    }
    return null;
}

From source file:org.sonar.api.server.ws.internal.ValidatingRequest.java

@CheckForNull
@Override/*w w  w .  ja v a  2  s  .  c  om*/
public <E extends Enum<E>> List<E> paramAsEnums(String key, Class<E> enumClass) {
    List<String> values = paramAsStrings(key);
    if (values == null) {
        return null;
    }
    return values.stream().map(value -> Enum.valueOf(enumClass, value)).collect(Collectors.toList());
}

From source file:edu.utah.further.core.api.discrete.EnumUtil.java

/**
 * Convert a string to an enum. Encapsulates unchecked warning suppression.
 *
 * @param enumType//from ww w  . j av  a2  s  .  c  om
 * @param value
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Enum<?> valueOf(final Class<?> enumType, final String value) {
    return Enum.valueOf((Class<Enum>) enumType, value);
}

From source file:com.android.tests.lib.LibUnitTest.java

@Test
public void enums() throws Exception {
    assertNotNull(AsyncTask.Status.RUNNING);
    assertNotEquals(AsyncTask.Status.RUNNING, AsyncTask.Status.FINISHED);

    assertEquals(AsyncTask.Status.FINISHED, AsyncTask.Status.valueOf("FINISHED"));
    assertEquals(1, AsyncTask.Status.PENDING.ordinal());
    assertEquals("RUNNING", AsyncTask.Status.RUNNING.name());

    assertEquals(AsyncTask.Status.RUNNING, Enum.valueOf(AsyncTask.Status.class, "RUNNING"));

    AsyncTask.Status[] values = AsyncTask.Status.values();
    assertEquals(3, values.length);// w  w w.j  a va  2s . c om
    assertEquals(AsyncTask.Status.FINISHED, values[0]);
    assertEquals(AsyncTask.Status.PENDING, values[1]);
    assertEquals(AsyncTask.Status.RUNNING, values[2]);
}