*/
class AttributeValue
{
/** The value of the enumeration. Package visible for speed. */
final int value;
/** The list of enumeration names for the given subclass. */
private final String[] names;
/**
* Construct a type-safe enumeration element. For example,
*
* class Foo extends AttributeValue
* {
* private static final String[] names = { "one", "two" }
* public static final Foo ONE = new Foo(0);
* public static final Foo TWO = new Foo(1);
* private Foo(int value) { super(value, names); }
* }
*
*
* @param value the position of this enumeration element, consecutive from 0
* @param names the constant list of enumeration names for the subclass
*/
AttributeValue(int value, String[] names)
{
this.value = value;
this.names = names;
}
/**
* Returns the hashcode of this element. This is the index of the element
* in the enumeration. Note that equals defaults to the == relation.
*
* @return the hashcode
*/
public int hashCode()
{
return value;
}
/**
* Returns the name of this enumeration element.
*
* @return the element name
*/
public String toString()
{
return names[value];
}
} // class AttributeValue