0N/A/*
2362N/A * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
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 *
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.
0N/A *
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
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.jmx.snmp;
0N/A
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.*;
0N/A
0N/A
0N/A
0N/A/** This class is used for implementing enumerated values.
0N/A *
0N/A * An enumeration is represented by a class derived from Enumerated.
0N/A * The derived class defines what are the permitted values in the enumeration.
0N/A *
0N/A * An enumerated value is represented by an instance of the derived class.
0N/A * It can be represented :
0N/A * - as an integer
0N/A * - as a string
0N/A *
0N/A * <p><b>This API is a Sun Microsystems internal API and is subject
0N/A * to change without notice.</b></p>
0N/A */
0N/A
0N/Aabstract public class Enumerated implements Serializable {
0N/A
0N/A /**
0N/A * Construct an enumerated with a default value.
0N/A * The default value is the first available in getIntTable().
0N/A * @exception IllegalArgumentException One of the arguments passed to the method is illegal or inappropriate.
0N/A */
0N/A public Enumerated() throws IllegalArgumentException {
0N/A Enumeration e =getIntTable().keys() ;
0N/A if (e.hasMoreElements()) {
0N/A value = ((Integer)e.nextElement()).intValue() ;
0N/A }
0N/A else {
0N/A throw new IllegalArgumentException() ;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Construct an enumerated from its integer form.
0N/A *
0N/A * @param valueIndex The integer form.
0N/A * @exception IllegalArgumentException One of the arguments passed to
0N/A * the method is illegal or inappropriate.
0N/A */
0N/A public Enumerated(int valueIndex) throws IllegalArgumentException {
0N/A if (getIntTable().get(new Integer(valueIndex)) == null) {
0N/A throw new IllegalArgumentException() ;
0N/A }
0N/A value = valueIndex ;
0N/A }
0N/A
0N/A /**
0N/A * Construct an enumerated from its Integer form.
0N/A *
0N/A * @param valueIndex The Integer form.
0N/A * @exception IllegalArgumentException One of the arguments passed to
0N/A * the method is illegal or inappropriate.
0N/A */
0N/A public Enumerated(Integer valueIndex) throws IllegalArgumentException {
0N/A if (getIntTable().get(valueIndex) == null) {
0N/A throw new IllegalArgumentException() ;
0N/A }
0N/A value = valueIndex.intValue() ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Construct an enumerated from its string form.
0N/A *
0N/A * @param valueString The string form.
0N/A * @exception IllegalArgumentException One of the arguments passed
0N/A * to the method is illegal or inappropriate.
0N/A */
0N/A public Enumerated(String valueString) throws IllegalArgumentException {
0N/A Integer index = (Integer)getStringTable().get(valueString) ;
0N/A if (index == null) {
0N/A throw new IllegalArgumentException() ;
0N/A }
0N/A else {
0N/A value = index.intValue() ;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Return the integer form of the enumerated.
0N/A *
0N/A * @return The integer form
0N/A */
0N/A
0N/A public int intValue() {
0N/A return value ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an Java enumeration of the permitted integers.
0N/A *
0N/A * @return An enumeration of Integer instances
0N/A */
0N/A
0N/A public Enumeration valueIndexes() {
0N/A return getIntTable().keys() ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an Java enumeration of the permitted strings.
0N/A *
0N/A * @return An enumeration of String instances
0N/A */
0N/A
0N/A public Enumeration valueStrings() {
0N/A return getStringTable().keys() ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Compares this enumerated to the specified enumerated.
0N/A *
0N/A * The result is true if and only if the argument is not null
0N/A * and is of the same class.
0N/A *
0N/A * @param obj The object to compare with.
0N/A *
0N/A * @return True if this and obj are the same; false otherwise
0N/A */
0N/A public boolean equals(Object obj) {
0N/A
0N/A return ((obj != null) &&
0N/A (getClass() == obj.getClass()) &&
0N/A (value == ((Enumerated)obj).value)) ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the hash code for this enumerated.
0N/A *
0N/A * @return A hash code value for this object.
0N/A */
0N/A public int hashCode() {
0N/A String hashString = getClass().getName() + String.valueOf(value) ;
0N/A return hashString.hashCode() ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the string form of this enumerated.
0N/A *
0N/A * @return The string for for this object.
0N/A */
0N/A
0N/A public String toString() {
0N/A return (String)getIntTable().get(new Integer(value)) ;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the hashtable of the integer forms.
0N/A * getIntTable().get(x) returns the string form associated
0N/A * to the integer x.
0N/A *
0N/A * This method must be implemented by the derived class.
0N/A *
0N/A * @return An hashtable for read-only purpose
0N/A */
0N/A
0N/A protected abstract Hashtable getIntTable() ;
0N/A
0N/A
0N/A
0N/A /**
0N/A * Returns the hashtable of the string forms.
0N/A * getStringTable().get(s) returns the integer form associated
0N/A * to the string s.
0N/A *
0N/A * This method must be implemented by the derived class.
0N/A *
0N/A * @return An hashtable for read-only purpose
0N/A */
0N/A
0N/A protected abstract Hashtable getStringTable() ;
0N/A
0N/A
0N/A /**
0N/A * This variable keeps the integer form of the enumerated.
0N/A * The string form is retreived using getIntTable().
0N/A */
0N/A protected int value ;
0N/A
0N/A}