Source Code Cross Referenced for CollectionIterator.java in  » Portal » Open-Portal » com » sun » portal » wireless » taglibs » base » 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 » Portal » Open Portal » com.sun.portal.wireless.taglibs.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: CollectionIterator.java,v 1.2 2002/06/01 22:16:15 sorensen Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.wireless.taglibs.base;
014:
015:        import java.util.*;
016:
017:        /**
018:         * CollectionIterator - collection iteration bean
019:         * 
020:         * The state of an iteration over a collection.
021:         * It is used by CollectionTag to  make the
022:         * iteration state available as bean properties.
023:         * 
024:         * @author Robert O'Brien
025:         * @version 1.0
026:         * @see com.sun.portal.wireless.taglibs.base.CollectionTag
027:         */
028:        public class CollectionIterator implements  Iterator {
029:
030:            /**
031:             * The collection to iterate
032:             */
033:            protected Collection collection;
034:
035:            /**
036:             * Object array from the collection
037:             */
038:            protected Object[] objects;
039:
040:            /**
041:             * The current index into the iteration
042:             */
043:            protected int index;
044:
045:            /**
046:             * The current index into the iteration
047:             */
048:            protected int start;
049:
050:            /**
051:             * The number of iterations
052:             */
053:            protected int count;
054:
055:            /**
056:             * Iteration related properties...
057:             */
058:            private int end;
059:            private int startOne, endOne;
060:            private int nextStart, prevStart;
061:            private int size;
062:            private boolean nextPage, prevPage;
063:
064:            /**
065:             * Recompute the various iteration limits...
066:             */
067:            private void computeLimits() {
068:
069:                if ((prevStart = start - count) < 0) {
070:                    prevStart = 0;
071:                }
072:
073:                if (start == 0) {
074:                    prevPage = false;
075:                } else {
076:                    prevPage = true;
077:                }
078:
079:                if ((nextStart = start + count) >= size) {
080:                    count = size - start;
081:                    nextPage = false;
082:                } else {
083:                    nextPage = true;
084:                }
085:
086:                end = start + count;
087:                startOne = start + 1;
088:                endOne = end + 1;
089:                index = start;
090:
091:            }
092:
093:            /**
094:             * Construct an iteration for a collection
095:             * 
096:             * @param collection the collection to iterate over
097:             */
098:            public CollectionIterator(Collection collection) {
099:                this (collection, 0, collection.size());
100:            }
101:
102:            /**
103:             * Construct an iteration for a collection
104:             * 
105:             * @param collection the collection to iterate over
106:             * @param start      the starting index of the iteration
107:             * @param count      the number of iterations
108:             */
109:            public CollectionIterator(Collection collection, int start,
110:                    int count) {
111:                this .collection = collection;
112:                this .start = start;
113:                this .count = count;
114:                this .objects = collection.toArray();
115:                this .size = objects.length;
116:
117:                computeLimits();
118:
119:            }
120:
121:            /**
122:             * Return the collection being iterated
123:             */
124:            public Collection getCollection() {
125:                return collection;
126:            }
127:
128:            /**
129:             * Returns true if the iteration has more elements
130:             * 
131:             * @return true if the iteration has more items
132:             *         false if the iteration is complete
133:             */
134:            public boolean hasNext() {
135:                return (index < end);
136:            }
137:
138:            /**
139:             * Returns the next element in the iteration
140:             * 
141:             * @return the next object
142:             */
143:            public Object next() {
144:                if (index < end) {
145:                    return objects[index++];
146:                }
147:                return null;
148:            }
149:
150:            /**
151:             * Removes from the underlying collection the last element
152:             * returned by the iterator; not supported
153:             *
154:             * @throws UnsupportedOperationException
155:             */
156:            public void remove() throws UnsupportedOperationException {
157:                throw new UnsupportedOperationException();
158:            }
159:
160:            /**
161:             * Get the index of the current item
162:             * 
163:             * @return index of the current item
164:             */
165:            public int getIndex() {
166:                return index - 1;
167:            }
168:
169:            /**
170:             * Get the one-based index of the current item
171:             * 
172:             * @return index of the current item
173:             */
174:            public int getIndexOne() {
175:                return index;
176:            }
177:
178:            /***********************
179:             * Process properties...
180:             **********************/
181:
182:            /**
183:             * Process "start" property...
184:             */
185:
186:            public String getStart() {
187:                return Integer.toString(start);
188:            }
189:
190:            public int getStartInt() {
191:                return start;
192:            }
193:
194:            public void setStart(String s) {
195:                if (s == null || s.length() == 0) {
196:                    start = 0;
197:                } else
198:                    try {
199:                        start = Integer.parseInt(s);
200:                    } catch (Exception e) {
201:                        start = 0;
202:                    }
203:
204:                computeLimits();
205:            }
206:
207:            /**
208:             * Process "count" property...
209:             */
210:
211:            public String getCount() {
212:                return Integer.toString(count);
213:            }
214:
215:            public int getCountInt() {
216:                return count;
217:            }
218:
219:            public void setCount(String s) {
220:                if (s == null || s.length() == 0) {
221:                    count = size;
222:                } else
223:                    try {
224:                        count = Integer.parseInt(s);
225:                    } catch (Exception e) {
226:                        count = 0;
227:                    }
228:
229:                computeLimits();
230:            }
231:
232:            /**
233:             * Process "end" property...
234:             */
235:
236:            public int getEnd() {
237:                return end - 1;
238:            }
239:
240:            /**
241:             * Process "startOne" property...
242:             */
243:
244:            public int getStartOne() {
245:                return startOne;
246:            }
247:
248:            /**
249:             * Process "endOne" property...
250:             */
251:
252:            public int getEndOne() {
253:                return endOne - 1;
254:            }
255:
256:            /**
257:             * Process "size" property...
258:             */
259:
260:            public int getSize() {
261:                return size;
262:            }
263:
264:            /**
265:             * Process "nextPage" property...
266:             */
267:
268:            public boolean isNextPage() {
269:                return nextPage;
270:            }
271:
272:            /**
273:             * Process "prevPage" property...
274:             */
275:
276:            public boolean isPrevPage() {
277:                return prevPage;
278:            }
279:
280:            /**
281:             * Process "nextStart" property...
282:             */
283:
284:            public int getNextStart() {
285:                return nextStart;
286:            }
287:
288:            /**
289:             * Process "prevStart" property...
290:             */
291:
292:            public int getPrevStart() {
293:                return prevStart;
294:            }
295:
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.