Source Code Cross Referenced for CheckedArrayList.java in  » GIS » GeoTools-2.4.1 » org » geotools » 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 » GIS » GeoTools 2.4.1 » org.geotools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.util;
017:
018:        // J2SE dependencies
019:        import java.util.ArrayList;
020:        import java.util.Collection;
021:        import java.util.Iterator;
022:
023:        // OpenGIS dependencies
024:        import org.opengis.util.Cloneable;
025:
026:        // Geotools dependencies
027:        import org.geotools.resources.Utilities;
028:        import org.geotools.resources.i18n.Errors;
029:        import org.geotools.resources.i18n.ErrorKeys;
030:
031:        /**
032:         * Acts as a typed {@link java.util.List} while we wait for Java 5.0.
033:         *
034:         * @since 2.1
035:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/util/CheckedArrayList.java $
036:         * @version $Id: CheckedArrayList.java 25193 2007-04-18 13:37:38Z desruisseaux $
037:         * @author Jody Garnett (Refractions Research)
038:         * @author Martin Desruisseaux
039:         *
040:         * @todo Provides synchronization facility on arbitrary lock, for use with the metadata package.
041:         *       The lock would be the metadata that owns this collection. Be carefull to update the lock
042:         *       after a clone (this work may be done in {@code MetadataEntity.unmodifiable(Object)}).
043:         */
044:        public class CheckedArrayList extends ArrayList implements 
045:                CheckedCollection, Cloneable {
046:            /**
047:             * Serial version UID for compatibility with different versions.
048:             */
049:            private static final long serialVersionUID = -587331971085094268L;
050:
051:            /**
052:             * The element type.
053:             */
054:            private final Class type;
055:
056:            /**
057:             * Constructs a list of the specified type.
058:             *
059:             * @param type The element type (should not be null).
060:             */
061:            public CheckedArrayList(final Class type) {
062:                super ();
063:                this .type = type;
064:                ensureNonNull();
065:            }
066:
067:            /**
068:             * Constructs a list of the specified type and initial capacity.
069:             *
070:             * @param type The element type (should not be null).
071:             * @param capacity The initial capacity.
072:             *
073:             * @since 2.4
074:             */
075:            public CheckedArrayList(final Class type, final int capacity) {
076:                super (capacity);
077:                this .type = type;
078:                ensureNonNull();
079:            }
080:
081:            /**
082:             * Returns the element type given at construction time.
083:             *
084:             * @since 2.4
085:             */
086:            public Class getElementType() {
087:                return type;
088:            }
089:
090:            /**
091:             * Make sure that {@link #type} is non-null.
092:             */
093:            private void ensureNonNull() {
094:                if (type == null) {
095:                    throw new IllegalArgumentException(Errors.format(
096:                            ErrorKeys.NULL_ARGUMENT_$1, "type"));
097:                }
098:            }
099:
100:            /**
101:             * Checks the type of the specified object. The default implementation ensure
102:             * that the object is assignable to the type specified at construction time.
103:             *
104:             * @param  element the object to check, or {@code null}.
105:             * @throws IllegalArgumentException if the specified element is not of the expected type.
106:             */
107:            protected void ensureValidType(final Object element)
108:                    throws IllegalArgumentException {
109:                if (element != null && !type.isInstance(element)) {
110:                    throw new IllegalArgumentException(Errors.format(
111:                            ErrorKeys.ILLEGAL_CLASS_$2, Utilities
112:                                    .getShortClassName(element), Utilities
113:                                    .getShortName(type)));
114:                }
115:            }
116:
117:            /**
118:             * Checks the type of all elements in the specified collection.
119:             *
120:             * @param  collection the collection to check, or {@code null}.
121:             * @throws IllegalArgumentException if at least one element is not of the expected type.
122:             */
123:            private void ensureValid(final Collection collection)
124:                    throws IllegalArgumentException {
125:                if (collection != null) {
126:                    for (final Iterator it = collection.iterator(); it
127:                            .hasNext();) {
128:                        ensureValidType(it.next());
129:                    }
130:                }
131:            }
132:
133:            /**
134:             * Replaces the element at the specified position in this list with the specified element.
135:             *
136:             * @param  index   index of element to replace.
137:             * @param  element element to be stored at the specified position.
138:             * @return the element previously at the specified position.
139:             * @throws IndexOutOfBoundsException if index out of range.
140:             * @throws IllegalArgumentException if the specified element is not of the expected type.
141:             */
142:            public Object set(final int index, final Object element) {
143:                ensureValidType(element);
144:                return super .set(index, element);
145:            }
146:
147:            /**
148:             * Appends the specified element to the end of this list.
149:             *
150:             * @param  element element to be appended to this list.
151:             * @return always {@code true}.
152:             * @throws IllegalArgumentException if the specified element is not of the expected type.
153:             */
154:            public boolean add(final Object element) {
155:                ensureValidType(element);
156:                return super .add(element);
157:            }
158:
159:            /**
160:             * Inserts the specified element at the specified position in this list.
161:             *
162:             * @param  index index at which the specified element is to be inserted.
163:             * @param  element element to be inserted.
164:             * @throws IndexOutOfBoundsException if index out of range.
165:             * @throws IllegalArgumentException if the specified element is not of the expected type.
166:             */
167:            public void add(final int index, final Object element) {
168:                ensureValidType(element);
169:                super .add(index, element);
170:            }
171:
172:            /**
173:             * Appends all of the elements in the specified collection to the end of this list,
174:             * in the order that they are returned by the specified Collection's Iterator.
175:             *
176:             * @param collection the elements to be inserted into this list.
177:             * @return {@code true} if this list changed as a result of the call.
178:             * @throws IllegalArgumentException if at least one element is not of the expected type.
179:             */
180:            public boolean addAll(final Collection collection) {
181:                ensureValid(collection);
182:                return super .addAll(collection);
183:            }
184:
185:            /**
186:             * Inserts all of the elements in the specified collection into this list,
187:             * starting at the specified position.
188:             *
189:             * @param index index at which to insert first element fromm the specified collection.
190:             * @param collection elements to be inserted into this list.
191:             * @return {@code true} if this list changed as a result of the call.
192:             * @throws IllegalArgumentException if at least one element is not of the expected type.
193:             */
194:            public boolean addAll(final int index, final Collection collection) {
195:                ensureValid(collection);
196:                return super.addAll(index, collection);
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.