Source Code Cross Referenced for CollectionToLongCollectionAdapter.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, 2003  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.Adapter;
022:        import bak.pcj.AbstractLongCollection;
023:        import bak.pcj.LongIterator;
024:        import bak.pcj.util.Exceptions;
025:        import java.util.Collection;
026:        import java.util.AbstractCollection;
027:        import java.util.Iterator;
028:
029:        /**
030:         *  This class represents adaptions of Java Collections Framework
031:         *  collections to primitive collections of long values.
032:         *  The adapter is implemented as a wrapper around the collection. 
033:         *  Thus, changes to the underlying collection are reflected by this
034:         *  collection and vice versa.
035:         *
036:         *  <p>
037:         *  Adapters from JCF collections to primitive collections will
038:         *  fail if the JCF collection contains <tt>null</tt> values or
039:         *  values of the wrong class. However, adapters are not fast
040:         *  failing in the case that the underlying collection should
041:         *  contain illegal values. To implement fast failure would require
042:         *  every operation to check every element of the underlying
043:         *  collection before doing anything. Instead validation methods
044:         *  are provided. They can be called using the assertion facility
045:         *  in the client code:
046:         *  <pre>
047:         *      CollectionToLongCollectionAdapter s;
048:         *      ...
049:         *      <b>assert</b> s.validate();
050:         *  </pre>
051:         *  or by letting the adapter throw an exception on illegal values:
052:         *  <pre>
053:         *      CollectionToLongCollectionAdapter s;
054:         *      ...
055:         *      s.evalidate();  // Throws an exception on illegal values
056:         *  </pre>
057:         *  Either way, validation must be invoked directly by the client
058:         *  code.
059:         *
060:         *  @author     S&oslash;ren Bak
061:         *  @version    1.2     20-08-2003 23:18
062:         *  @since      1.0
063:         */
064:        public class CollectionToLongCollectionAdapter extends
065:                AbstractLongCollection {
066:
067:            /** The underlying collection. */
068:            protected Collection collection;
069:
070:            /**
071:             *  Creates a new adaption of a collection to a collection of long
072:             *  values.
073:             *
074:             *  @param      collection
075:             *              the underlying collection. This collection must
076:             *              consist of values of class
077:             *              {@link Long Long}. Otherwise a
078:             *              {@link ClassCastException ClassCastException}
079:             *              will be thrown by some methods.
080:             *
081:             *  @throws     NullPointerException
082:             *              if <tt>collection</tt> is <tt>null</tt>.
083:             */
084:            public CollectionToLongCollectionAdapter(Collection collection) {
085:                this (collection, false);
086:            }
087:
088:            /**
089:             *  Creates a new adaption of a collection to a collection of long
090:             *  values. The collection to adapt is optionally validated.
091:             *
092:             *  @param      collection
093:             *              the underlying collection. This collection must
094:             *              consist of values of class
095:             *              {@link Long Long}. Otherwise a
096:             *              {@link ClassCastException ClassCastException}
097:             *              will be thrown by some methods.
098:             *
099:             *  @param      validate
100:             *              indicates whether <tt>collection</tt> should
101:             *              be checked for illegal values.
102:             *
103:             *  @throws     NullPointerException
104:             *              if <tt>collection</tt> is <tt>null</tt>.
105:             *
106:             *  @throws     IllegalStateException
107:             *              if <tt>validate</tt> is <tt>true</tt> and
108:             *              <tt>collection</tt> contains a <tt>null</tt> value
109:             *              or a value that is not of class
110:             *              {@link Long Long}.
111:             */
112:            public CollectionToLongCollectionAdapter(Collection collection,
113:                    boolean validate) {
114:                super ();
115:                if (collection == null)
116:                    Exceptions.nullArgument("collection");
117:                this .collection = collection;
118:                if (validate)
119:                    evalidate();
120:            }
121:
122:            public boolean add(long v) {
123:                return collection.add(new Long(v));
124:            }
125:
126:            public void clear() {
127:                collection.clear();
128:            }
129:
130:            public boolean contains(long v) {
131:                return collection.contains(new Long(v));
132:            }
133:
134:            public int hashCode() {
135:                return collection.hashCode();
136:            }
137:
138:            public LongIterator iterator() {
139:                return new IteratorToLongIteratorAdapter(collection.iterator());
140:            }
141:
142:            public boolean remove(long v) {
143:                return collection.remove(new Long(v));
144:            }
145:
146:            public int size() {
147:                return collection.size();
148:            }
149:
150:            /**
151:             *  Indicates whether the underlying collection is valid for
152:             *  this adapter. For the underlying collection to be valid, it
153:             *  can only contain {@link Long Long} values and no <tt>null</tt>
154:             *  values.
155:             *
156:             *  @return     <tt>true</tt> if the underlying collection is
157:             *              valid; returns <tt>false</tt> otherwise.
158:             */
159:            public boolean validate() {
160:                return Adapter.isLongAdaptable(collection);
161:            }
162:
163:            /**
164:             *  Validates the collection underlying this adapter and throws
165:             *  an exception if it is invalid. For the underlying collection
166:             *  to be valid, it can only contain {@link Long Long}
167:             *  values and no <tt>null</tt> values.
168:             *
169:             *  @throws     IllegalStateException
170:             *              if the underlying collection is invalid.
171:             */
172:            public void evalidate() {
173:                if (!validate())
174:                    Exceptions.cannotAdapt("collection");
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.