net.dpml.lang
Class Enum

java.lang.Object
  extended bynet.dpml.lang.Enum
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ActivationPolicy, CollectionPolicy, Feature, ImportDirective.Mode, IncludeDirective.Mode, LifestylePolicy, ResourceDirective.Classifier, StartupPolicy, Status, ThreadSafePolicy, Trigger.TriggerEvent, ValuedEnum

public abstract class Enum
extends Object
implements Serializable

Basic enum class for type-safe enums. Should be used as an abstract base. For example:

 import net.dpml.lang.Enum;

 public final class Color extends Enum {
   public static final Color RED = new Color( "Red" );
   public static final Color GREEN = new Color( "Green" );
   public static final Color BLUE = new Color( "Blue" );

   private Color( final String color )
   {
     super( color );
   }
 }
 
If further operations, such as iterating over all items, are required, the Enum(String, Map) constructor can be used to populate a Map, from which further functionality can be derived:
 public final class Color extends Enum {
   static final Map map = new HashMap();

   public static final Color RED = new Color( "Red", map );
   public static final Color GREEN = new Color( "Green", map );
   public static final Color BLUE = new Color( "Blue", map );

   private Color( final String color, final Map map )
   {
     super( color, map );
   }

   public static Iterator iterator()
   {
     return map.values().iterator();
   }
 }
 

Version:
1.0.1
Author:
Digital Product Meta Library
See Also:
Serialized Form

Constructor Summary
protected Enum(String name)
          Constructor to add a new named item.
protected Enum(String name, Map map)
          Constructor to add a new named item.
 
Method Summary
 boolean equals(Object o)
          Tests for equality.
 String getName()
          Retrieve the name of this Enum item, set in the constructor.
 int hashCode()
          Compute the hashcode.
 String toString()
          Human readable description of this Enum item in the form type:name, eg.: Color:Red.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enum

protected Enum(String name)
Constructor to add a new named item.

Parameters:
name - Name of the item.

Enum

protected Enum(String name,
               Map map)
Constructor to add a new named item.

Parameters:
name - Name of the item.
map - A Map to which newly constructed instances will be added.
Method Detail

equals

public boolean equals(Object o)
Tests for equality. Two Enum:s are considered equal if they are of the same class and have the same names.

Parameters:
o - the other object
Returns:
the equality status

hashCode

public int hashCode()
Compute the hashcode.

Returns:
the hashcode value

getName

public final String getName()
Retrieve the name of this Enum item, set in the constructor.

Returns:
the name String of this Enum item

toString

public String toString()
Human readable description of this Enum item in the form type:name, eg.: Color:Red.

Returns:
the string representation