Source Code Cross Referenced for ShortSetToSetAdapter.java in  » Development » PCJ » bak » pcj » adapter » 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 » Development » PCJ » bak.pcj.adapter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Primitive Collections for Java.
003:         *  Copyright (C) 2002  Søren Bak
004:         *
005:         *  This library is free software; you can redistribute it and/or
006:         *  modify it under the terms of the GNU Lesser General Public
007:         *  License as published by the Free Software Foundation; either
008:         *  version 2.1 of the License, or (at your option) any later version.
009:         *
010:         *  This library is distributed in the hope that it will be useful,
011:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         *  Lesser General Public License for more details.
014:         *
015:         *  You should have received a copy of the GNU Lesser General Public
016:         *  License along with this library; if not, write to the Free Software
017:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package bak.pcj.adapter;
020:
021:        import bak.pcj.set.ShortSet;
022:        import bak.pcj.adapter.ShortIteratorToIteratorAdapter;
023:        import bak.pcj.util.Exceptions;
024:
025:        import java.util.AbstractSet;
026:        import java.util.Iterator;
027:        import java.util.Collection;
028:
029:        /**
030:         *  This class represents adapters of short sets to Java Collections
031:         *  Framework sets. The adapter
032:         *  is implemented as a wrapper around a primitive set. Thus, 
033:         *  changes to the underlying set are reflected by this
034:         *  set and vice versa.
035:         *
036:         *  @see        ShortSet
037:         *  @see        java.util.Set
038:         *
039:         *  @author     Søren Bak
040:         *  @version    1.2     20-08-2003 22:56
041:         *  @since      1.0
042:         */
043:        public class ShortSetToSetAdapter extends AbstractSet {
044:
045:            /** The underlying primitive set. */
046:            protected ShortSet set;
047:
048:            /**
049:             *  Creates a new adaption of a set of short
050:             *  values to a Java Collections Framework set.
051:             *
052:             *  @param      set
053:             *              the underlying primitive set.
054:             *
055:             *  @throws     NullPointerException
056:             *              if <tt>set</tt> is <tt>null</tt>.
057:             */
058:            public ShortSetToSetAdapter(ShortSet set) {
059:                if (set == null)
060:                    Exceptions.nullArgument("set");
061:                this .set = set;
062:            }
063:
064:            /**
065:             *  Adds an element to this set. The unwrapped element is added
066:             *  to the underlying set.
067:             *
068:             *  @param      o
069:             *              the element to add to this set.
070:             *
071:             *  @return     <tt>true</tt> if this set was modified
072:             *              as a result of adding <tt>o</tt>; returns
073:             *              <tt>false</tt> otherwise.
074:             *
075:             *  @throws     IllegalArgumentException
076:             *              if <tt>o</tt> is <tt>null</tt>.
077:             *
078:             *  @throws     ClassCastException
079:             *              if <tt>o</tt> is not of class {@link Short Short}.
080:             *
081:             *  @throws     UnsupportedOperationException
082:             *              if the operation is not supported by the
083:             *              underlying set.
084:             */
085:            public boolean add(Object o) {
086:                if (o == null)
087:                    Exceptions.nullElementNotAllowed();
088:                return set.add(((Short) o).shortValue());
089:            }
090:
091:            /**
092:             *  Clears this collection. The underlying set is
093:             *  cleared.
094:             *
095:             *  @throws     UnsupportedOperationException
096:             *              if the operation is not supported by the
097:             *              underlying set.
098:             */
099:            public void clear() {
100:                set.clear();
101:            }
102:
103:            /**
104:             *  Indicates whether this set contains a specified
105:             *  element. For this set to contain an object, the
106:             *  underlying set must contain its unwrapped value.
107:             *  <p>Note that this set can never contain <tt>null</tt>
108:             *  values or values of other classes than {@link Short Short}.
109:             *  In those cases, this method will return <tt>false</tt>.
110:             *
111:             *  @param      o
112:             *              the element to test for containment.
113:             *
114:             *  @return     <tt>true</tt> if <tt>o</tt> is contained in this
115:             *              set; returns <tt>false</tt> otherwise.
116:             */
117:            public boolean contains(Object o) {
118:                try {
119:                    return set.contains(((Short) o).shortValue());
120:                } catch (ClassCastException cce) {
121:                } catch (NullPointerException npe) {
122:                }
123:                return false;
124:            }
125:
126:            /**
127:             *  Returns a hash code value for this set. The hash code
128:             *  returned is that of the underlying set.
129:             *
130:             *  @return     a hash code value for this set.
131:             */
132:            public int hashCode() {
133:                return set.hashCode();
134:            }
135:
136:            /**
137:             *  Returns an iterator over this set.
138:             *
139:             *  @return     an iterator over this set.
140:             */
141:            public Iterator iterator() {
142:                return new ShortIteratorToIteratorAdapter(set.iterator());
143:            }
144:
145:            /**
146:             *  Removes a specified element from this set.
147:             *  The unwrapped element is removed from the underlying set.
148:             *  <p>Note that this set can never contain <tt>null</tt>
149:             *  values or values of other classes than {@link Short Short}.
150:             *  In those cases, this method will return <tt>false</tt>.
151:             *
152:             *  @param      o
153:             *              the Short value to remove from this set.
154:             *
155:             *  @return     <tt>true</tt> if this set was modified
156:             *              as a result of removing <tt>o</tt>; returns
157:             *              <tt>false</tt> otherwise.
158:             *
159:             *  @throws     UnsupportedOperationException
160:             *              if the operation is not supported by the 
161:             *              underlying set.
162:             */
163:            public boolean remove(Object o) {
164:                try {
165:                    return set.remove(((Short) o).shortValue());
166:                } catch (ClassCastException cce) {
167:                } catch (NullPointerException npe) {
168:                }
169:                return false;
170:            }
171:
172:            /**
173:             *  Retains only the elements of a specified collection in
174:             *  this set. The unwrapped elements are removed from
175:             *  the underlying set.
176:             *  <p>This method is only overridden to work
177:             *  around a bug in {@link AbstractSet AbstractSet},
178:             *  which does not throw a 
179:             *  {@link NullPointerException NullPointerException} when the
180:             *  argument is <tt>null</tt> and the set is empty. The
181:             *  bug is inherited from {@link java.util.AbstractCollection java.util.AbstractCollection}.
182:             *
183:             *  @param      c
184:             *              the collection whose elements to retain in this
185:             *              collection.
186:             *
187:             *  @return     <tt>true</tt> if this set was modified
188:             *              as a result of removing the elements not contained
189:             *              in <tt>c</tt>;
190:             *              returns <tt>false</tt> otherwise.
191:             *
192:             *  @throws     UnsupportedOperationException
193:             *              if the operation is not supported by the underlying
194:             *              set.
195:             *
196:             *  @throws     NullPointerException
197:             *              if <tt>c</tt> is <tt>null</tt>.
198:             */
199:            public boolean retainAll(Collection c) {
200:                if (c == null)
201:                    Exceptions.nullArgument("collection");
202:                return super .retainAll(c);
203:            }
204:
205:            /**
206:             *  Returns the number of elements in this set. The
207:             *  number of elements is the same as that of the underlying
208:             *  set.
209:             *
210:             *  @return     the number of elements in this set.
211:             */
212:            public int size() {
213:                return set.size();
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.