/** * Creates a mutable enumeration from an existing enumeration, which may * already be immutable. */ public EnumeratedValues getMutableClone() { return clone(); }
/** * Returns whether <code>ordinal</code> is valid for this enumeration. * This method is particularly useful in pre- and post-conditions, for * example * <blockquote> * <pre>@param axisCode Axis code, must be a {@link AxisCode} value * @pre AxisCode.instance.isValid(axisCode)</pre> * </blockquote> * * @param ordinal Suspected ordinal from this enumeration. * @return Whether <code>ordinal</code> is valid. */ public final boolean isValid(int ordinal) { if ((ordinal < min) || (ordinal > max)) { return false; } if (getName(ordinal) == null) { return false; } return true; }
/** * Creates an enumeration, with an array of values, and freezes it. */ public EnumeratedValues(V[] values) { for (V value : values) { register(value); } makeImmutable(); }
/** * 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]; }
/** * Looks up a Property with a given ordinal. * Returns null if not found. */ public static Property lookup(int ordinal) { return enumeration.getValue(ordinal); }
/** * Create an enumeration, initializes it with arrays of code/name pairs, * and freezes it. */ public EnumeratedValues(String[] names, int[] codes, String[] descriptions) { for (int i = 0; i < names.length; i++) { register((V) new BasicValue(names[i], codes[i], descriptions[i])); } makeImmutable(); }
/** * 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 ordinal associated with a name * * @throws Error if the name is not a member of the enumeration */ public final int getOrdinal(String name) { return getValue(name, true).getOrdinal(); }
/** * Creates an enumeration, initialize it with an array of strings, and * freezes it. */ public EnumeratedValues(String[] names) { for (int i = 0; i < names.length; i++) { register((V) new BasicValue(names[i], i, names[i])); } makeImmutable(); }
/** * 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(); }
/** * Looks up a Property with a given name. * * @param name Name of property * @param matchCase Whether to perform case-sensitive match * @return Property with given name, or null if not found. */ public static Property lookup(String name, boolean matchCase) { if (matchCase) { Property property = enumeration.getValue(name, false); if (property != null) { return property; } return synonyms.get(name); } else { // No need to check synonyms separately - the map contains them. return mapUpperNameToProperties.get(name.toUpperCase()); } } }
/** * Returns an error indicating that the value is illegal. (The client needs * to throw the error.) */ public RuntimeException badValue(int ordinal) { return Util.newInternal( "bad value " + ordinal + "(" + getName(ordinal) + ") for enumeration '" + getClass().getName() + "'"); }
/** * Create an enumeration, initializes it with arrays of code/name pairs, * and freezes it. */ public EnumeratedValues(String[] names, int[] codes) { for (int i = 0; i < names.length; i++) { register((V) new BasicValue(names[i], codes[i], names[i])); } makeImmutable(); }
/** * 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); }