Source Code Cross Referenced for AbstractSet.java in  » 6.0-JDK-Modules » j2me » java » 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 » 6.0 JDK Modules » j2me » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)AbstractSet.java	1.21 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.  
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER  
006:         *   
007:         * This program is free software; you can redistribute it and/or  
008:         * modify it under the terms of the GNU General Public License version  
009:         * 2 only, as published by the Free Software Foundation.   
010:         *   
011:         * This program is distributed in the hope that it will be useful, but  
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of  
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  
014:         * General Public License version 2 for more details (a copy is  
015:         * included at /legal/license.txt).   
016:         *   
017:         * You should have received a copy of the GNU General Public License  
018:         * version 2 along with this work; if not, write to the Free Software  
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
020:         * 02110-1301 USA   
021:         *   
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa  
023:         * Clara, CA 95054 or visit www.sun.com if you need additional  
024:         * information or have any questions. 
025:         *
026:         */
027:
028:        package java.util;
029:
030:        /**
031:         * This class provides a skeletal implementation of the <tt>Set</tt>
032:         * interface to minimize the effort required to implement this
033:         * interface. <p>
034:         *
035:         * The process of implementing a set by extending this class is identical
036:         * to that of implementing a Collection by extending AbstractCollection,
037:         * except that all of the methods and constructors in subclasses of this
038:         * class must obey the additional constraints imposed by the <tt>Set</tt>
039:         * interface (for instance, the add method must not permit addition of
040:         * multiple intances of an object to a set).<p>
041:         *
042:         * Note that this class does not override any of the implementations from
043:         * the <tt>AbstractCollection</tt> class.  It merely adds implementations
044:         * for <tt>equals</tt> and <tt>hashCode</tt>.<p>
045:         *
046:         * This class is a member of the 
047:         * <a href="{@docRoot}/../guide/collections/index.html">
048:         * Java Collections Framework</a>.
049:         *
050:         * @author  Josh Bloch
051:         * @version 1.14, 02/02/00
052:         * @see Collection
053:         * @see AbstractCollection
054:         * @see Set
055:         * @since 1.2
056:         */
057:
058:        public abstract class AbstractSet extends AbstractCollection implements 
059:                Set {
060:            /**
061:             * Sole constructor.  (For invocation by subclass constructors, typically
062:             * implicit.)
063:             */
064:            protected AbstractSet() {
065:            }
066:
067:            // Comparison and hashing
068:
069:            /**
070:             * Compares the specified object with this set for equality.  Returns
071:             * <tt>true</tt> if the given object is also a set, the two sets have
072:             * the same size, and every member of the given set is contained in
073:             * this set.  This ensures that the <tt>equals</tt> method works
074:             * properly across different implementations of the <tt>Set</tt>
075:             * interface.<p>
076:             *
077:             * This implementation first checks if the specified object is this
078:             * set; if so it returns <tt>true</tt>.  Then, it checks if the
079:             * specified object is a set whose size is identical to the size of
080:             * this set; if not, it it returns false.  If so, it returns
081:             * <tt>containsAll((Collection) o)</tt>.
082:             *
083:             * @param o Object to be compared for equality with this set.
084:             * @return <tt>true</tt> if the specified object is equal to this set.
085:             */
086:            public boolean equals(Object o) {
087:                if (o == this )
088:                    return true;
089:
090:                if (!(o instanceof  Set))
091:                    return false;
092:                Collection c = (Collection) o;
093:                if (c.size() != size())
094:                    return false;
095:                try {
096:                    return containsAll(c);
097:                } catch (ClassCastException unused) {
098:                    return false;
099:                } catch (NullPointerException unused) {
100:                    return false;
101:                }
102:            }
103:
104:            /**
105:             * Returns the hash code value for this set.  The hash code of a set is
106:             * defined to be the sum of the hash codes of the elements in the set.
107:             * This ensures that <tt>s1.equals(s2)</tt> implies that
108:             * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
109:             * and <tt>s2</tt>, as required by the general contract of
110:             * Object.hashCode.<p>
111:             *
112:             * This implementation enumerates over the set, calling the
113:             * <tt>hashCode</tt> method on each element in the collection, and
114:             * adding up the results.
115:             *
116:             * @return the hash code value for this set.
117:             */
118:            public int hashCode() {
119:                int h = 0;
120:                Iterator i = iterator();
121:                while (i.hasNext()) {
122:                    Object obj = i.next();
123:                    if (obj != null)
124:                        h += obj.hashCode();
125:                }
126:                return h;
127:            }
128:
129:            /**
130:             * Removes from this set all of its elements that are contained in
131:             * the specified collection (optional operation).<p>
132:             *
133:             * This implementation determines which is the smaller of this set
134:             * and the specified collection, by invoking the <tt>size</tt>
135:             * method on each.  If this set has fewer elements, then the
136:             * implementation iterates over this set, checking each element
137:             * returned by the iterator in turn to see if it is contained in
138:             * the specified collection.  If it is so contained, it is removed
139:             * from this set with the iterator's <tt>remove</tt> method.  If
140:             * the specified collection has fewer elements, then the
141:             * implementation iterates over the specified collection, removing
142:             * from this set each element returned by the iterator, using this
143:             * set's <tt>remove</tt> method.<p>
144:             *
145:             * Note that this implementation will throw an
146:             * <tt>UnsupportedOperationException</tt> if the iterator returned by the
147:             * <tt>iterator</tt> method does not implement the <tt>remove</tt> method.
148:             *
149:             * @param c elements to be removed from this set.
150:             * @return <tt>true</tt> if this set changed as a result of the call.
151:             *
152:             * @throws    UnsupportedOperationException removeAll is not supported
153:             *            by this set.
154:             * @throws    NullPointerException if the specified collection is null.
155:             * @see #remove(Object)
156:             * @see #contains(Object)
157:             */
158:            public boolean removeAll(Collection c) {
159:                boolean modified = false;
160:
161:                if (size() > c.size()) {
162:                    for (Iterator i = c.iterator(); i.hasNext();)
163:                        modified |= remove(i.next());
164:                } else {
165:                    for (Iterator i = iterator(); i.hasNext();) {
166:                        if (c.contains(i.next())) {
167:                            i.remove();
168:                            modified = true;
169:                        }
170:                    }
171:                }
172:                return modified;
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.