Source Code Cross Referenced for Enum.java in  » Science » javolution-5.2 » javolution » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » javolution 5.2 » javolution.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
003:         * Copyright (C) 2005 - Javolution (http://javolution.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package javolution.lang;
010:
011:        import j2me.io.Serializable;
012:        import j2me.lang.Comparable;
013:        import j2mex.realtime.MemoryArea;
014:
015:        import javolution.util.FastMap;
016:
017:        /**
018:         * <p> This class is equivalent to <code>java.lang.Enum</code> 
019:         *     and is moved (refactored) to the <code>java.lang</code> system 
020:         *     package for applications targetting the J2SE 5.0+ run-time.</p>
021:         *    
022:         * <p> This is a clean-room implementation of the Enum base class.</p>
023:         * 
024:         * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
025:         * @version 2.0, November 26, 2004
026:         */
027:        public abstract class Enum implements  Comparable, Serializable {
028:
029:            /**
030:             * Holds the class to enum mapping.
031:             */
032:            private static final FastMap CLASS_TO_ENUMS = new FastMap();
033:
034:            /**
035:             * Holds the enum's name.
036:             */
037:            private final String _name;
038:
039:            /**
040:             * Holds the enum's position.
041:             */
042:            private final int _ordinal;
043:
044:            /**
045:             * Returns the name of this enum.
046:             * 
047:             * @return the enum's name.
048:             */
049:            public final String name() {
050:                return _name;
051:            }
052:
053:            /**
054:             * Returns the position of this enum in the enumeration (starting 
055:             * at <code>0</code>).
056:             * 
057:             * @return the enum's position.
058:             */
059:            public final int ordinal() {
060:                return _ordinal;
061:            }
062:
063:            /**
064:             * Enum's base constructor. 
065:             * 
066:             * @param name the enum's name.
067:             * @param ordinal the enum's position.
068:             */
069:            protected Enum(String name, int ordinal) {
070:                _name = name;
071:                _ordinal = ordinal;
072:                synchronized (CLASS_TO_ENUMS) {
073:                    MemoryArea.getMemoryArea(CLASS_TO_ENUMS).executeInArea(
074:                            new Runnable() {
075:                                public void run() {
076:                                    FastMap nameToEnum = (FastMap) CLASS_TO_ENUMS
077:                                            .get(Enum.this .getClass());
078:                                    if (nameToEnum == null) {
079:                                        nameToEnum = new FastMap();
080:                                        CLASS_TO_ENUMS.put(
081:                                                Enum.this .getClass(),
082:                                                nameToEnum);
083:                                    }
084:                                    Object prev = nameToEnum.put(_name,
085:                                            Enum.this );
086:                                    if (prev != null) {
087:                                        throw new IllegalArgumentException(
088:                                                "Duplicate enum " + _name);
089:                                    }
090:                                }
091:                            });
092:                }
093:            }
094:
095:            /**
096:             * Returns the <code>String</code> representation of this enum. 
097:             * 
098:             * @return the enum's name.
099:             */
100:            public String toString() {
101:                return _name;
102:            }
103:
104:            /**
105:             * Indicates if two enums are equals. 
106:             * 
107:             * @param that the enum to be compared for equality.
108:             * @return <code>this == that</code>
109:             */
110:            public final boolean equals(Object that) {
111:                return this  == that;
112:            }
113:
114:            /**
115:             * Returns the enums' hashcode. 
116:             * 
117:             * @return <code>System.identityHashCode(this)</code>
118:             */
119:            public final int hashCode() {
120:                return System.identityHashCode(this );
121:            }
122:
123:            /**
124:             * Compares the position of two enum from the same enumeration. 
125:             * 
126:             * @param  that the enum to be compared with.
127:             * @return a negative value, zero, or a positive value as this enum 
128:             *         is less than, equal to, or greater than the specified enum.
129:             * @throws ClassCastException if both enum do not belong to the same
130:             *         enumeration.
131:             */
132:            public final int compareTo(Object that) {
133:                Enum e = (Enum) that;
134:                if (this .getClass() == that.getClass()) {
135:                    return this ._ordinal - e._ordinal;
136:                } else {
137:                    throw new ClassCastException();
138:                }
139:            }
140:
141:            /**
142:             * Returns this enum's class. 
143:             * 
144:             * @return <code>this.getClass()</code>
145:             */
146:            public final Class getDeclaringClass() {
147:                return this .getClass();
148:            }
149:
150:            /**
151:             * Returns the enum from the specified enum's class with the specified 
152:             * name.
153:             * 
154:             * @param enumType the enum's declaring class.
155:             * @param name the name of the enum to return.
156:             * @return the corresponding enum.
157:             * @throws IllegalArgumentException if the enum does not exist.
158:             */
159:            public static Enum valueOf(Class enumType, String name) {
160:                FastMap nameToEnum = (FastMap) CLASS_TO_ENUMS.get(enumType);
161:                if (nameToEnum != null) {
162:                    Enum e = (Enum) nameToEnum.get(name);
163:                    if (e != null) {
164:                        return e;
165:                    }
166:                }
167:                throw new IllegalArgumentException(enumType + "." + name
168:                        + " not found");
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.