Source Code Cross Referenced for IntListToListAdapter.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.list.IntList;
022:        import bak.pcj.list.IntListIterator;
023:        import bak.pcj.util.Exceptions;
024:
025:        import java.util.AbstractList;
026:        import java.util.ListIterator;
027:        import java.util.Collection;
028:        import java.util.AbstractCollection;
029:
030:        /**
031:         *  This class represents adapters of int lists to Java Collection Framework lists.
032:         *  The adapter is implemented as a wrapper around a primitive list. Thus, 
033:         *  changes to the underlying list are reflected by this
034:         *  list and vice versa.
035:         *
036:         *  @see        bak.pcj.list.IntList
037:         *  @see        java.util.List
038:         *
039:         *  @author     Søren Bak
040:         *  @version    1.2     20-08-2003 22:58
041:         *  @since      1.0
042:         */
043:        public class IntListToListAdapter extends AbstractList {
044:
045:            /** The underlying primitive list. */
046:            protected IntList list;
047:
048:            /**
049:             *  Creates a new adaption of a collection of int
050:             *  values to a Java Collections Framework collection.
051:             *
052:             *  @param      list
053:             *              the underlying primitive collection.
054:             *
055:             *  @throws     NullPointerException
056:             *              if <tt>collection</tt> is <tt>null</tt>.
057:             */
058:            public IntListToListAdapter(IntList list) {
059:                if (list == null)
060:                    Exceptions.nullArgument("list");
061:                this .list = list;
062:            }
063:
064:            /**
065:             *  Adds all the elements of a specified collection to
066:             *  this list starting at a specified index. The elements are
067:             *  inserted in the specified collection's iteration order.
068:             *  All elements from the specified index and forward are pushed
069:             *  to their successors' indices (<tt>c.size()</tt> indices).
070:             *  All elements are added to the underlying list.
071:             *  <p>This method is only overridden to work
072:             *  around a bug in {@link AbstractList AbstractList},
073:             *  which does not throw a 
074:             *  {@link NullPointerException NullPointerException} when the
075:             *  argument is <tt>null</tt> and the list is empty.
076:             *
077:             *  @param      index
078:             *              the index at which to insert the elements of
079:             *              the specified collection. If
080:             *              <tt>index == size()</tt> the elements are appended
081:             *              to this list.
082:             *
083:             *  @param      c
084:             *              the collection whose elements to add to this
085:             *              list.
086:             *
087:             *  @return     <tt>true</tt> if this list was modified
088:             *              as a result of adding the elements of <tt>c</tt>;
089:             *              returns <tt>false</tt> otherwise.
090:             *
091:             *  @throws     UnsupportedOperationException
092:             *              if the operation is not supported by the
093:             *              underlying list.
094:             *
095:             *  @throws     NullPointerException
096:             *              if <tt>c</tt> is <tt>null</tt>.
097:             *
098:             *  @throws     IndexOutOfBoundsException
099:             *              if <tt>index</tt> does not denote a valid insertion
100:             *              position (valid: <tt>0 - size()</tt>).
101:             *
102:             *  @throws     IllegalArgumentException
103:             *              if an element of <tt>c</tt> is <tt>null</tt>.
104:             *
105:             *  @throws     ClassCastException
106:             *              if an element of <tt>c</tt> is not of class
107:             *              {@link Integer Integer}.
108:             */
109:            public boolean addAll(int index, Collection c) {
110:                if (index > size() || index < 0)
111:                    Exceptions.indexOutOfBounds(index, 0, size());
112:                return super .addAll(index, c);
113:            }
114:
115:            /**
116:             *  Adds an element to this list at a specified index. All
117:             *  elements from the specified index and forward are pushed
118:             *  to their successor's indices. The element is added to
119:             *  the underlying collection.
120:             *
121:             *  @param      index
122:             *              the index at which to add the element. If
123:             *              <tt>index == size()</tt> the element is appended
124:             *              to this list.
125:             *
126:             *  @param      o
127:             *              the element to add to this list.
128:             *
129:             *  @throws     UnsupportedOperationException
130:             *              if the operation is not supported by this
131:             *              list.
132:             *
133:             *  @throws     IndexOutOfBoundsException
134:             *              if <tt>index</tt> does not denote a valid insertion
135:             *              position (valid: <tt>0 - size()</tt>).
136:             *
137:             *  @throws     IllegalArgumentException
138:             *              if <tt>o</tt> is <tt>null</tt>.
139:             *
140:             *  @throws     ClassCastException
141:             *              if <tt>o</tt> is not of class {@link Integer Integer}.
142:             */
143:            public void add(int index, Object o) {
144:                if (o == null)
145:                    Exceptions.nullElementNotAllowed();
146:                list.add(index, ((Integer) o).intValue());
147:            }
148:
149:            /**
150:             *  Returns the element at a specified position in this list.
151:             *  The returned value will always be of class {@link Integer Integer}.
152:             *
153:             *  @param      index
154:             *              the position of the element to return.
155:             *
156:             *  @return     the element at the specified position.
157:             *
158:             *  @throws     IndexOutOfBoundsException
159:             *              if <tt>index</tt> does not denote a valid index
160:             *              in this list.
161:             */
162:            public Object get(int index) {
163:                return new Integer(list.get(index));
164:            }
165:
166:            /**
167:             *  Returns a list iterator over this list, starting from a
168:             *  specified index.
169:             *
170:             *  @param      index
171:             *              the index at which to begin the iteration.
172:             *
173:             *  @return     a list iterator over this list.
174:             *
175:             *  @throws     IndexOutOfBoundsException
176:             *              if <tt>index</tt> does not denote a valid
177:             *              iteration position (valid: <tt>0 - size()</tt>).
178:             */
179:            public ListIterator listIterator(int index) {
180:                return new IntListIteratorToListIteratorAdapter(list
181:                        .listIterator(index));
182:            }
183:
184:            /**
185:             *  Removes the element at a specified index in this list. All
186:             *  elements following the removed element are pushed to their
187:             *  predecessor's indices. The element is removed from the
188:             *  underlying collection.
189:             *
190:             *  @param      index
191:             *              the index of the element to remove.
192:             *
193:             *  @throws     UnsupportedOperationException
194:             *              if the operation is not supported by the underlying
195:             *              list.
196:             *
197:             *  @throws     IndexOutOfBoundsException
198:             *              if <tt>index</tt> does not denote a valid
199:             *              element position (valid: <tt>0 - size()-1</tt>).
200:             */
201:            public Object remove(int index) {
202:                return new Integer(list.removeElementAt(index));
203:            }
204:
205:            /**
206:             *  Removes all the elements of a specified collection from
207:             *  this list. The elements are removed from the
208:             *  underlying list.
209:             *  <p>This method is only overridden to work
210:             *  around a bug in {@link AbstractList AbstractList},
211:             *  which does not throw a 
212:             *  {@link NullPointerException NullPointerException} when the
213:             *  argument is <tt>null</tt> and the list is empty. The
214:             *  bug is inherited from {@link AbstractCollection AbstractCollection}.
215:             *
216:             *  @param      c
217:             *              the collection whose elements to remove from this
218:             *              collection.
219:             *
220:             *  @return     <tt>true</tt> if this list was modified
221:             *              as a result of removing the elements of <tt>c</tt>;
222:             *              returns <tt>false</tt> otherwise.
223:             *
224:             *  @throws     UnsupportedOperationException
225:             *              if the operation is not supported by the underlying
226:             *              collection.
227:             *
228:             *  @throws     NullPointerException
229:             *              if <tt>c</tt> is <tt>null</tt>.
230:             */
231:            public boolean removeAll(Collection c) {
232:                if (c == null)
233:                    Exceptions.nullArgument("collection");
234:                return super .removeAll(c);
235:            }
236:
237:            /**
238:             *  Retains only the elements of a specified collection in
239:             *  this list. The elements are removed from the
240:             *  underlying list.
241:             *  <p>This method is only overridden to work
242:             *  around a bug in {@link AbstractList AbstractList},
243:             *  which does not throw a 
244:             *  {@link NullPointerException NullPointerException} when the
245:             *  argument is <tt>null</tt> and the list is empty. The
246:             *  bug is inherited from {@link AbstractCollection AbstractCollection}.
247:             *
248:             *  @param      c
249:             *              the collection whose elements to retain in this
250:             *              collection.
251:             *
252:             *  @return     <tt>true</tt> if this list was modified
253:             *              as a result of removing the elements not contained
254:             *              in <tt>c</tt>;
255:             *              returns <tt>false</tt> otherwise.
256:             *
257:             *  @throws     UnsupportedOperationException
258:             *              if the operation is not supported by the underlying
259:             *              list.
260:             *
261:             *  @throws     NullPointerException
262:             *              if <tt>c</tt> is <tt>null</tt>.
263:             */
264:            public boolean retainAll(Collection c) {
265:                if (c == null)
266:                    Exceptions.nullArgument("collection");
267:                return super .retainAll(c);
268:            }
269:
270:            /**
271:             *  Sets a specified element to a new value. The corresponding
272:             *  element of the underlying list is set to the unwrapped value.
273:             *
274:             *  @param      index
275:             *              the index of the element whose value to set.
276:             *
277:             *  @param      o
278:             *              the new value of the specified element.
279:             *
280:             *  @return     the previous value of the element.
281:             *
282:             *  @throws     UnsupportedOperationException
283:             *              if the operation is not supported by the underlying
284:             *              list.
285:             *
286:             *  @throws     IndexOutOfBoundsException
287:             *              if <tt>index</tt> does not denote a valid
288:             *              element position (valid: <tt>0 - size()-1</tt>).
289:             *
290:             *  @throws     IllegalArgumentException
291:             *              if <tt>o</tt> is <tt>null</tt>.
292:             *
293:             *  @throws     ClassCastException
294:             *              if <tt>o</tt> is not of class {@link Integer Integer}.
295:             */
296:            public Object set(int index, Object o) {
297:                if (o == null)
298:                    Exceptions.nullElementNotAllowed();
299:                return new Integer(list.set(index, ((Integer) o).intValue()));
300:            }
301:
302:            /**
303:             *  Returns the number of elements in this list. The
304:             *  number of elements is the same as that of the underlying
305:             *  list.
306:             *
307:             *  @return     the number of elements in this list.
308:             */
309:            public int size() {
310:                return list.size();
311:            }
312:
313:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.