blob: b36fbf7a1125a7d4def30cdc05a01fc81038d945 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.jvmstat.perfdata.monitor.v1_0;
27
28/**
29 * A typesafe enumeration for describing Java basic types.
30 *
31 * <p> The enumeration values for this typesafe enumeration must be
32 * kept in synchronization with the BasicType enum in the
33 * globalsDefinitions.hpp file in the HotSpot source base.</p>
34 *
35 * @author Brian Doherty
36 * @since 1.5
37 */
38public class BasicType {
39
40 private final String name;
41 private final int value;
42
43 public static final BasicType BOOLEAN = new BasicType("boolean", 4);
44 public static final BasicType CHAR = new BasicType("char", 5);
45 public static final BasicType FLOAT = new BasicType("float", 6);
46 public static final BasicType DOUBLE = new BasicType("double", 7);
47 public static final BasicType BYTE = new BasicType("byte", 8);
48 public static final BasicType SHORT = new BasicType("short", 9);
49 public static final BasicType INT = new BasicType("int", 10);
50 public static final BasicType LONG = new BasicType("long", 11);
51 public static final BasicType OBJECT = new BasicType("object", 12);
52 public static final BasicType ARRAY = new BasicType("array", 13);
53 public static final BasicType VOID = new BasicType("void", 14);
54 public static final BasicType ADDRESS = new BasicType("address", 15);
55 public static final BasicType ILLEGAL = new BasicType("illegal", 99);
56
57 private static BasicType basicTypes[] = {
58 BOOLEAN, CHAR, FLOAT, DOUBLE, BYTE, SHORT, INT, LONG, OBJECT,
59 ARRAY, VOID, ADDRESS, ILLEGAL
60 };
61
62 /**
63 * Convert enumeration value to a String.
64 *
65 * @return String - the string representation for the enumeration.
66 */
67 public String toString() {
68 return name;
69 }
70
71 /**
72 * Convert enumeration to an integer value.
73 *
74 * @return int - the integer representation for the enumeration.
75 */
76 public int intValue() {
77 return value;
78 }
79
80 /**
81 * Map an integer value to its corresponding BasicType object.
82 *
83 * @param i an integer representation of a BasicType
84 * @return BasicType - The BasicType enumeration object matching
85 * the value of <code>i</code>
86 */
87 public static BasicType toBasicType(int i) {
88 for (int j = 0; j < basicTypes.length; j++) {
89 if (basicTypes[j].intValue() == j) {
90 return (basicTypes[j]);
91 }
92 }
93 return ILLEGAL;
94 }
95
96 private BasicType(String name, int value) {
97 this.name = name;
98 this.value = value;
99 }
100}