Source Code Cross Referenced for FloatCache.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » compiler » codegen » 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 » IDE Eclipse » jdt » org.eclipse.jdt.internal.compiler.codegen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.compiler.codegen;
011:
012:        public class FloatCache {
013:            private float keyTable[];
014:            private int valueTable[];
015:            private int elementSize;
016:
017:            /**
018:             * Constructs a new, empty hashtable. A default capacity and
019:             * load factor is used. Note that the hashtable will automatically 
020:             * grow when it gets full.
021:             */
022:            public FloatCache() {
023:                this (13);
024:            }
025:
026:            /**
027:             * Constructs a new, empty hashtable with the specified initial
028:             * capacity.
029:             * @param initialCapacity int
030:             *  the initial number of buckets
031:             */
032:            public FloatCache(int initialCapacity) {
033:                this .elementSize = 0;
034:                this .keyTable = new float[initialCapacity];
035:                this .valueTable = new int[initialCapacity];
036:            }
037:
038:            /**
039:             * Clears the hash table so that it has no more elements in it.
040:             */
041:            public void clear() {
042:                for (int i = this .keyTable.length; --i >= 0;) {
043:                    this .keyTable[i] = 0.0f;
044:                    this .valueTable[i] = 0;
045:                }
046:                this .elementSize = 0;
047:            }
048:
049:            /** Returns true if the collection contains an element for the key.
050:             *
051:             * @param key <CODE>float</CODE> the key that we are looking for
052:             * @return boolean
053:             */
054:            public boolean containsKey(float key) {
055:                if (key == 0.0f) {
056:                    for (int i = 0, max = this .elementSize; i < max; i++) {
057:                        if (this .keyTable[i] == 0.0f) {
058:                            int value1 = Float.floatToIntBits(key);
059:                            int value2 = Float.floatToIntBits(this .keyTable[i]);
060:                            if (value1 == -2147483648 && value2 == -2147483648)
061:                                return true;
062:                            if (value1 == 0 && value2 == 0)
063:                                return true;
064:                        }
065:                    }
066:                } else {
067:                    for (int i = 0, max = this .elementSize; i < max; i++) {
068:                        if (this .keyTable[i] == key) {
069:                            return true;
070:                        }
071:                    }
072:                }
073:                return false;
074:            }
075:
076:            /**
077:             * Puts the specified element into the hashtable, using the specified
078:             * key.  The element may be retrieved by doing a get() with the same key.
079:             * 
080:             * @param key <CODE>float</CODE> the specified key in the hashtable
081:             * @param value <CODE>int</CODE> the specified element
082:             * @return int value
083:             */
084:            public int put(float key, int value) {
085:                if (this .elementSize == this .keyTable.length) {
086:                    // resize
087:                    System.arraycopy(this .keyTable, 0,
088:                            (this .keyTable = new float[this .elementSize * 2]),
089:                            0, this .elementSize);
090:                    System.arraycopy(this .valueTable, 0,
091:                            (this .valueTable = new int[this .elementSize * 2]),
092:                            0, this .elementSize);
093:                }
094:                this .keyTable[this .elementSize] = key;
095:                this .valueTable[this .elementSize] = value;
096:                this .elementSize++;
097:                return value;
098:            }
099:
100:            /**
101:             * Puts the specified element into the hashtable, using the specified
102:             * key.  The element may be retrieved by doing a get() with the same key.
103:             * 
104:             * @param key <CODE>float</CODE> the specified key in the hashtable
105:             * @param value <CODE>int</CODE> the specified element
106:             * @return int value
107:             */
108:            public int putIfAbsent(float key, int value) {
109:                if (key == 0.0f) {
110:                    for (int i = 0, max = this .elementSize; i < max; i++) {
111:                        if (this .keyTable[i] == 0.0f) {
112:                            int value1 = Float.floatToIntBits(key);
113:                            int value2 = Float.floatToIntBits(this .keyTable[i]);
114:                            if (value1 == -2147483648 && value2 == -2147483648)
115:                                return this .valueTable[i];
116:                            if (value1 == 0 && value2 == 0)
117:                                return this .valueTable[i];
118:                        }
119:                    }
120:                } else {
121:                    for (int i = 0, max = this .elementSize; i < max; i++) {
122:                        if (this .keyTable[i] == key) {
123:                            return this .valueTable[i];
124:                        }
125:                    }
126:                }
127:                if (this .elementSize == this .keyTable.length) {
128:                    // resize
129:                    System.arraycopy(this .keyTable, 0,
130:                            (this .keyTable = new float[this .elementSize * 2]),
131:                            0, this .elementSize);
132:                    System.arraycopy(this .valueTable, 0,
133:                            (this .valueTable = new int[this .elementSize * 2]),
134:                            0, this .elementSize);
135:                }
136:                this .keyTable[this .elementSize] = key;
137:                this .valueTable[this .elementSize] = value;
138:                this .elementSize++;
139:                return -value; // negative when added, assumes value is > 0
140:            }
141:
142:            /**
143:             * Converts to a rather lengthy String.
144:             *
145:             * @return String the ascii representation of the receiver
146:             */
147:            public String toString() {
148:                int max = this .elementSize;
149:                StringBuffer buf = new StringBuffer();
150:                buf.append("{"); //$NON-NLS-1$
151:                for (int i = 0; i < max; ++i) {
152:                    if ((this .keyTable[i] != 0)
153:                            || ((this .keyTable[i] == 0) && (this .valueTable[i] != 0))) {
154:                        buf.append(this .keyTable[i])
155:                                .append("->").append(this .valueTable[i]); //$NON-NLS-1$
156:                    }
157:                    if (i < max) {
158:                        buf.append(", "); //$NON-NLS-1$
159:                    }
160:                }
161:                buf.append("}"); //$NON-NLS-1$
162:                return buf.toString();
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.