Example usage for org.apache.commons.lang3 EnumUtils getEnumList

List of usage examples for org.apache.commons.lang3 EnumUtils getEnumList

Introduction

In this page you can find the example usage for org.apache.commons.lang3 EnumUtils getEnumList.

Prototype

public static <E extends Enum<E>> List<E> getEnumList(final Class<E> enumClass) 

Source Link

Document

Gets the List of enums.

This method is useful when you need a list of enums rather than an array.

Usage

From source file:com.github.dozermapper.core.converters.EnumConverter.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Object convert(Class destClass, Object srcObj) {
    if (null == srcObj) {
        MappingUtils.throwMappingException("Cannot convert null to enum of type " + destClass);
    }/*from  w  w w .  jav a  2s.c  o m*/

    try {
        if ((srcObj.getClass().equals(Byte.class)) || (srcObj.getClass().equals(Byte.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Byte) srcObj).intValue());
        } else if ((srcObj.getClass().equals(Short.class)) || (srcObj.getClass().equals(Short.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Short) srcObj).intValue());
        } else if ((srcObj.getClass().equals(Integer.class)) || (srcObj.getClass().equals(Integer.TYPE))) {
            return EnumUtils.getEnumList(destClass).get((Integer) srcObj);
        } else if ((srcObj.getClass().equals(Long.class)) || (srcObj.getClass().equals(Long.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Long) srcObj).intValue());
        } else {
            return Enum.valueOf(destClass, srcObj.toString());
        }
    } catch (Exception e) {
        MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e);
    }
    return srcObj;
}

From source file:com.tomoare.mybatis.type.EnumValueTypeHandler.java

/**
 *
 * @param value/*w w w.j a va2  s.c om*/
 * @return
 */
@Nullable
private E getEnum(@Nullable String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }

    List<E> enums = EnumUtils.getEnumList(type);
    if (enums == null || enums.isEmpty()) {
        return null;
    }

    for (E enm : enums) {
        if (((DbCodeConstant) enm).getCodeValue().equals(value)) {
            return enm;
        }
    }
    return null;
}

From source file:org.efaps.esjp.admin.common.systemconfiguration.EnumSysConfAttribute_Base.java

@Override
public CharSequence getHtml(final Parameter _parameter, final Object _value, final String _fieldName) {
    E val = null;
    if (_value != null) {
        val = EnumUtils.getEnum(this.clazz, (String) _value);
    }//from   www. j  a  va 2s. c  o  m
    final StringBuilder ret = new StringBuilder();
    for (final E e : EnumUtils.getEnumList(this.clazz)) {
        ret.append("<label tag=\"rem\"><input type=\"radio\" name=\"").append(_fieldName).append("\" value=\"")
                .append(e).append("\"");
        if (e.equals(val)) {
            ret.append(" checked=\"checked\" ");
        }
        ret.append(" >").append(e).append("</label><br/>");
    }
    return ret;
}

From source file:org.jbb.system.web.logging.controller.AcpLoggerController.java

private void putLoggingLevelsToModel(Model model) {
    model.addAttribute(LOGGING_LEVELS, EnumUtils.getEnumList(LogLevel.class).stream()
            .map(level -> capitalize(lowerCase(level.toString()))).collect(Collectors.toList()));
}

From source file:org.omnaest.utils.structure.map.MapUtils.java

/**
 * Returns an {@link EnumMap} filled with all available values of the given {@link Enum} type as keys and the result of the
 * {@link Factory} as value for each {@link Enum} key.
 * //from w ww .  j a v a2s  .com
 * @param enumType
 * @param factory
 * @return {@link EnumMap}
 */
public static <K extends Enum<K>, V> EnumMap<K, V> initializedEnumMap(Class<K> enumType, Factory<V> factory) {
    //    
    final EnumMap<K, V> retmap = enumType != null ? new EnumMap<K, V>(enumType) : null;

    //
    if (retmap != null) {
        for (K key : EnumUtils.getEnumList(enumType)) {
            V value = factory != null ? factory.newInstance() : null;
            retmap.put(key, value);
        }
    }

    //
    return retmap;
}

From source file:org.wrml.model.rest.ResourceOptionsTest.java

@Test
public void testGetSetAllow() {

    List<Method> mock = new ArrayList<Method>();
    mock.addAll(EnumUtils.getEnumList(Method.class));
    resourceOptions.setAllow(mock);/*from   ww  w.ja v a2s  . co m*/
    List<Method> other = resourceOptions.getAllow();
    assertEquals(mock.size(), other.size());
    assertEquals(mock, other);
}

From source file:ve.zoonosis.model.combomodel.EnumComboBoxModel.java

public EnumComboBoxModel(Class<? extends Enum> enumClass) {
    this.enumItems = EnumUtils.getEnumList(enumClass);
    index = -1;
}