com.plotnix.enum
Class Enum

java.lang.Object
  |
  +--com.plotnix.enum.Enum
All Implemented Interfaces:
java.io.Serializable

public class Enum
extends java.lang.Object
implements java.io.Serializable

Enum represents a value characterized by the following properties:

Static methods of the Enum class support:

Version:
$Revision$ $Date$
Author:
Dmitri Plotnikov
See Also:
Serialized Form

Constructor Summary
protected Enum()
          Initialize the Enum, using default integer and string values.
protected Enum(int integer)
          Initialize the Enum with an integer value.
protected Enum(int integer, java.lang.String label)
          Initialize the Enum with an integer value and a default label.
protected Enum(java.lang.String string)
          Initialize the Enum with a string value.
protected Enum(java.lang.String string, java.lang.String label)
          Initialize the Enum with a string value and a default label.
 
Method Summary
static Enum[] enum(java.lang.Class enumClass)
          Returns an array of all Enums of the specified class in the order they were created.
static Enum enum(java.lang.Class enumClass, int integer)
          Returns the Enum of the specified class that has the specified integer value, or null if there is no such Enum.
static Enum enum(java.lang.Class enumClass, java.lang.String string)
          Returns the Enum of the specified class that has the specified st, or null if there is no such Enum.
protected static void initIntegerEnum(java.lang.Class enumClass)
           
 int intValue()
          Returns the Enum's integer value.
protected static void loadEnum(java.lang.Class enumClass)
          Loads properties from an enumClass.properties resource file.
protected static void loadIntegerEnum(java.lang.Class enumClass)
          Loads properties from an enumClass.properties resource file.
protected  java.lang.Object readResolve()
          Ensures uniqueness of Enums during deserialization.
 java.lang.String stringValue()
          Returns the string value of this Enum.
 java.lang.String toString()
          Returns this Enum's human readable description in the default locale.
 java.lang.String toString(java.util.Locale locale)
          Returns this Enum's human readable description in the specified locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enum

protected Enum()
Initialize the Enum, using default integer and string values.

Enum

protected Enum(java.lang.String string)
Initialize the Enum with a string value. An integer value is assigned automatically.

Enum

protected Enum(java.lang.String string,
               java.lang.String label)
Initialize the Enum with a string value and a default label. An integer value is assigned automatically.

Enum

protected Enum(int integer)
Initialize the Enum with an integer value. A string value will be produced automatically.

Enum

protected Enum(int integer,
               java.lang.String label)
Initialize the Enum with an integer value and a default label. A string value will be produced automatically.
Method Detail

stringValue

public java.lang.String stringValue()
Returns the string value of this Enum. Depending on how the Enum was created, the method behaves differently:
  • If the constant was created as a public static Enum, the name of that field is returned.
  • If the constant was declared as a public static int, and registered with initIntegerEnum, the name of that integer field is returned.
  • If the constant was loaded from a .properties file, the corresponding property name is returned.

  • intValue

    public int intValue()
    Returns the Enum's integer value. An Enum can be allocated with an explicitly specified integer value. If the integer value is not specified, the Enum's constructor gives it a default one, which is computed by adding one to the integer value of the previous Enum of the same type.

    toString

    public java.lang.String toString()
    Returns this Enum's human readable description in the default locale.
    Overrides:
    toString in class java.lang.Object

    toString

    public java.lang.String toString(java.util.Locale locale)
    Returns this Enum's human readable description in the specified locale. If the resource bundle is not found or does not have a value for this Enum, the value of the default label specified during construction is returned. If that value was not unspecified, the Enum's string value is returned.

    enum

    public static Enum[] enum(java.lang.Class enumClass)
    Returns an array of all Enums of the specified class in the order they were created.

    enum

    public static Enum enum(java.lang.Class enumClass,
                            java.lang.String string)
    Returns the Enum of the specified class that has the specified st, or null if there is no such Enum.

    enum

    public static Enum enum(java.lang.Class enumClass,
                            int integer)
    Returns the Enum of the specified class that has the specified integer value, or null if there is no such Enum.

    initIntegerEnum

    protected static void initIntegerEnum(java.lang.Class enumClass)

    loadEnum

    protected static void loadEnum(java.lang.Class enumClass)
    Loads properties from an enumClass.properties resource file. Uses property names as string values of the Enums.

    loadIntegerEnum

    protected static void loadIntegerEnum(java.lang.Class enumClass)
    Loads properties from an enumClass.properties resource file. Uses property names as integer values of the Enums.

    readResolve

    protected java.lang.Object readResolve()
                                    throws java.io.ObjectStreamException
    Ensures uniqueness of Enums during deserialization. Finds an Enum that is already declared with the same integer value and returns that Enum instead of the current instance.


    Copyright (c) 2001 - PLOTNIX, Inc