qflib 0.99

de.qfs.lib.util
Class Enum

java.lang.Object
  extended byde.qfs.lib.util.Enum
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class Enum
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

An implementation of the Enum pattern to provide enumerations for Java.

Since:
0.99.0
Author:
Gregor Schmid
See Also:
Serialized Form

Constructor Summary
Enum(int value, java.lang.String name)
          Create a new Enum.
 
Method Summary
 java.lang.Object clone()
          Cloning conflicts with the identity requirement, so the original Enum is returned.
 int compareTo(java.lang.Object o)
          Compare the Enum to another enum.
 boolean equals(java.lang.Object o)
          Compare two enums.
 java.lang.String getName()
          Get the name of the Enum.
 java.lang.String getTypeName()
          Get the type name for the Enum.
 int getValue()
          Get the int value.
 int hashCode()
          Finalize hashCode to avoid accidental overriding.
static Enum lookup(java.lang.String type, int value)
          Get an Enum defined by its type and value.
 java.lang.Object readResolve()
          Resolve an Object during derserialization.
 java.lang.String toString()
          Get a String representation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enum

public Enum(int value,
            java.lang.String name)
     throws java.lang.IllegalArgumentException
Create a new Enum.

Parameters:
value - The value for the Enum.
name - The Name for the Enum.
Throws:
java.lang.IllegalArgumentException - if an Enum of the same class with the same id is already registered.
Method Detail

lookup

public static Enum lookup(java.lang.String type,
                          int value)
Get an Enum defined by its type and value.

Parameters:
type - The type as returned by getTypeName.
value - The value of the enum.
Returns:
The enum if known or null.

getValue

public final int getValue()
Get the int value.

Returns:
The int value.

getName

public final java.lang.String getName()
Get the name of the Enum.

Returns:
The name of the Enum.

toString

public java.lang.String toString()
Get a String representation.

Returns:
The String representation.

clone

public java.lang.Object clone()
Cloning conflicts with the identity requirement, so the original Enum is returned.

Returns:
This.

readResolve

public java.lang.Object readResolve()
Resolve an Object during derserialization. Will only be called for JDK 1.2 and up.

Returns:
The registered Enum if it exists.

equals

public final boolean equals(java.lang.Object o)
Compare two enums. For JDK 1.2 and above object identity is used. For JDK 1.1 an additional test for type/value equality is made.

Parameters:
o - The object to compare to.
Returns:
True if the Enums are equal.

hashCode

public final int hashCode()
Finalize hashCode to avoid accidental overriding.

Returns:
The default hashCode.

compareTo

public int compareTo(java.lang.Object o)
Compare the Enum to another enum.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The enum to compare against.
Returns:
<0 if value is less, 0 if equal or >0 if value is greate than the other enum's value.

getTypeName

public java.lang.String getTypeName()
Get the type name for the Enum. Can be implemented in a derived class.

Returns:
The name of the Enum type.

qflib 0.99