Source Code Cross Referenced for UnmodifiableBoundedCollection.java in  » Library » Apache-common-Collections » org » apache » commons » collections » collection » 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 » Library » Apache common Collections » org.apache.commons.collections.collection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2003-2004 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections.collection;
017:
018:        import java.util.Collection;
019:        import java.util.Iterator;
020:
021:        import org.apache.commons.collections.BoundedCollection;
022:        import org.apache.commons.collections.iterators.UnmodifiableIterator;
023:
024:        /**
025:         * <code>UnmodifiableBoundedCollection</code> decorates another 
026:         * <code>BoundedCollection</code> to ensure it can't be altered.
027:         * <p>
028:         * If a BoundedCollection is first wrapped in some other collection decorator,
029:         * such as synchronized or predicated, the BoundedCollection methods are no 
030:         * longer accessible.
031:         * The factory on this class will attempt to retrieve the bounded nature by
032:         * examining the package scope variables.
033:         * <p>
034:         * This class is Serializable from Commons Collections 3.1.
035:         *
036:         * @since Commons Collections 3.0
037:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
038:         * 
039:         * @author Stephen Colebourne
040:         */
041:        public final class UnmodifiableBoundedCollection extends
042:                AbstractSerializableCollectionDecorator implements 
043:                BoundedCollection {
044:
045:            /** Serialization version */
046:            private static final long serialVersionUID = -7112672385450340330L;
047:
048:            /**
049:             * Factory method to create an unmodifiable bounded collection.
050:             * 
051:             * @param coll  the <code>BoundedCollection</code> to decorate, must not be null
052:             * @return a new unmodifiable bounded collection
053:             * @throws IllegalArgumentException if bag is null
054:             */
055:            public static BoundedCollection decorate(BoundedCollection coll) {
056:                return new UnmodifiableBoundedCollection(coll);
057:            }
058:
059:            /**
060:             * Factory method to create an unmodifiable bounded collection.
061:             * <p>
062:             * This method is capable of drilling down through up to 1000 other decorators 
063:             * to find a suitable BoundedCollection.
064:             * 
065:             * @param coll  the <code>BoundedCollection</code> to decorate, must not be null
066:             * @return a new unmodifiable bounded collection
067:             * @throws IllegalArgumentException if bag is null
068:             */
069:            public static BoundedCollection decorateUsing(Collection coll) {
070:                if (coll == null) {
071:                    throw new IllegalArgumentException(
072:                            "The collection must not be null");
073:                }
074:
075:                // handle decorators
076:                for (int i = 0; i < 1000; i++) { // counter to prevent infinite looping
077:                    if (coll instanceof  BoundedCollection) {
078:                        break; // normal loop exit
079:                    } else if (coll instanceof  AbstractCollectionDecorator) {
080:                        coll = ((AbstractCollectionDecorator) coll).collection;
081:                    } else if (coll instanceof  SynchronizedCollection) {
082:                        coll = ((SynchronizedCollection) coll).collection;
083:                    } else {
084:                        break; // normal loop exit
085:                    }
086:                }
087:
088:                if (coll instanceof  BoundedCollection == false) {
089:                    throw new IllegalArgumentException(
090:                            "The collection is not a bounded collection");
091:                }
092:                return new UnmodifiableBoundedCollection(
093:                        (BoundedCollection) coll);
094:            }
095:
096:            /**
097:             * Constructor that wraps (not copies).
098:             * 
099:             * @param coll  the collection to decorate, must not be null
100:             * @throws IllegalArgumentException if coll is null
101:             */
102:            private UnmodifiableBoundedCollection(BoundedCollection coll) {
103:                super (coll);
104:            }
105:
106:            //-----------------------------------------------------------------------
107:            public Iterator iterator() {
108:                return UnmodifiableIterator
109:                        .decorate(getCollection().iterator());
110:            }
111:
112:            public boolean add(Object object) {
113:                throw new UnsupportedOperationException();
114:            }
115:
116:            public boolean addAll(Collection coll) {
117:                throw new UnsupportedOperationException();
118:            }
119:
120:            public void clear() {
121:                throw new UnsupportedOperationException();
122:            }
123:
124:            public boolean remove(Object object) {
125:                throw new UnsupportedOperationException();
126:            }
127:
128:            public boolean removeAll(Collection coll) {
129:                throw new UnsupportedOperationException();
130:            }
131:
132:            public boolean retainAll(Collection coll) {
133:                throw new UnsupportedOperationException();
134:            }
135:
136:            //-----------------------------------------------------------------------    
137:            public boolean isFull() {
138:                return ((BoundedCollection) collection).isFull();
139:            }
140:
141:            public int maxSize() {
142:                return ((BoundedCollection) collection).maxSize();
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.