Source Code Cross Referenced for ConcurrentHashSet.java in  » Net » openfire » org » jivesoftware » 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 » Net » openfire » org.jivesoftware.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $RCSfile$
003:         * $Revision: 42 $
004:         * $Date: 2004-10-21 00:28:12 -0700 (Thu, 21 Oct 2004) $
005:         *
006:         * Copyright (C) 2004 Jive Software. All rights reserved.
007:         *
008:         * This software is published under the terms of the GNU Public License (GPL),
009:         * a copy of which is included in this distribution.
010:         */package org.jivesoftware.util;
011:
012:        import java.util.*;
013:        import java.util.concurrent.ConcurrentHashMap;
014:
015:        /**
016:         * This class implements the <tt>Set</tt> interface, backed by a ConcurrentHashMap instance.
017:         *
018:         * @author Matt Tucker
019:         */
020:        public class ConcurrentHashSet<E> extends AbstractSet<E> implements 
021:                Set<E>, Cloneable, java.io.Serializable {
022:
023:            private transient ConcurrentHashMap<E, Object> map;
024:
025:            // Dummy value to associate with an Object in the backing Map
026:            private static final Object PRESENT = new Object();
027:
028:            /**
029:             * Constructs a new, empty set; the backing <tt>ConcurrentHashMap</tt> instance has
030:             * default initial capacity (16) and load factor (0.75).
031:             */
032:            public ConcurrentHashSet() {
033:                map = new ConcurrentHashMap<E, Object>();
034:            }
035:
036:            /**
037:             * Constructs a new set containing the elements in the specified
038:             * collection.  The <tt>ConcurrentHashMap</tt> is created with default load factor
039:             * (0.75) and an initial capacity sufficient to contain the elements in
040:             * the specified collection.
041:             *
042:             * @param c the collection whose elements are to be placed into this set.
043:             * @throws NullPointerException   if the specified collection is null.
044:             */
045:            public ConcurrentHashSet(Collection<? extends E> c) {
046:                map = new ConcurrentHashMap<E, Object>(Math.max(
047:                        (int) (c.size() / .75f) + 1, 16));
048:                addAll(c);
049:            }
050:
051:            /**
052:             * Constructs a new, empty set; the backing <tt>ConcurrentHashMap</tt> instance has
053:             * the specified initial capacity and the specified load factor.
054:             *
055:             * @param initialCapacity the initial capacity of the hash map.
056:             * @param loadFactor the load factor of the hash map.
057:             * @throws IllegalArgumentException if the initial capacity is less
058:             *      than zero, or if the load factor is nonpositive.
059:             */
060:            public ConcurrentHashSet(int initialCapacity, float loadFactor) {
061:                map = new ConcurrentHashMap<E, Object>(initialCapacity,
062:                        loadFactor, 16);
063:            }
064:
065:            /**
066:             * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
067:             * the specified initial capacity and default load factor, which is
068:             * <tt>0.75</tt>.
069:             *
070:             * @param      initialCapacity   the initial capacity of the hash table.
071:             * @throws     IllegalArgumentException if the initial capacity is less
072:             *             than zero.
073:             */
074:            public ConcurrentHashSet(int initialCapacity) {
075:                map = new ConcurrentHashMap<E, Object>(initialCapacity);
076:            }
077:
078:            public Iterator<E> iterator() {
079:                return map.keySet().iterator();
080:            }
081:
082:            public int size() {
083:                return map.size();
084:            }
085:
086:            public boolean isEmpty() {
087:                return map.isEmpty();
088:            }
089:
090:            public boolean contains(Object o) {
091:                return map.containsKey(o);
092:            }
093:
094:            public boolean add(E o) {
095:                return map.put(o, PRESENT) == null;
096:            }
097:
098:            public boolean remove(Object o) {
099:                return map.remove(o) == PRESENT;
100:            }
101:
102:            public void clear() {
103:                map.clear();
104:            }
105:
106:            public Object clone() {
107:                try {
108:                    ConcurrentHashSet<E> newSet = (ConcurrentHashSet<E>) super 
109:                            .clone();
110:                    newSet.map.putAll(map);
111:                    return newSet;
112:                } catch (CloneNotSupportedException e) {
113:                    throw new InternalError();
114:                }
115:            }
116:
117:            private void writeObject(java.io.ObjectOutputStream s)
118:                    throws java.io.IOException {
119:                s.defaultWriteObject();
120:
121:                // Write out size
122:                s.writeInt(map.size());
123:
124:                // Write out all elements in the proper order.
125:                for (Iterator i = map.keySet().iterator(); i.hasNext();)
126:                    s.writeObject(i.next());
127:            }
128:
129:            /**
130:             * Reconstitute the <tt>HashSet</tt> instance from a stream (that is,
131:             * deserialize it).
132:             */
133:            private void readObject(java.io.ObjectInputStream s)
134:                    throws java.io.IOException, ClassNotFoundException {
135:                s.defaultReadObject();
136:
137:                map = new ConcurrentHashMap<E, Object>();
138:
139:                // Read in size
140:                int size = s.readInt();
141:
142:                // Read in all elements in the proper order.
143:                for (int i = 0; i < size; i++) {
144:                    E e = (E) s.readObject();
145:                    map.put(e, PRESENT);
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.