com.sun.n1.util.enum
Class EnumFactoryImpl

java.lang.Object
  extended by com.sun.n1.util.enum.EnumFactoryImpl
All Implemented Interfaces:
EnumFactory
Direct Known Subclasses:
EnumFactoryXImpl

public abstract class EnumFactoryImpl
extends java.lang.Object
implements EnumFactory

This class is the base implementation of the Enumumeration types. Its not meant to be used directly, only subclasses should be used.


Constructor Summary
protected EnumFactoryImpl()
          Creates a new enumeration factory with a default expected size.
protected EnumFactoryImpl(int expectedSize)
          Creates a new enum factory that is expected to contain the passed number of enums.
 
Method Summary
 Enum[] getAllEnums(Enum[] container)
          Returns an array of all enums.
 Enum getEnum(int value)
          Returns the enum associated with the passed int value.
 Enum getEnum(java.lang.String value)
          Returns the enum associated with the passed string value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumFactoryImpl

protected EnumFactoryImpl()
Creates a new enumeration factory with a default expected size.


EnumFactoryImpl

protected EnumFactoryImpl(int expectedSize)
Creates a new enum factory that is expected to contain the passed number of enums. The actual number of enums may vary from the expected number. However, performance and memory consumption is optimal when the expected size is equal to the actual size.

Parameters:
expectedSize - the expected number of enums
Method Detail

getEnum

public Enum getEnum(java.lang.String value)
             throws NoSuchEnumException
Returns the enum associated with the passed string value. If no such enum exists an exception is raised.

Note: subclasses of EnumFactory will typcially provide a strongly-typed variant of this method named "get".

Specified by:
getEnum in interface EnumFactory
Parameters:
value - the string value of the desired enum.
Returns:
the enum associated with the passed value.
Throws:
NoSuchEnumException - if no such enum exists.

getEnum

public Enum getEnum(int value)
             throws NoSuchEnumException
Returns the enum associated with the passed int value. If no such enum exists an exception is raised.

Note: subclasses of EnumFactory will typcially provide a strongly-typed variant of this method named "get".

Specified by:
getEnum in interface EnumFactory
Parameters:
value - the int value of the desired enum.
Returns:
the enum associated with the passed value.
Throws:
NoSuchEnumException - if no such enum exists.

getAllEnums

public Enum[] getAllEnums(Enum[] container)
Returns an array of all enums. If the passed array is large enough to contain all the enums, it is used. Otherwise, a new array with the same runtime type of the passed array is created and used instead.

Note: Subclasses of EnumFactory typically provide a strongly-typed no-arg variant of this method named "getAll".

Specified by:
getAllEnums in interface EnumFactory
Returns:
an array of all enums.