org.apache.commons.lang.enum
Class EnumUtils

java.lang.Object
  |
  +--org.apache.commons.lang.enum.EnumUtils
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public abstract class EnumUtils
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Utility class for accessing and manipulating Enums.

Version:
$Id: EnumUtils.java,v 1.3 2002/09/28 10:49:59 scolebourne Exp $
Author:
Stephen Colebourne
See Also:
Enum, ValuedEnum, Serialized Form

Constructor Summary
private EnumUtils()
          Restricted constructor
 
Method Summary
static ValuedEnum getEnum(java.lang.Class enumClass, int value)
          Gets a ValuedEnum object by class and value.
static Enum getEnum(java.lang.Class enumClass, java.lang.String name)
          Gets an Enum object by class and name.
static java.util.List getEnumList(java.lang.Class enumClass)
          Gets the List of Enum objects using the Enum class.
static java.util.Map getEnumMap(java.lang.Class enumClass)
          Gets the Map of Enum objects by name using the Enum class.
static java.util.Iterator iterator(java.lang.Class enumClass)
          Gets an iterator over the Enum objects in an Enum class.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

EnumUtils

private EnumUtils()
Restricted constructor
Method Detail

getEnum

public static Enum getEnum(java.lang.Class enumClass,
                           java.lang.String name)
Gets an Enum object by class and name.
Parameters:
enumClass - the class of the Enum to get
name - the name of the Enum to get, may be null
Returns:
the enum object
Throws:
java.lang.IllegalArgumentException - if the enum class is null

getEnum

public static ValuedEnum getEnum(java.lang.Class enumClass,
                                 int value)
Gets a ValuedEnum object by class and value.
Parameters:
enumClass - the class of the Enum to get
value - the value of the Enum to get
Returns:
the enum object, or null if the enum does not exist
Throws:
java.lang.IllegalArgumentException - if the enum class is null

getEnumMap

public static java.util.Map getEnumMap(java.lang.Class enumClass)
Gets the Map of Enum objects by name using the Enum class. If the requested class has no enum objects an empty Map is returned. The Map is unmodifiable.
Parameters:
enumClass - the class of the Enum to get
Returns:
the enum object Map
Throws:
java.lang.IllegalArgumentException - if the enum class is null
java.lang.IllegalArgumentException - if the enum class is not a subclass of Enum

getEnumList

public static java.util.List getEnumList(java.lang.Class enumClass)
Gets the List of Enum objects using the Enum class. The list is in the order that the objects were created (source code order). If the requested class has no enum objects an empty List is returned. The List is unmodifiable.
Parameters:
enumClass - the class of the Enum to get
Returns:
the enum object Map
Throws:
java.lang.IllegalArgumentException - if the enum class is null
java.lang.IllegalArgumentException - if the enum class is not a subclass of Enum

iterator

public static java.util.Iterator iterator(java.lang.Class enumClass)
Gets an iterator over the Enum objects in an Enum class. The iterator is in the order that the objects were created (source code order). If the requested class has no enum objects an empty Iterator is returned. The Iterator is unmodifiable.
Parameters:
enumClass - the class of the Enum to get
Returns:
an iterator of the Enum objects
Throws:
java.lang.IllegalArgumentException - if the enum class is null
java.lang.IllegalArgumentException - if the enum class is not a subclass of Enum


Copyright (c) 2001-2002 - Apache Software Foundation