0N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 2362N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 2362N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Class EnumSyntax is an abstract base class providing the common 0N/A * implementation of all "type safe enumeration" objects. An enumeration class 0N/A * (which extends class EnumSyntax) provides a group of enumeration values 0N/A * (objects) that are singleton instances of the enumeration class; for example: 0N/A * public class Bach extends EnumSyntax { 0N/A * public static final Bach JOHANN_SEBASTIAN = new Bach(0); 1693N/A * public static final Bach WILHELM_FRIEDEMANN = new Bach(1); 1693N/A * public static final Bach CARL_PHILIP_EMMANUEL = new Bach(2); 1693N/A * public static final Bach JOHANN_CHRISTIAN = new Bach(3); 1693N/A * public static final Bach P_D_Q = new Bach(4); 5980N/A * private static final String[] stringTable = { 0N/A * "Wilhelm Friedemann Bach", 0N/A * "Carl Philip Emmanuel Bach", 0N/A * "Johann Christian Bach", 3171N/A * protected String[] getStringTable() { 0N/A * private static final Bach[] enumValueTable = { 0N/A * WILHELM_FRIEDEMANN, 0N/A * CARL_PHILIP_EMMANUEL, 0N/A * protected EnumSyntax[] getEnumValueTable() { 0N/A * return enumValueTable; 0N/A * You can then write code that uses the <CODE>==</CODE> and <CODE>!=</CODE> 0N/A * operators to test enumeration values; for example: 1693N/A * if (theComposer == Bach.JOHANN_SEBASTIAN) { 0N/A * System.out.println ("The greatest composer of all time!"); 0N/A * The <CODE>equals()</CODE> method for an enumeration class just does a test 0N/A * for identical objects (<CODE>==</CODE>). 0N/A * You can convert an enumeration value to a string by calling {@link 0N/A * #toString() <CODE>toString()</CODE>}. The string is obtained from a table 0N/A * supplied by the enumeration class. 0N/A * Under the hood, an enumeration value is just an integer, a different integer 0N/A * for each enumeration value within an enumeration class. You can get an 0N/A * enumeration value's integer value by calling {@link #getValue() 0N/A * <CODE>getValue()</CODE>}. An enumeration value's integer value is established 0N/A * when it is constructed (see {@link #EnumSyntax(int) 0N/A * <CODE>EnumSyntax(int)</CODE>}). Since the constructor is protected, the only 0N/A * possible enumeration values are the singleton objects declared in the 0N/A * enumeration class; additional enumeration values cannot be created at run 0N/A * You can define a subclass of an enumeration class that extends it with 0N/A * additional enumeration values. The subclass's enumeration values' integer 0N/A * values need not be distinct from the superclass's enumeration values' integer 1693N/A * values; the <CODE>==</CODE>, <CODE>!=</CODE>, <CODE>equals()</CODE>, and 0N/A * <CODE>toString()</CODE> methods will still work properly even if the subclass 0N/A * uses some of the same integer values as the superclass. However, the 0N/A * application in which the enumeration class and subclass are used may need to 0N/A * have distinct integer values in the superclass and subclass. * @author David Mendenhall * This enumeration value's integer value. * Construct a new enumeration value with the given integer value. * @param value Integer value. * Returns this enumeration value's integer value. * Returns a clone of this enumeration value, which to preserve the * semantics of enumeration values is the same object as this enumeration * Returns a hash code value for this enumeration value. The hash code is * just this enumeration value's integer value. * Returns a string value corresponding to this enumeration value. * During object input, convert this deserialized enumeration instance to * the proper enumeration value defined in the enumeration attribute class. * @return The enumeration singleton value stored at index * <I>i</I>-<I>L</I> in the enumeration value table returned by * {@link #getEnumValueTable() <CODE>getEnumValueTable()</CODE>}, * where <I>i</I> is this enumeration value's integer value and * <I>L</I> is the value returned by {@link #getOffset() * <CODE>getOffset()</CODE>}. * @throws ObjectStreamException if the stream can't be deserialised * @throws InvalidObjectException * Thrown if the enumeration value table is null, this enumeration * value's integer value does not correspond to an element in the * enumeration value table, or the corresponding element in the * enumeration value table is null. (Note: {@link * java.io.InvalidObjectException InvalidObjectException} is a subclass * of {@link java.io.ObjectStreamException ObjectStreamException}, which * <CODE>readResolve()</CODE> is declared to throw.) "Null enumeration value table for class " +
(
"Integer value = " +
value +
" not in valid range " +
(
"No enumeration value for integer value = " +
// Hidden operations to be implemented in a subclass. * Returns the string table for this enumeration value's enumeration class. * The enumeration class's integer values are assumed to lie in the range * <I>L</I>..<I>L</I>+<I>N</I>-1, where <I>L</I> is the value returned by * {@link #getOffset() <CODE>getOffset()</CODE>} and <I>N</I> is the length * of the string table. The element in the string table at index * <I>i</I>-<I>L</I> is the value returned by {@link #toString() * <CODE>toString()</CODE>} for the enumeration value whose integer value * is <I>i</I>. If an integer within the above range is not used by any * enumeration value, leave the corresponding table element null. * The default implementation returns null. If the enumeration class (a * subclass of class EnumSyntax) does not override this method to return a * non-null string table, and the subclass does not override the {@link * #toString() <CODE>toString()</CODE>} method, the base class {@link * #toString() <CODE>toString()</CODE>} method will return just a string * representation of this enumeration value's integer value. * @return the string table * Returns the enumeration value table for this enumeration value's * enumeration class. The enumeration class's integer values are assumed to * lie in the range <I>L</I>..<I>L</I>+<I>N</I>-1, where <I>L</I> is the * value returned by {@link #getOffset() <CODE>getOffset()</CODE>} and * <I>N</I> is the length of the enumeration value table. The element in the * enumeration value table at index <I>i</I>-<I>L</I> is the enumeration * value object whose integer value is <I>i</I>; the {@link #readResolve() * <CODE>readResolve()</CODE>} method needs this to preserve singleton * semantics during deserialization of an enumeration instance. If an * integer within the above range is not used by any enumeration value, * leave the corresponding table element null. * The default implementation returns null. If the enumeration class (a * subclass of class EnumSyntax) does not override this method to return * a non-null enumeration value table, and the subclass does not override * the {@link #readResolve() <CODE>readResolve()</CODE>} method, the base * class {@link #readResolve() <CODE>readResolve()</CODE>} method will throw * an exception whenever an enumeration instance is deserialized from an * @return the value table * Returns the lowest integer value used by this enumeration value's * The default implementation returns 0. If the enumeration class (a * subclass of class EnumSyntax) uses integer values starting at other than * 0, override this method in the subclass. * @return the offset of the lowest enumeration value.