public abstract class EnumeratedType
extends java.lang.Object
implements java.io.Serializable
| Modifier | Constructor and Description |
|---|---|
protected |
EnumeratedType(java.lang.String name,
int ordinal)
Concrete subclasses should define a private static field to generate
ordinals and a private constructor as follows:
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object object)
Indicates whether some other object is "equal to" this enumerated type.
|
java.lang.String |
getName()
Retrieves the value of the
name instance variable. |
int |
getOrdinal()
Retrieves the value of the
ordinal instance variable. |
protected abstract java.util.List |
getValues()
Retrieves the list of constants for this enumerated type.
|
int |
hashCode()
Retrieves a hash code value for this enumerated type.
|
protected java.lang.Object |
readResolve()
Designates an alternative object to be used when reading an enumerated
type from a stream.
|
java.lang.String |
toString()
Retrieves a textual representation of this enumerated type.
|
protected EnumeratedType(java.lang.String name,
int ordinal)
private static int nextOrdinal = 0;
private Subclass(String name) {
super(name, nextOrdinal++);
}
name - The name of the new enumerated type.ordinal - The ordinal for the new enumerated type.public java.lang.String getName()
name instance variable.name instance variable.public final int getOrdinal()
ordinal instance variable.ordinal instance variable.protected abstract java.util.List getValues()
Concrete subclasses should define a private static array of values and a(n) (final) implementation of this method as follows:
private static final Subclass[] VALUES = { ... };
protected final List getValues() {
return Collections.unmodifiableList(Arrays.asList(VALUES));
}
public final boolean equals(java.lang.Object object)
equals in class java.lang.Objectobject - The reference object with which to compare.true if this enumerated type is the same as the
object argument; false otherwise.Object.equals(Object)public final int hashCode()
java.util.Hashtable.hashCode in class java.lang.ObjectObject.hashCode()public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()protected final java.lang.Object readResolve()
throws java.io.ObjectStreamException
java.io.ObjectStreamExceptionSerializable