Web Site

org.codehaus.janino.util.enumerator
Class Enumerator

java.lang.Object
  extended byorg.codehaus.janino.util.enumerator.Enumerator

public abstract class Enumerator
extends Object

A class that represents an enumerated value. Its main feature is its toString() method, which reconstructs the clear text value through reflection.

To use this class, derive from it and define one or more public static final fields, as follows:

 public class Color extends Enumerator {
     public static final Color RED   = new Color(0);
     public static final Color GREEN = new Color(1);
     public static final Color BLUE  = new Color(2);

     public Color(String s) throws EnumeratorFormatException { super(s); }

     private Color(int value) { super(value); }
 }
 


Constructor Summary
protected Enumerator(int value)
          Initialize the enumerator to the given value.
protected Enumerator(String s)
          Initialize an Enumerator from a string.
 
Method Summary
 boolean equals(Object that)
          Check the object's value
 int hashCode()
           
 String toString()
          Convert an Enumerator into a clear-text string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enumerator

protected Enumerator(int value)
Initialize the enumerator to the given value.


Enumerator

protected Enumerator(String s)
              throws EnumeratorFormatException
Initialize an Enumerator from a string.

The given string is converted into a value by looking at the class's public static final fields which have the same type as the class itself.

Throws:
EnumeratorFormatException - if the string cannot be identified
Method Detail

equals

public boolean equals(Object that)
Check the object's value


hashCode

public int hashCode()

toString

public String toString()
Convert an Enumerator into a clear-text string.

Examine the object through reflection for public static final fields that have the same type as this object, and return the name of the fields who's value matches the object's value.


Web Site