001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.jvmstat.perfdata.monitor.v1_0;
027:
028: /**
029: * A typesafe enumeration for describing Java basic types.
030: *
031: * <p> The enumeration values for this typesafe enumeration must be
032: * kept in synchronization with the BasicType enum in the
033: * globalsDefinitions.hpp file in the HotSpot source base.</p>
034: *
035: * @author Brian Doherty
036: * @version 1.8, 05/05/07
037: * @since 1.5
038: */
039: public class BasicType {
040:
041: private final String name;
042: private final int value;
043:
044: public static final BasicType BOOLEAN = new BasicType("boolean", 4);
045: public static final BasicType CHAR = new BasicType("char", 5);
046: public static final BasicType FLOAT = new BasicType("float", 6);
047: public static final BasicType DOUBLE = new BasicType("double", 7);
048: public static final BasicType BYTE = new BasicType("byte", 8);
049: public static final BasicType SHORT = new BasicType("short", 9);
050: public static final BasicType INT = new BasicType("int", 10);
051: public static final BasicType LONG = new BasicType("long", 11);
052: public static final BasicType OBJECT = new BasicType("object", 12);
053: public static final BasicType ARRAY = new BasicType("array", 13);
054: public static final BasicType VOID = new BasicType("void", 14);
055: public static final BasicType ADDRESS = new BasicType("address", 15);
056: public static final BasicType ILLEGAL = new BasicType("illegal", 99);
057:
058: private static BasicType basicTypes[] = { BOOLEAN, CHAR, FLOAT,
059: DOUBLE, BYTE, SHORT, INT, LONG, OBJECT, ARRAY, VOID,
060: ADDRESS, ILLEGAL };
061:
062: /**
063: * Convert enumeration value to a String.
064: *
065: * @return String - the string representation for the enumeration.
066: */
067: public String toString() {
068: return name;
069: }
070:
071: /**
072: * Convert enumeration to an integer value.
073: *
074: * @return int - the integer representation for the enumeration.
075: */
076: public int intValue() {
077: return value;
078: }
079:
080: /**
081: * Map an integer value to its corresponding BasicType object.
082: *
083: * @param i an integer representation of a BasicType
084: * @return BasicType - The BasicType enumeration object matching
085: * the value of <code>i</code>
086: */
087: public static BasicType toBasicType(int i) {
088: for (int j = 0; j < basicTypes.length; j++) {
089: if (basicTypes[j].intValue() == j) {
090: return (basicTypes[j]);
091: }
092: }
093: return ILLEGAL;
094: }
095:
096: private BasicType(String name, int value) {
097: this.name = name;
098: this.value = value;
099: }
100: }
|