Source Code Cross Referenced for BooleanCollectionToCollectionAdapter.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.BooleanCollection;
022:        import bak.pcj.util.Exceptions;
023:        import java.util.Collection;
024:        import java.util.AbstractCollection;
025:        import java.util.Iterator;
026:
027:        /**
028:         *  This class represents adaptions of primitive collections of
029:         *  boolean values to Java Collections Framework collections. The adapter
030:         *  is implemented as a wrapper around a primitive collection. Thus, 
031:         *  changes to the underlying collection are reflected by this
032:         *  collection and vice versa.
033:         *
034:         *  @see        BooleanCollection
035:         *  @see        java.util.Collection
036:         *
037:         *  @author     Søren Bak
038:         *  @version    1.2     21-08-2003 19:01
039:         *  @since      1.0
040:         */
041:        public class BooleanCollectionToCollectionAdapter extends
042:                AbstractCollection {
043:
044:            /** The underlying primitive collection. */
045:            protected BooleanCollection collection;
046:
047:            /**
048:             *  Creates a new adaption of a collection of boolean
049:             *  values to a Java Collections Framework collection.
050:             *
051:             *  @param      collection
052:             *              the underlying primitive collection.
053:             *
054:             *  @throws     NullPointerException
055:             *              if <tt>collection</tt> is <tt>null</tt>.
056:             */
057:            public BooleanCollectionToCollectionAdapter(
058:                    BooleanCollection collection) {
059:                super ();
060:                if (collection == null)
061:                    Exceptions.nullArgument("collection");
062:                this .collection = collection;
063:            }
064:
065:            /**
066:             *  Adds an element to this collection. The element is added
067:             *  to the underlying collection.
068:             *
069:             *  @param      o
070:             *              the element to add to this collection.
071:             *
072:             *  @return     <tt>true</tt> if this collection was modified
073:             *              as a result of adding <tt>o</tt>; returns
074:             *              <tt>false</tt> otherwise.
075:             *
076:             *  @throws     IllegalArgumentException
077:             *              if <tt>o</tt> is <tt>null</tt>.
078:             *
079:             *  @throws     ClassCastException
080:             *              if <tt>o</tt> is not of class {@link Boolean Boolean}.
081:             *
082:             *  @throws     UnsupportedOperationException
083:             *              if the operation is not supported by the
084:             *              underlying collection.
085:             */
086:            public boolean add(Object o) {
087:                if (o == null)
088:                    Exceptions.nullElementNotAllowed();
089:                return collection.add(((Boolean) o).booleanValue());
090:            }
091:
092:            /**
093:             *  Clears this collection. The underlying collection is
094:             *  cleared.
095:             *
096:             *  @throws     UnsupportedOperationException
097:             *              if the operation is not supported by the
098:             *              underlying collection.
099:             */
100:            public void clear() {
101:                collection.clear();
102:            }
103:
104:            /**
105:             *  Indicates whether this collection contains a specified
106:             *  element. For this collection to contain an object, the
107:             *  underlying collection must contain its unwrapped value.
108:             *  <p>Note that this collection can never contain <tt>null</tt>
109:             *  values or values of other classes than {@link Boolean Boolean}.
110:             *  In those cases, this method will return <tt>false</tt>.
111:             *
112:             *  @param      o
113:             *              the element to test for containment.
114:             *
115:             *  @return     <tt>true</tt> if <tt>o</tt> is contained in this
116:             *              collection; returns <tt>false</tt> otherwise.
117:             */
118:            public boolean contains(Object o) {
119:                try {
120:                    return collection.contains(((Boolean) o).booleanValue());
121:                } catch (ClassCastException cce) {
122:                } catch (NullPointerException npe) {
123:                }
124:                return false;
125:            }
126:
127:            /**
128:             *  Returns an iterator over this collection.
129:             *
130:             *  @return     an iterator over this collection.
131:             */
132:            public Iterator iterator() {
133:                return new BooleanIteratorToIteratorAdapter(collection
134:                        .iterator());
135:            }
136:
137:            /**
138:             *  Removes a specified element from this collection.
139:             *  The unwrapped element is removed from the underlying collection.
140:             *  <p>Note that this collection can never contain <tt>null</tt>
141:             *  values or values of other classes than {@link Boolean Boolean}.
142:             *  In those cases, this method will return <tt>false</tt>.
143:             *
144:             *  @param      o
145:             *              the Boolean value to remove from this collection.
146:             *
147:             *  @return     <tt>true</tt> if this collection was modified
148:             *              as a result of removing <tt>o</tt>; returns
149:             *              <tt>false</tt> otherwise.
150:             *
151:             *  @throws     UnsupportedOperationException
152:             *              if the operation is not supported by the 
153:             *              underlying collection.
154:             */
155:            public boolean remove(Object o) {
156:                try {
157:                    return collection.remove(((Boolean) o).booleanValue());
158:                } catch (ClassCastException cce) {
159:                } catch (NullPointerException npe) {
160:                }
161:                return false;
162:            }
163:
164:            /**
165:             *  Removes all the elements of a specified collection from
166:             *  this collection. The unwrapped elements are removed from
167:             *  the underlying collection.
168:             *  <p>This method is only overridden to work
169:             *  around a bug in {@link AbstractCollection AbstractCollection},
170:             *  which does not throw a 
171:             *  {@link NullPointerException NullPointerException} when the
172:             *  argument is <tt>null</tt> and the collection is empty.
173:             *
174:             *  @param      c
175:             *              the collection whose elements to remove from this
176:             *              collection.
177:             *
178:             *  @return     <tt>true</tt> if this collection was modified
179:             *              as a result of removing the elements of <tt>c</tt>;
180:             *              returns <tt>false</tt> otherwise.
181:             *
182:             *  @throws     UnsupportedOperationException
183:             *              if the operation is not supported by the underlying
184:             *              collection.
185:             *
186:             *  @throws     NullPointerException
187:             *              if <tt>c</tt> is <tt>null</tt>.
188:             */
189:            public boolean removeAll(Collection c) {
190:                if (c == null)
191:                    Exceptions.nullArgument("collection");
192:                return super .removeAll(c);
193:            }
194:
195:            /**
196:             *  Retains only the elements of a specified collection in
197:             *  this collection. The unwrapped elements are removed from
198:             *  the underlying collection.
199:             *  <p>This method is only overridden to work
200:             *  around a bug in {@link AbstractCollection AbstractCollection},
201:             *  which does not throw a 
202:             *  {@link NullPointerException NullPointerException} when the
203:             *  argument is <tt>null</tt> and the collection is empty.
204:             *
205:             *  @param      c
206:             *              the collection whose elements to retain in this
207:             *              collection.
208:             *
209:             *  @return     <tt>true</tt> if this collection was modified
210:             *              as a result of removing the elements not contained
211:             *              in <tt>c</tt>;
212:             *              returns <tt>false</tt> otherwise.
213:             *
214:             *  @throws     UnsupportedOperationException
215:             *              if the operation is not supported by the underlying
216:             *              collection.
217:             *
218:             *  @throws     NullPointerException
219:             *              if <tt>c</tt> is <tt>null</tt>.
220:             */
221:            public boolean retainAll(Collection c) {
222:                if (c == null)
223:                    Exceptions.nullArgument("collection");
224:                return super .retainAll(c);
225:            }
226:
227:            /**
228:             *  Returns the number of elements in this collection. The
229:             *  number of elements is the same as that of the underlying
230:             *  collection.
231:             *
232:             *  @return     the number of elements in this collection.
233:             */
234:            public int size() {
235:                return collection.size();
236:            }
237:
238:            /**
239:             *  Returns a hash code value for this collection. The hash code
240:             *  returned is that of the underlying collection.
241:             *
242:             *  @return     a hash code value for this collection.
243:             */
244:            public int hashCode() {
245:                return collection.hashCode();
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.