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:edu.brown.statistics.AbstractStatistics.java

protected String debug(Database catalog_db, Enum<?> elements[]) {
    Map<String, Object> m = new ListOrderedMap<String, Object>();
    try {//  ww  w.j a va 2  s . c  o m
        Class<?> statsClass = this.getClass();
        for (Enum<?> element : elements) {
            Field field = statsClass.getDeclaredField(element.toString().toLowerCase());
            Object value = field.get(this);

            if (field.getClass().isAssignableFrom(SortedMap.class)) {
                SortedMap<?, ?> orig_value = (SortedMap<?, ?>) value;
                Map<String, Object> inner_m = new ListOrderedMap<String, Object>();
                for (Object inner_key : orig_value.keySet()) {
                    Object inner_val = orig_value.get(inner_key);
                    if (inner_val instanceof AbstractStatistics<?>) {
                        inner_val = ((AbstractStatistics<?>) inner_val).debug(catalog_db);
                    }
                    inner_m.put(inner_key.toString(), inner_val);
                } // FOR
                value = StringUtil.formatMaps(inner_m);
            }
            m.put(element.toString(), value);
        } // FOR
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(1);
    }
    return (String.format("%s\n%s", this.getCatalogItem(catalog_db),
            StringUtil.prefix(StringUtil.formatMaps(m), DEBUG_SPACER)));
}

From source file:org.fornax.cartridges.sculptor.framework.propertyeditor.EnumEditor.java

/**
 * Format the Enum as translated String/*from  w  ww .  jav a  2  s  . c  o m*/
 */
public String getAsText() {
    Enum<?> value = (Enum<?>) getValue();
    if (value == null) {
        return "";
    }

    String text = getMessagesAccessor().getMessage(messagesKeyPrefix + value.name(), (String) null);
    if (text == null) {
        return value.toString();
    } else {
        return text;
    }
}

From source file:heigit.ors.api.requests.common.GenericHandler.java

protected String convertAPIEnum(Enum valuesIn) {
    return valuesIn.toString();
}

From source file:fr.zcraft.zlib.components.commands.Command.java

protected <T extends Enum> T getEnumParameter(int index, Class<T> enumType) throws CommandException {
    Enum[] enumValues = enumType.getEnumConstants();
    String parameter = args[index].toLowerCase();

    for (Enum value : enumValues) {
        if (value.toString().toLowerCase().equals(parameter))
            return (T) value;
    }// w w  w .j av a  2  s  . com

    throw new CommandException(this, Reason.INVALID_PARAMETERS, invalidParameterString(index, enumValues));
}

From source file:org.openhealthtools.openexchange.actorconfig.Configuration.java

/**
* Translates an enum value into a Code appropriate for this actor or connection.
* 
* @param description the actor or connection being submitted to
* @param value the enum value used//ww  w  .j a  v a 2  s  . c  om
* @param enumType the enum Class for this value, ie. the name of the EnumMap to use for translation
* @param isRequired <code>true</code> if a translation of this value is required, False if the value can default to itself
* @return The translated Code
* @throws IheConfigurationException When the required EnumMap is not defined for this connection
*/

public static String applyEnumMap(IBaseDescription description, Enum value, Class enumType, boolean isRequired)
        throws IheConfigurationException {
    if (value == null) {
        if (isRequired)
            throw new IheConfigurationException("Invalid enum value (NULL)");
        return null;
    }
    if (enumType == null)
        throw new IheConfigurationException("Invalid enum type (NULL)");
    if (description == null)
        throw new IheConfigurationException("Invalid connection description (NULL)");
    EnumMap emap = description.getEnumMap(enumType);
    if (emap == null) {
        if (isRequired)
            throw new IheConfigurationException("No enum map to translate '" + enumType.getSimpleName()
                    + "' values for actor/connection \"" + description.getName() + "\"");
        return null;
    } else {
        String translation = emap.getCodeValue(value);
        if (isRequired && (translation == null))
            throw new IheConfigurationException("No translation of '" + value.toString() + "' in string map '"
                    + enumType.getSimpleName() + "' for actor/connection \"" + description.getName() + "\"");
        return translation;
    }
}

From source file:org.richfaces.tests.metamer.ftest.webdriver.Attributes.java

public void set(T attribute, Enum<?> item) {
    setProperty(attribute.toString(), item.toString());
}

From source file:org.wso2.carbon.identity.recovery.handler.AdminForcedPasswordResetHandler.java

protected void handleAuthenticate(Map<String, Object> eventProperties, UserStoreManager userStoreManager)
        throws IdentityEventException {
    User user = getUser(eventProperties, userStoreManager);

    if (log.isDebugEnabled()) {
        log.debug("PreAuthenticate - AdminForcedPasswordResetHandler for user : " + user.toString());
    }/*w ww .jav  a 2s  .  c o  m*/

    UserRecoveryData userRecoveryData = getRecoveryData(user);
    if (userRecoveryData != null) {

        Enum recoveryScenario = userRecoveryData.getRecoveryScenario();

        if (log.isDebugEnabled()) {
            log.debug("Handling recovery scenario : " + recoveryScenario.toString() + " for user : "
                    + user.toString());
        }

        String errorCode = null;
        String errorMsg = "User : " + user.toString();
        boolean isForcedPasswordReset = false;

        if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.equals(recoveryScenario)) {
            errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_EMAIL_LINK_ERROR_CODE;
            errorMsg = errorMsg + " needs to reset the password using the given link in email";
            isForcedPasswordReset = true;

        } else if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.equals(recoveryScenario)) {
            String credential = (String) eventProperties.get(IdentityEventConstants.EventProperty.CREDENTIAL);
            isForcedPasswordReset = true;

            if (userRecoveryData.getSecret().equals(credential)) {
                errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_OTP_ERROR_CODE;
                errorMsg = errorMsg + " has given correct OTP";
            } else {
                errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_OTP_MISMATCHED_ERROR_CODE;
                errorMsg = errorMsg + " has given in-correct OTP";
            }
        }

        if (isForcedPasswordReset) {
            if (log.isDebugEnabled()) {
                log.debug(errorMsg);
            }

            IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(errorCode);
            IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
            throw new IdentityEventException(errorMsg);
        }

    }
}

From source file:fr.zcraft.zlib.components.rawtext.RawTextPart.java

private String enumCamel(Enum enumValue) {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, enumValue.toString());
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

@SuppressWarnings("rawtypes")
protected String getEnum(Enum enumObj) {
    return enumObj.toString();
}

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

/**
 * Returns the statement value with the specified name.
 * <p>/*  w w  w.j av a2s .co  m*/
 *
 * The following statement returns ["foo", "bar"]:
 *
 * <pre>
 * statement "foo"
 * statement "bar"
 * </pre>
 *
 * @param name
 *            the {@link Enum} name.
 *
 * @return the {@link Set} of values or {@code null}.
 */
public <T> Set<T> tableValues(Enum<?> name) {
    return tableValues(name.toString());
}