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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.util;
011:
012:        /**
013:         * A simple lookup table is a non-synchronized Hashtable, whose keys
014:         * and values are Objects. It also uses linear probing to resolve collisions
015:         * rather than a linked list of hash table entries.
016:         */
017:        public final class SimpleSet implements  Cloneable {
018:
019:            // to avoid using Enumerations, walk the individual values skipping nulls
020:            public Object[] values;
021:            public int elementSize; // number of elements in the table
022:            public int threshold;
023:
024:            public SimpleSet() {
025:                this (13);
026:            }
027:
028:            public SimpleSet(int size) {
029:                if (size < 3)
030:                    size = 3;
031:                this .elementSize = 0;
032:                this .threshold = size + 1; // size is the expected number of elements
033:                this .values = new Object[2 * size + 1];
034:            }
035:
036:            public Object add(Object object) {
037:                int length = this .values.length;
038:                int index = (object.hashCode() & 0x7FFFFFFF) % length;
039:                Object current;
040:                while ((current = this .values[index]) != null) {
041:                    if (current.equals(object))
042:                        return this .values[index] = object;
043:                    if (++index == length)
044:                        index = 0;
045:                }
046:                this .values[index] = object;
047:
048:                // assumes the threshold is never equal to the size of the table
049:                if (++this .elementSize > this .threshold)
050:                    rehash();
051:                return object;
052:            }
053:
054:            public Object addIfNotIncluded(Object object) {
055:                int length = this .values.length;
056:                int index = (object.hashCode() & 0x7FFFFFFF) % length;
057:                Object current;
058:                while ((current = this .values[index]) != null) {
059:                    if (current.equals(object))
060:                        return null; // already existed
061:                    if (++index == length)
062:                        index = 0;
063:                }
064:                this .values[index] = object;
065:
066:                // assumes the threshold is never equal to the size of the table
067:                if (++this .elementSize > this .threshold)
068:                    rehash();
069:                return object;
070:            }
071:
072:            public void asArray(Object[] copy) {
073:                if (this .elementSize != copy.length)
074:                    throw new IllegalArgumentException();
075:                int index = this .elementSize;
076:                for (int i = 0, l = this .values.length; i < l && index > 0; i++)
077:                    if (this .values[i] != null)
078:                        copy[--index] = this .values[i];
079:            }
080:
081:            public void clear() {
082:                for (int i = this .values.length; --i >= 0;)
083:                    this .values[i] = null;
084:                this .elementSize = 0;
085:            }
086:
087:            public Object clone() throws CloneNotSupportedException {
088:                SimpleSet result = (SimpleSet) super .clone();
089:                result.elementSize = this .elementSize;
090:                result.threshold = this .threshold;
091:
092:                int length = this .values.length;
093:                result.values = new Object[length];
094:                System.arraycopy(this .values, 0, result.values, 0, length);
095:                return result;
096:            }
097:
098:            public boolean includes(Object object) {
099:                int length = values.length;
100:                int index = (object.hashCode() & 0x7FFFFFFF) % length;
101:                Object current;
102:                while ((current = values[index]) != null) {
103:                    if (current.equals(object))
104:                        return true;
105:                    if (++index == length)
106:                        index = 0;
107:                }
108:                return false;
109:            }
110:
111:            public Object remove(Object object) {
112:                int length = values.length;
113:                int index = (object.hashCode() & 0x7FFFFFFF) % length;
114:                Object current;
115:                while ((current = values[index]) != null) {
116:                    if (current.equals(object)) {
117:                        elementSize--;
118:                        Object oldValue = values[index];
119:                        values[index] = null;
120:                        if (values[index + 1 == length ? 0 : index + 1] != null)
121:                            rehash(); // only needed if a possible collision existed
122:                        return oldValue;
123:                    }
124:                    if (++index == length)
125:                        index = 0;
126:                }
127:                return null;
128:            }
129:
130:            private void rehash() {
131:                SimpleSet newSet = new SimpleSet(elementSize * 2); // double the number of expected elements
132:                Object current;
133:                for (int i = values.length; --i >= 0;)
134:                    if ((current = values[i]) != null)
135:                        newSet.add(current);
136:
137:                this .values = newSet.values;
138:                this .elementSize = newSet.elementSize;
139:                this .threshold = newSet.threshold;
140:            }
141:
142:            public String toString() {
143:                String s = ""; //$NON-NLS-1$
144:                Object object;
145:                for (int i = 0, l = values.length; i < l; i++)
146:                    if ((object = values[i]) != null)
147:                        s += object.toString() + "\n"; //$NON-NLS-1$
148:                return s;
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.