org.japano.util
Class Enum

java.lang.Object
  extended by org.japano.util.Enum
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BodyContent, IDMechanism, TagType

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

Base class for serialization-safe Enum-Classes.

Classes which are derived from this base class should have only private Constructors and should define all possible instances as public final static members.

Example:


 public class Color extends org.japano.util.Enum
 {
   public final static Color RED=new Color("red");
   public final static Color BLUE=new Color("blue");

   private Color(String name)
   {
      super(name);
   } 
 }

 
This Enum implementation is used instead of java 1.5 enums to keep the japano core java 1.4 compatible.

Version:
$Id: Enum.java,v 1.4 2005/09/27 21:30:51 fforw Exp $ SourceForge.net Logo
Author:
Sven Helmberger ( sven dot helmberger at gmx dot de )
See Also:
Serialized Form

Constructor Summary
protected Enum(java.lang.Object identifier)
          Creates a new enum instance.
 
Method Summary
protected static Enum fromIdentifier(java.lang.Class klass, java.lang.Object identifier)
          Returns the enum instance with the given identifier and the given type.
protected  java.lang.Object getIdentifier()
          Returns the identifier of this enum instance
 int hashCode()
          Returns the identifier's hashcode as hashcode of this enum instance.
static java.util.Iterator instances(java.lang.Class klass)
          Returns an iterator over all enum instances of the given type.
protected  java.lang.Object readResolve()
          Replaces a deserialized enum instance with an already existing instance of the same type with the same identifier
 java.lang.String toString()
          Returns a string representation of this enum instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enum

protected Enum(java.lang.Object identifier)
Creates a new enum instance.

Parameters:
identifier - unique indentifier within all instances of the same type
Method Detail

fromIdentifier

protected static Enum fromIdentifier(java.lang.Class klass,
                                     java.lang.Object identifier)
Returns the enum instance with the given identifier and the given type.

Returns:
enum instance
Throws:
java.lang.IllegalArgumentException - if no such instance exists

instances

public static java.util.Iterator instances(java.lang.Class klass)
Returns an iterator over all enum instances of the given type.

Parameters:
klass - type
Returns:
Iterator

getIdentifier

protected java.lang.Object getIdentifier()
Returns the identifier of this enum instance


readResolve

protected java.lang.Object readResolve()
                                throws java.io.InvalidObjectException
Replaces a deserialized enum instance with an already existing instance of the same type with the same identifier

Returns:
Replacement
Throws:
java.io.InvalidObjectException - if no such replacement exists.

hashCode

public int hashCode()
Returns the identifier's hashcode as hashcode of this enum instance.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode

toString

public java.lang.String toString()
Returns a string representation of this enum instance

Overrides:
toString in class java.lang.Object
Returns:
string representation