Example usage for java.lang Enum toString

List of usage examples for java.lang Enum toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the name of this enum constant, as contained in the declaration.

Usage

From source file:com.anrisoftware.sscontrol.core.groovy.statementstable.StatementsTable.java

/**
 * Returns the statement table values with the specified name.
 * <p>// w  w  w. j  a v a 2s .c om
 *
 * The following statements returns the table for the key "keyFoo"
 * {@code ["foo": "value1", "bar": "value2"]}
 *
 * <pre>
 * statement "foo", keyFoo: "value1"
 * statement "bar", keyFoo: "value2", keyBar: "value3"
 * </pre>
 *
 * @param name
 *            the {@link Enum} statement name.
 *
 * @param key
 *            the {@link String} key.
 *
 * @return the {@link Object} value or {@code null}.
 */
public <T> Map<String, T> tableKeys(Enum<?> name, String key) {
    return tableKeys(name.toString(), key);
}

From source file:com.anrisoftware.sscontrol.core.groovy.statementstable.StatementsTable.java

/**
 * Returns the statement table values with the specified name.
 * <p>// ww w . ja v a  2 s  . co m
 *
 * The following statements returns the table for the key "keyFoo"
 * {@code ["foo": "value1", "bar": "value2"]}
 *
 * <pre>
 * statement "foo", keyFoo: "value1"
 * statement "bar", keyFoo: "value2", keyBar: "value3"
 * </pre>
 *
 * @param name
 *            the {@link Enum} statement name.
 *
 * @param key
 *            the {@link Enum} key.
 *
 * @return the {@link Object} value or {@code null}.
 */
public <T> Map<String, T> tableKeys(Enum<?> name, Enum<?> key) {
    return tableKeys(name.toString(), key.toString());
}

From source file:com.anrisoftware.sscontrol.core.groovy.statementstable.StatementsTable.java

/**
 * Returns the statement table values with the specified name.
 * <p>/*w  w  w  .  j  a v  a 2  s .  c  o  m*/
 *
 * The following statements returns the table for the key "keyFoo"
 * {@code ["foo": ["value1"], "bar": ["value2", "value3"]]}
 *
 * <pre>
 * statement "foo", keyFoo: "value1"
 * statement "bar", keyFoo: "value2, value3", keyBar: "value4"
 * </pre>
 *
 * @param name
 *            the {@link Enum} statement name.
 *
 * @param key
 *            the {@link Enum} key.
 *
 * @return the {@link Object} value or {@code null}.
 */
public <T> Map<String, List<T>> tableKeysAsList(Enum<?> name, Enum<?> key) {
    return tableKeysAsList(name.toString(), key.toString());
}

From source file:org.rundeck.api.ApiPathBuilder.java

/**
 * Append the given parameter (key and value). This will only append the parameter if it is not null, and make sure
 * to add the right separator ("?" or "&") before. The key and value will be separated by the "=" character. Also,
 * the value will be converted to lower-case.
 *
 * @param key of the parameter. Must not be null or empty
 * @param value of the parameter. May be null
 * @return this, for method chaining/*w  w w .  j ava 2s. c o  m*/
 */
public ApiPathBuilder param(String key, Enum<?> value) {
    if (value != null) {
        param(key, StringUtils.lowerCase(value.toString()));
    }
    return this;
}

From source file:org.apache.pig.backend.hadoop.executionengine.tez.TezLauncher.java

private void computeWarningAggregate(Map<String, Map<String, Long>> counterGroups, Map<Enum, Long> aggMap) {
    for (Map<String, Long> counters : counterGroups.values()) {
        for (Enum e : PigWarning.values()) {
            if (counters.containsKey(e.toString())) {
                if (aggMap.containsKey(e.toString())) {
                    Long currentCount = aggMap.get(e.toString());
                    currentCount = (currentCount == null ? 0 : currentCount);
                    if (counters != null) {
                        currentCount += counters.get(e.toString());
                    }/* w  w w  . j a  v  a 2  s  .c o  m*/
                    aggMap.put(e, currentCount);
                } else {
                    aggMap.put(e, counters.get(e.toString()));
                }
            }
        }
    }
}

From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java

/**
 * Validate enum version value./*  www. ja  v a 2s  . co m*/
 *
 * @param enumValue      the enum value
 * @param requestVersion the request version
 * @throws ServiceVersionException the service version exception
 */
public static void validateEnumVersionValue(Enum<?> enumValue, ExchangeVersion requestVersion)
        throws ServiceVersionException {
    final Map<Class<?>, Map<String, ExchangeVersion>> member = ENUM_VERSION_DICTIONARIES.getMember();
    final Map<String, ExchangeVersion> enumVersionDict = member.get(enumValue.getClass());

    final ExchangeVersion enumVersion = enumVersionDict.get(enumValue.toString());
    if (enumVersion != null) {
        final int i = requestVersion.compareTo(enumVersion);
        if (i < 0) {
            throw new ServiceVersionException(String.format(
                    "Enumeration value %s in enumeration type %s is only valid for Exchange version %s or later.",
                    enumValue.toString(), enumValue.getClass().getName(), enumVersion));
        }
    }
}

From source file:com.scaleunlimited.cascading.FlowMonitor.java

@SuppressWarnings("rawtypes")
private String getTableHeader(FlowStep flowStep, Enum... counters) {
    StringBuilder header = new StringBuilder();
    for (Enum counter : counters) {
        header.append("<td>");
        header.append(StringEscapeUtils.escapeHtml(counter.toString()));
        header.append("</td>");
    }//from ww w.  j av  a2s  . co m

    for (IMonitorTask task : _tasks) {
        header.append("<td>");
        header.append(StringEscapeUtils.escapeHtml(task.getName(_flow, flowStep)));
        header.append("</td>");
    }

    if (_includeCascadingCounters) {
        for (Enum counter : StepCounters.values()) {
            header.append("<td>");
            header.append(StringEscapeUtils.escapeHtml(counter.toString()));
            header.append("</td>");
        }
    }

    return header.toString();
}

From source file:kg.apc.jmeter.config.redis.RedisDataSet.java

/**
 * Override the setProperty method in order to convert
 * the original String calcMode property.
 * This used the locale-dependent display value, so caused
 * problems when the language was changed.
 * Note that the calcMode StringProperty is replaced with an IntegerProperty
 * so the conversion only needs to happen once.
 *///from  www  . jav  a  2s  .  com
@Override
public void setProperty(JMeterProperty property) {
    if (property instanceof StringProperty) {
        final String pn = property.getName();
        if (pn.equals("getMode")) {
            final Object objectValue = property.getObjectValue();
            try {
                final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
                final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor()
                        .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
                for (Enum<GetMode> e : GetMode.values()) {
                    final String propName = e.toString();
                    if (objectValue.equals(rb.getObject(propName))) {
                        final int tmpMode = e.ordinal();
                        if (log.isDebugEnabled()) {
                            log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode
                                    + " using Locale: " + rb.getLocale());
                        }
                        super.setProperty(pn, tmpMode);
                        return;
                    }
                }
                log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
            } catch (IntrospectionException e) {
                log.error("Could not find BeanInfo", e);
            }
        } else if (pn.equals("whenExhaustedAction")) {
            final Object objectValue = property.getObjectValue();
            try {
                final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
                final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor()
                        .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
                for (Enum<WhenExhaustedAction> e : WhenExhaustedAction.values()) {
                    final String propName = e.toString();
                    if (objectValue.equals(rb.getObject(propName))) {
                        final int tmpMode = e.ordinal();
                        if (log.isDebugEnabled()) {
                            log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode
                                    + " using Locale: " + rb.getLocale());
                        }
                        super.setProperty(pn, tmpMode);
                        return;
                    }
                }
                log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
            } catch (IntrospectionException e) {
                log.error("Could not find BeanInfo", e);
            }
        }
    }
    super.setProperty(property);
}

From source file:de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer.java

private Map<String, Object> getTerms(Object bean, Class<?> mixInClass)
        throws IntrospectionException, IllegalAccessException, NoSuchFieldException {
    // define terms from package or type in context
    final Class<?> beanClass = bean.getClass();
    Map<String, Object> termsMap = getAnnotatedTerms(beanClass.getPackage(), beanClass.getPackage().getName());
    Map<String, Object> classTermsMap = getAnnotatedTerms(beanClass, beanClass.getName());
    Map<String, Object> mixinTermsMap = getAnnotatedTerms(mixInClass, beanClass.getName());

    // class terms override package terms
    termsMap.putAll(classTermsMap);//  w  ww .  j a va 2s.  c  om
    // mixin terms override class terms
    termsMap.putAll(mixinTermsMap);

    final Field[] fields = beanClass.getDeclaredFields();
    for (Field field : fields) {
        final Expose fieldExpose = field.getAnnotation(Expose.class);
        if (Enum.class.isAssignableFrom(field.getType())) {
            Map<String, String> map = new LinkedHashMap<String, String>();
            termsMap.put(field.getName(), map);
            if (fieldExpose != null) {
                map.put(AT_ID, fieldExpose.value());
            }
            map.put(AT_TYPE, AT_VOCAB);
            final Enum value = (Enum) field.get(bean);
            final Expose enumValueExpose = getAnnotation(value.getClass().getField(value.name()), Expose.class);
            // TODO redefine actual enum value to exposed on enum value definition
            if (enumValueExpose != null) {
                termsMap.put(value.toString(), enumValueExpose.value());
            } else {
                // might use upperToCamelCase if nothing is exposed
                final String camelCaseEnumValue = WordUtils
                        .capitalizeFully(value.toString(), new char[] { '_' }).replaceAll("_", "");
                termsMap.put(value.toString(), camelCaseEnumValue);
            }
        } else {
            if (fieldExpose != null) {
                termsMap.put(field.getName(), fieldExpose.value());
            }
        }
    }

    // TODO do this recursively for nested beans and collect as long as
    // nested beans have same vocab
    // expose getters in context
    final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
    final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        final Method method = propertyDescriptor.getReadMethod();

        final Expose expose = method.getAnnotation(Expose.class);
        if (expose != null) {
            termsMap.put(propertyDescriptor.getName(), expose.value());
        }
    }
    return termsMap;
}