/** * Returns the name associated with an ordinal; the return value * is null if the ordinal is not a member of the enumeration. * * @pre isImmutable() */ public final V getValue(int ordinal) { Util.assertPrecondition(isImmutable()); return (V) ordinalToValueMap[ordinal - min]; }
/** * Returns the description associated with an ordinal; the return value * is null if the ordinal is not a member of the enumeration. * * @pre isImmutable() */ public final String getDescription(int ordinal) { Util.assertPrecondition(isImmutable()); final Value value = ordinalToValueMap[ordinal - min]; return (value == null) ? null : value.getDescription(); }
/** * Returns the name associated with an ordinal; the return value * is null if the ordinal is not a member of the enumeration. * * @pre isImmutable() */ public final String getName(int ordinal) { Util.assertPrecondition(isImmutable()); final Value value = ordinalToValueMap[ordinal - min]; return (value == null) ? null : value.getName(); }
/** * Associates a symbolic name with an ordinal value. * * @pre value != null * @pre !isImmutable() * @pre value.getName() != null */ public void register(V value) { assert value != null : "pre: value != null"; Util.assertPrecondition(!isImmutable(), "isImmutable()"); final String name = value.getName(); Util.assertPrecondition(name != null, "value.getName() != null"); Value old = valuesByName.put(name, value); if (old != null) { throw Util.newInternal( "Enumeration already contained a value '" + old.getName() + "'"); } final int ordinal = value.getOrdinal(); min = Math.min(min, ordinal); max = Math.max(max, ordinal); }