| A class that represents an enumerated value. Its main features are its
Enumerator.toString() and
Enumerator.fromString(String,Class) method, which map names to values and vice versa.
To use this class, derive from it and define one or more
public static final fields, as follows:
public final class Suit extends Enumerator {
// Exactly N instances of "Suit" exist to represent the N possible values.
public static final Suit CLUBS = new Suit("clubs");
public static final Suit DIAMONDS = new Suit("diamonds");
public static final Suit HEARTS = new Suit("hearts");
public static final Suit SPADES = new Suit("spades");
// Optional, if you want to use EumeratorSet arithmetics.
public static final EnumeratorSet NONE = new EnumeratorSet(Suit.class ).setName("none");
public static final EnumeratorSet ALL = new EnumeratorSet(Suit.class, true).setName("all");
// These MUST be declared exactly like this:
private Suit(String name) { super(name); }
public static Suit fromString(String name) throws EnumeratorFormatException {
return (Suit) Enumerator.fromString(name, Suit.class);
}
}
See Also: Effective Java, Item 21 See Also: org.codehaus.janino.util.enumerator.EnumeratorSet |