Example usage for java.lang Enum name

List of usage examples for java.lang Enum name

Introduction

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

Prototype

String name

To view the source code for java.lang Enum name.

Click Source Link

Document

The name of this enum constant, as declared in the enum declaration.

Usage

From source file:org.dozer.MappingProcessor.java

private <T extends Enum<T>> T mapEnum(Enum<T> srcFieldValue, Class<T> destFieldType) {
    String name = srcFieldValue.name();
    return Enum.valueOf(destFieldType, name);
}

From source file:com.haulmont.cuba.core.sys.AbstractMessages.java

@Override
public String getMessage(Enum caller, Locale locale) {
    checkNotNullArgument(caller, "Enum parameter 'caller' is null");

    String className = caller.getClass().getName();
    int i = className.lastIndexOf('.');
    if (i > -1)
        className = className.substring(i + 1);
    // If enum has inner subclasses, its class name ends with "$1", "$2", ... suffixes. Cut them off.
    Matcher matcher = enumSubclassPattern.matcher(className);
    if (matcher.find()) {
        className = className.substring(0, matcher.start());
    }/*from  w w  w  . j  av a  2 s  .c o  m*/

    return getMessage(getPackName(caller.getClass()), className + "." + caller.name(), locale);
}

From source file:com.evolveum.midpoint.gui.api.page.PageBase.java

public static String createEnumResourceKey(Enum e) {
    return e.getDeclaringClass().getSimpleName() + "." + e.name();
}

From source file:com.flexive.shared.FxSharedUtils.java

/**
 * Extracts the names of the given enum elements and returns them as string.
 * Useful if the toString() method of the Enum class was overwritten.
 *
 * @param values the enum values//  w w w .j  a  v a 2s .co m
 * @return the names of the given enum elements
 */
public static List<String> getEnumNames(Collection<? extends Enum> values) {
    final List<String> result = new ArrayList<String>(values.size());
    for (final Enum value : values) {
        result.add(value.name());
    }
    return result;
}

From source file:com.github.dozermapper.core.MappingProcessor.java

private <T extends Enum<T>> T mapEnum(Enum<T> srcFieldValue, Class<T> destFieldType) {
    String name = srcFieldValue.name();
    return Enum.valueOf(getSerializableEnumClass(destFieldType), name);
}

From source file:com.complexible.pinto.RDFMapper.java

private IRI enumToURI(final Enum theEnum) {
    try {//from  w  w w.j av  a 2  s. co m
        final Iri aAnnotation = theEnum.getClass().getField(theEnum.name()).getAnnotation(Iri.class);

        if (aAnnotation != null) {
            return iri(aAnnotation.value());
        } else {
            return mValueFactory.createIRI(mDefaultNamespace, theEnum.name());
        }
    } catch (NoSuchFieldException e) {
        throw new AssertionError();
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

/**
 * Checks attribute if it has to be written to LDAP or removed from LDAP if attribute = null, its like not set.
 * //w  w w.ja v  a 2  s.c  o m
 * @param pOrgAtt: ConstEnumOrgStatus or ConstEnumOrgSector
 * @param pOldOrgAtt
 * @param ldapAttributeName
 * @param vOrgAttributes
 * @param vOrgRemoveAttributes
 * @param isUpdate
 */
private boolean checkAttribute(Enum<?> pOrgAtt, Enum<?> pOldOrgAtt, String ldapAttributeName,
        Attributes vOrgAttributes, Attributes vOrgRemoveAttributes, boolean isUpdate) {
    boolean hasChanged = false;
    if (!isUpdate) {
        if (pOldOrgAtt != null && pOrgAtt != null) {
            vOrgAttributes.put(new BasicAttribute(ldapAttributeName, String.valueOf(pOrgAtt.name())));
        }
    } else {
        if ((pOrgAtt != null) && ((pOldOrgAtt == null) || (pOldOrgAtt != pOrgAtt))) {
            vOrgAttributes.put(ldapAttributeName, String.valueOf(pOrgAtt));
            hasChanged = true;
        } else if ((pOrgAtt == null) && (pOldOrgAtt != null)) {
            vOrgRemoveAttributes.put(new BasicAttribute(ldapAttributeName));
            hasChanged = true;
        }
    }
    return hasChanged;
}

From source file:at.treedb.db.Base.java

/**
 * Field constraint - given text field of an entity must be unique over all
 * domains.//  ww  w .j a  v a 2  s  .c  o m
 * 
 * @param dao
 *            {@code DAOiface} (data access object)
 * @param update
 *            update data
 * @param dbID
 *            DB ID of the entity
 * @param fieldName
 *            text field name
 * @param value
 *            field value
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static void checkConstraint(DAOiface dao, UpdateMap update, int dbID, Enum<?> fieldName, String value)
        throws Exception {
    List<Base> list = null;
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("status", at.treedb.db.HistorizationIface.STATUS.ACTIVE);
    String entry = fieldName.name();
    Class<?> clazz = fieldName.getDeclaringClass().getDeclaringClass();
    if (update == null) {
        map.put(entry, value);
        list = (List<Base>) dao.query("select i from " + clazz.getSimpleName() + " i where i." + entry + " = :"
                + entry + " and i.status = :status", map);
    } else {
        Update m = update.get(fieldName);
        if (m != null) {
            map.put("histId", dbID);
            map.put(entry, m.getString());
            list = (List<Base>) dao.query("select i from " + clazz.getSimpleName() + " i where i." + entry
                    + " = :" + entry + " and i.status = :status and i.histId <> :histId", map);
        }
    }
    if (list != null && list.size() > 0) {
        throw new Exception(
                clazz.getSimpleName() + ".checkConstraints(): Property " + entry + " isn't unique:" + value);
    }
}

From source file:at.treedb.db.Base.java

/**
 * Field constraint - given text field of an entity must be unique for a
 * domain.//from  w  w  w  .j a va  2s . c o  m
 * 
 * @param dao
 *            {@code DAOiface} (data access object)
 * @param update
 *            update data
 * @param domain
 *            {@code Domain} of the entity
 * @param dbID
 *            ID of the entity
 * @param fieldName
 *            text field name
 * @param value
 *            field value
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static void checkConstraintPerDomain(DAOiface dao, UpdateMap update, int domain, int dbID,
        Enum<?> fieldName, String value) throws Exception {
    List<Base> list = null;
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("domain", domain);
    map.put("status", at.treedb.db.HistorizationIface.STATUS.ACTIVE);
    String entry = fieldName.name();
    Class<?> clazz = fieldName.getDeclaringClass().getDeclaringClass();
    if (update == null) {
        map.put(entry, value);
        list = (List<Base>) dao.query("select i from " + clazz.getSimpleName()
                + " i where i.domain = :domain and i." + entry + " = :" + entry + " and i.status = :status",
                map);
    } else {
        Update m = update.get(fieldName);
        if (m != null) {
            map.put("histId", dbID);
            map.put("name", m.getString());
            list = (List<Base>) dao
                    .query("select i from " + clazz.getSimpleName() + " i where i.domain = :domain and i."
                            + entry + " = :" + entry + " and i.status = :status and i.histId <> :histId", map);
        }
    }
    if (list != null && list.size() > 0) {
        throw new Exception(
                clazz.getSimpleName() + ".checkConstraints(): Property " + entry + " isn't unique:" + value);
    }
}

From source file:at.treedb.db.Base.java

/**
 * Field constraint - given text field of a entity must be unique for a CI.
 * /*from   ww  w  .ja  va2 s.c  om*/
 * @param dao
 *            {@code DAOiface} (data access object)
 * @param update
 *            update data
 * @param domain
 *            {@code Domain} of the entity
 * @param ciID
 *            ID of the CI
 * @param dbID
 *            DB ID of the entity
 * @param fieldName
 *            text field name
 * @param value
 *            field value
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static void checkConstraintsPerCI(DAOiface dao, UpdateMap update, int domain, int ciID, int dbID,
        Enum<?> fieldName, String value) throws Exception {
    List<Base> list = null;
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("domain", domain);
    map.put("status", at.treedb.db.HistorizationIface.STATUS.ACTIVE);
    Class<?> clazz = fieldName.getDeclaringClass().getDeclaringClass();
    String entry = fieldName.name();
    if (update == null) {
        map.put(entry, value);
        map.put("ciId", ciID);
        list = (List<Base>) dao
                .query("select i from " + clazz.getSimpleName() + " i where i.domain = :domain and i." + entry
                        + " = :" + entry + " and i.status = :status and i.ci = :ciId", map);
    } else {
        Update m = update.get(fieldName);
        if (m != null) {
            map.put("histId", dbID);
            map.put("ciId", ciID);
            map.put("name", m.getString());
            list = (List<Base>) dao.query("select i from " + clazz.getSimpleName()
                    + " i where i.domain = :domain and i." + entry + " = :" + entry
                    + " and i.ci =:ciId and i.status = :status and i.histId <> :histId", map);
        }
    }
    if (list != null && list.size() > 0) {
        throw new Exception(
                clazz.getSimpleName() + ".checkConstraints(): Property " + entry + " isn't unique:" + value);
    }
}