All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.jvm.sandbox.module.debug.util.GaEnumUtils Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.alibaba.jvm.sandbox.module.debug.util;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.EnumUtils;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * 枚举工具类
 *
 * @author [email protected]
 */
public class GaEnumUtils {

    public static > Set valuesOf(Class enumClass, String[] enumNameArray, T[] defaultEnumArray) {
        final Set enumSet = new LinkedHashSet();
        if (ArrayUtils.isNotEmpty(enumNameArray)) {
            for (final String enumName : enumNameArray) {
                final T enumValue = EnumUtils.getEnum(enumClass, enumName);
                if (null != enumValue) {
                    enumSet.add(enumValue);
                }
            }
        }
        if (CollectionUtils.isEmpty(enumSet)
                && ArrayUtils.isNotEmpty(defaultEnumArray)) {
            Collections.addAll(enumSet, defaultEnumArray);
        }
        return enumSet;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy