日期:2014-05-16  浏览次数:20945 次

Apache 枚举工具类的源码的分析

Apache commons-lang报的枚举工具类的学习应用:

他提供的根据枚举的类方法如下逐个分析

备注咋Apache commons-lang中枚举对象(Enum是一个封装枚举类而非枚举类型)

?

public class EnumUtils {

??? /**
???? * Public constructor. This class should not normally be instantiated.
???? * @since 2.0
???? */
??? public EnumUtils() {
????? super();
??? }

??? /**

??? * 根据枚举类和类型类型的名称(value)查找枚举
???? * <p>Gets an <code>Enum</code> object by class and name.</p>
???? *
???? * @param enumClass? the class of the <code>Enum</code> to get
???? * @param name? the name of the Enum to get, may be <code>null</code>
???? * @return the enum object
???? * @throws IllegalArgumentException if the enum class is <code>null</code>
???? */
??? public static Enum getEnum(Class enumClass, String name) {
??????? return Enum.getEnum(enumClass, name);
??? }

??? /**根据枚举类和枚举键查找
???? * <p>Gets a <code>ValuedEnum</code> object by class and value.</p>
???? *
???? * @param enumClass? the class of the <code>Enum</code> to get
???? * @param value? the value of the <code>Enum</code> to get
???? * @return the enum object, or null if the enum does not exist
???? * @throws IllegalArgumentException if the enum class is <code>null</code>
???? */
??? public static ValuedEnum getEnum(Class enumClass, int value) {
??????? return (ValuedEnum) ValuedEnum.getEnum(enumClass, value);
??? }

??? /**根据枚举类查找所有枚举类型的Map
???? * <p>Gets the <code>Map</code> of <code>Enum</code> objects by
???? * name using the <code>Enum</code> class.</p>
???? *
???? * <p>If the requested class has no enum objects an empty
???? * <code>Map</code> is returned. The <code>Map</code> is unmodifiable.</p>
???? *
???? * @param enumClass? the class of the <code>Enum</code> to get
???? * @return the enum object Map
???? * @throws IllegalArgumentException if the enum class is <code>null</code>
???? * @throws IllegalArgumentException if the enum class is not a subclass
???? *? of <code>Enum</code>
???? */
??? public static Map getEnumMap(Class enumClass) {
??????? return Enum.getEnumMap(enumClass);
??? }

??? /**根据枚举类所有枚举类型集合
???? * <p>Gets the <code>List</code> of <code>Enum</code> objects using
???? * the <code>Enum</code> class.</p>
???? *
???? * <p>The list is in the order that the objects were created
???? * (source code order).</p>
???? *
???? * <p>If the requested class has no enum objects an empty
???? * <code>List</code> is returned. The <code>List</code> is unmodifiable.</p>
???? *
???? * @param enumClass? the class of the Enum to get
???? * @return the enum object Map
???? * @throws IllegalArgumentException if the enum class is <code>null</code>
???? * @throws IllegalArgumentException if the enum class is not a subclass
???? *? of <code>Enum</code>
???? */
??? public static List getEnumList(Class enumClass) {
??????? return Enum.getEnumList(enumClass);
??? }

??? /**
???? * <p>Gets an <code>Iterator</code> over the <code>Enum</code> objects
???? * in an <code>Enum</code> class.</p>
???? *
???? * <p>The iterator is in the order that the objects were created
???? * (source code order).</p>
???? *
???? * <p>If the requested class has no enum objects an empty
???? * <code>Iterator</code> is returned. The <code>Iterator</code>
???? * is unmodifiable.</p>
???? *
???? * @param enumClass? the class of the <code>