KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > PrimitiveTypeKindEnum


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.jmi.javamodel;
21
22 /**
23  * PrimitiveTypeKind enumeration class implementation.
24  * Enumeration of Java primitive type kinds.
25  *
26  * <p><em><strong>Note:</strong> This type should not be subclassed or implemented
27  * by clients. It is generated from a MOF metamodel and automatically implemented
28  * by MDR (see <a HREF="http://mdr.netbeans.org/">mdr.netbeans.org</a>).</em></p>
29  */

30 public final class PrimitiveTypeKindEnum implements PrimitiveTypeKind {
31     /**
32      * Enumeration constant corresponding to literal void.
33      */

34     public static final PrimitiveTypeKindEnum VOID = new PrimitiveTypeKindEnum("void");
35     /**
36      * Enumeration constant corresponding to literal int.
37      */

38     public static final PrimitiveTypeKindEnum INT = new PrimitiveTypeKindEnum("int");
39     /**
40      * Enumeration constant corresponding to literal char.
41      */

42     public static final PrimitiveTypeKindEnum CHAR = new PrimitiveTypeKindEnum("char");
43     /**
44      * Enumeration constant corresponding to literal boolean.
45      */

46     public static final PrimitiveTypeKindEnum BOOLEAN = new PrimitiveTypeKindEnum("boolean");
47     /**
48      * Enumeration constant corresponding to literal long.
49      */

50     public static final PrimitiveTypeKindEnum LONG = new PrimitiveTypeKindEnum("long");
51     /**
52      * Enumeration constant corresponding to literal double.
53      */

54     public static final PrimitiveTypeKindEnum DOUBLE = new PrimitiveTypeKindEnum("double");
55     /**
56      * Enumeration constant corresponding to literal float.
57      */

58     public static final PrimitiveTypeKindEnum FLOAT = new PrimitiveTypeKindEnum("float");
59     /**
60      * Enumeration constant corresponding to literal byte.
61      */

62     public static final PrimitiveTypeKindEnum BYTE = new PrimitiveTypeKindEnum("byte");
63     /**
64      * Enumeration constant corresponding to literal short.
65      */

66     public static final PrimitiveTypeKindEnum SHORT = new PrimitiveTypeKindEnum("short");
67
68     private static final java.util.List JavaDoc typeName;
69     private final java.lang.String JavaDoc literalName;
70
71     static {
72         java.util.ArrayList JavaDoc temp = new java.util.ArrayList JavaDoc();
73         temp.add("JavaModel");
74         temp.add("PrimitiveTypeKind");
75         typeName = java.util.Collections.unmodifiableList(temp);
76     }
77
78     private PrimitiveTypeKindEnum(java.lang.String JavaDoc literalName) {
79         this.literalName = literalName;
80     }
81
82     /**
83      * Returns fully qualified name of the enumeration type.
84      * @return List containing all parts of the fully qualified name.
85      */

86     public java.util.List JavaDoc refTypeName() {
87         return typeName;
88     }
89
90     /**
91      * Returns a string representation of the enumeration value.
92      * @return A string representation of the enumeration value.
93      */

94     public java.lang.String JavaDoc toString() {
95         return literalName;
96     }
97
98     /**
99      * Returns a hash code for this the enumeration value.
100      * @return A hash code for this enumeration value.
101      */

102     public int hashCode() {
103         return literalName.hashCode();
104     }
105
106     /**
107      * Indicates whether some other object is equal to this enumeration value.
108      * @param o The reference object with which to compare.
109      * @return true if the other object is the enumeration of the same type and
110      * of the same value.
111      */

112     public boolean equals(java.lang.Object JavaDoc o) {
113         if (o instanceof PrimitiveTypeKindEnum) return (o == this);
114         else if (o instanceof PrimitiveTypeKind) return (o.toString().equals(literalName));
115         else return ((o instanceof javax.jmi.reflect.RefEnum) && ((javax.jmi.reflect.RefEnum) o).refTypeName().equals(typeName) && o.toString().equals(literalName));
116     }
117
118     /**
119      * Translates literal name to correspondent enumeration value.
120      * @param name Enumeration literal.
121      * @return Enumeration value corresponding to the passed literal.
122      */

123     public static PrimitiveTypeKind forName(java.lang.String JavaDoc name) {
124         if (name.equals("void")) return VOID;
125         if (name.equals("int")) return INT;
126         if (name.equals("char")) return CHAR;
127         if (name.equals("boolean")) return BOOLEAN;
128         if (name.equals("long")) return LONG;
129         if (name.equals("double")) return DOUBLE;
130         if (name.equals("float")) return FLOAT;
131         if (name.equals("byte")) return BYTE;
132         if (name.equals("short")) return SHORT;
133         throw new java.lang.IllegalArgumentException JavaDoc("Unknown literal name '" + name + "' for enumeration 'JavaModel.PrimitiveTypeKind'");
134     }
135     /**
136      * Resolves serialized instance of enumeration value.
137      * @return Resolved enumeration value.
138      */

139     protected java.lang.Object JavaDoc readResolve() throws java.io.ObjectStreamException JavaDoc {
140         try {
141             return forName(literalName);
142         } catch (java.lang.IllegalArgumentException JavaDoc e) {
143             throw new java.io.InvalidObjectException JavaDoc(e.getMessage());
144         }
145     }
146 }
147
Popular Tags