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

jacky的部落 2009-12-15

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

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

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

public class EnumUtils {

    /**

*Publicconstructor.Thisclassshouldnotnormallybeinstantiated.

*@since2.0

*/

publicEnumUtils(){

super();

    }

    /**

    * 根据枚举类和类型类型的名称(value)查找枚举

*<p>Getsan<code>Enum</code>objectbyclassandname.</p>

*

*@paramenumClasstheclassofthe<code>Enum</code>toget

*@paramnamethenameoftheEnumtoget,maybe<code>null</code>

*@returntheenumobject

*@throwsIllegalArgumentExceptioniftheenumclassis<code>null</code>

*/

publicstaticEnumgetEnum(ClassenumClass,Stringname){

returnEnum.getEnum(enumClass,name);

    }

    /**根据枚举类和枚举键查找

*<p>Getsa<code>ValuedEnum</code>objectbyclassandvalue.</p>

*

*@paramenumClasstheclassofthe<code>Enum</code>toget

*@paramvaluethevalueofthe<code>Enum</code>toget

*@returntheenumobject,ornulliftheenumdoesnotexist

*@throwsIllegalArgumentExceptioniftheenumclassis<code>null</code>

*/

publicstaticValuedEnumgetEnum(ClassenumClass,intvalue){

return(ValuedEnum)ValuedEnum.getEnum(enumClass,value);

    }

    /**根据枚举类查找所有枚举类型的Map

*<p>Getsthe<code>Map</code>of<code>Enum</code>objectsby

*nameusingthe<code>Enum</code>class.</p>

*

*<p>Iftherequestedclasshasnoenumobjectsanempty

*<code>Map</code>isreturned.The<code>Map</code>isunmodifiable.</p>

*

*@paramenumClasstheclassofthe<code>Enum</code>toget

*@returntheenumobjectMap

*@throwsIllegalArgumentExceptioniftheenumclassis<code>null</code>

*@throwsIllegalArgumentExceptioniftheenumclassisnotasubclass

*of<code>Enum</code>

*/

publicstaticMapgetEnumMap(ClassenumClass){

returnEnum.getEnumMap(enumClass);

    }

    /**根据枚举类所有枚举类型集合

*<p>Getsthe<code>List</code>of<code>Enum</code>objectsusing

*the<code>Enum</code>class.</p>

*

*<p>Thelistisintheorderthattheobjectswerecreated

*(sourcecodeorder).</p>

*

*<p>Iftherequestedclasshasnoenumobjectsanempty

*<code>List</code>isreturned.The<code>List</code>isunmodifiable.</p>

*

*@paramenumClasstheclassoftheEnumtoget

*@returntheenumobjectMap

*@throwsIllegalArgumentExceptioniftheenumclassis<code>null</code>

*@throwsIllegalArgumentExceptioniftheenumclassisnotasubclass

*of<code>Enum</code>

*/

publicstaticListgetEnumList(ClassenumClass){

returnEnum.getEnumList(enumClass);

    }

    /**

*<p>Getsan<code>Iterator</code>overthe<code>Enum</code>objects

*inan<code>Enum</code>class.</p>

*

*<p>Theiteratorisintheorderthattheobjectswerecreated

*(sourcecodeorder).</p>

*

*<p>Iftherequestedclasshasnoenumobjectsanempty

*<code>Iterator</code>isreturned.The<code>Iterator</code>

*isunmodifiable.</p>

*

*@paramenumClasstheclassofthe<code>Enum</code>toget

*@returnan<code>Iterator</code>ofthe<code>Enum</code>objects

*@throwsIllegalArgumentExceptioniftheenumclassis<code>null</code>

*@throwsIllegalArgumentExceptioniftheenumclassisnotasubclassof<code>Enum</code>

*/

publicstaticIteratoriterator(ClassenumClass){

returnEnum.getEnumList(enumClass).iterator();

}

}

相关推荐