Class EnumUtils
Utility class for accessing and manipulating Enums.
- Since:
- 2.1 (class existed in enum package from v1.0)
- Version:
- $Id: EnumUtils.java 905636 2010-02-02 14:03:32Z niallp $
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ValuedEnumGets aValuedEnumobject by class and value.static EnumGets anEnumobject by class and name.static ListgetEnumList(Class enumClass) Gets theListofEnumobjects using theEnumclass.static MapgetEnumMap(Class enumClass) Gets theMapofEnumobjects by name using theEnumclass.static IteratorGets anIteratorover theEnumobjects in anEnumclass.
-
Constructor Details
-
EnumUtils
public EnumUtils()Public constructor. This class should not normally be instantiated.- Since:
- 2.0
-
-
Method Details
-
getEnum
Gets an
Enumobject by class and name.- Parameters:
enumClass- the class of theEnumto getname- the name of the Enum to get, may benull- Returns:
- the enum object
- Throws:
IllegalArgumentException- if the enum class isnull
-
getEnum
Gets a
ValuedEnumobject by class and value.- Parameters:
enumClass- the class of theEnumto getvalue- the value of theEnumto get- Returns:
- the enum object, or null if the enum does not exist
- Throws:
IllegalArgumentException- if the enum class isnull
-
getEnumMap
Gets the
MapofEnumobjects by name using theEnumclass.If the requested class has no enum objects an empty
Mapis returned. TheMapis unmodifiable.- Parameters:
enumClass- the class of theEnumto get- Returns:
- the enum object Map
- Throws:
IllegalArgumentException- if the enum class isnullIllegalArgumentException- if the enum class is not a subclass ofEnum
-
getEnumList
Gets the
ListofEnumobjects using theEnumclass.The list is in the order that the objects were created (source code order).
If the requested class has no enum objects an empty
Listis returned. TheListis unmodifiable.- Parameters:
enumClass- the class of the Enum to get- Returns:
- the enum object Map
- Throws:
IllegalArgumentException- if the enum class isnullIllegalArgumentException- if the enum class is not a subclass ofEnum
-
iterator
Gets an
Iteratorover theEnumobjects in anEnumclass.The iterator is in the order that the objects were created (source code order).
If the requested class has no enum objects an empty
Iteratoris returned. TheIteratoris unmodifiable.- Parameters:
enumClass- the class of theEnumto get- Returns:
- an
Iteratorof theEnumobjects - Throws:
IllegalArgumentException- if the enum class isnullIllegalArgumentException- if the enum class is not a subclass ofEnum
-