Source Code Cross Referenced for ArrayIterator.java in  » Portal » stringbeans-3.5 » com » nabhinc » 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 » Portal » stringbeans 3.5 » com.nabhinc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * (C) Copyright 2002 Nabh Information Systems, Inc. 
003:         * 
004:         * All copyright notices regarding Nabh's products MUST remain
005:         * intact in the scripts and in the outputted HTML.
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1 
009:         * of the License, or (at your option) any later version.
010:         * 
011:         * This program 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 
014:         * GNU Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public License
017:         * along with this program; if not, write to the Free Software 
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         * 
020:         */
021:        package com.nabhinc.util;
022:
023:        import java.lang.reflect.Array;
024:        import java.util.Iterator;
025:        import java.util.NoSuchElementException;
026:
027:        /**
028:         *
029:         *
030:         * @author Padmanabh Dabke
031:         * (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
032:         */
033:        public class ArrayIterator implements  Iterator {
034:
035:            private Object array;
036:            private int length = 0;
037:            private int index = 0;
038:
039:            /**
040:             *  Construct an ArrayIterator.  Using this constructor, the iterator is
041:             *  equivalent to an empty iterator until {@link #setArray(Object)} is
042:             *  called to establish the array to iterate over.
043:             **/
044:            public ArrayIterator() {
045:            }
046:
047:            /**
048:             *  Construct an ArrayIterator that will iterate over the values in the
049:             *  specified array.
050:             *
051:             *  @param array the array to iterate over.
052:             *
053:             *  @exception IllegalArgumentException if <code>array</code> is not an
054:             *  array.
055:             *
056:             *  @exception NullPointerException 
057:             *  if <code>array</code> is <code>null</code>
058:             **/
059:            public ArrayIterator(Object array) {
060:                setArray(array);
061:            }
062:
063:            /**
064:             *  Construct an ArrayIterator that will iterate over the values in the
065:             *  specified array.
066:             *
067:             *  @param array the array to iterate over.
068:             *  @param start the index to start iterating at.
069:             *
070:             *  @exception IllegalArgumentException if <code>array</code> is not an
071:             *  array.
072:             *
073:             *  @exception NullPointerException 
074:             *  if <code>array</code> is <code>null</code>
075:             **/
076:            public ArrayIterator(Object array, int start) {
077:                setArray(array);
078:                checkBound(start, "start");
079:                this .index = start;
080:            }
081:
082:            /**
083:             *  Construct an ArrayIterator that will iterate over the values in the
084:             *  specified array.
085:             *
086:             *  @param array the array to iterate over.
087:             *  @param start the index to start iterating at.
088:             *  @param end the index to finish iterating at.
089:             *
090:             *  @exception IllegalArgumentException if <code>array</code> is not an
091:             *  array.
092:             *
093:             *  @exception NullPointerException 
094:             *  if <code>array</code> is <code>null</code>
095:             **/
096:            public ArrayIterator(Object array, int start, int end) {
097:                setArray(array);
098:                checkBound(start, "start");
099:                checkBound(end, "end");
100:                if (end <= start) {
101:                    throw new IllegalArgumentException(
102:                            "End index must be greater than start index. ");
103:                }
104:                this .index = start;
105:                this .length = end;
106:            }
107:
108:            private void checkBound(int bound, String type) {
109:                if (bound > this .length) {
110:                    throw new ArrayIndexOutOfBoundsException(
111:                            "Attempt to make an ArrayIterator that " + type
112:                                    + "s beyond the end of the array. ");
113:                }
114:                if (bound < 0) {
115:                    throw new ArrayIndexOutOfBoundsException(
116:                            "Attempt to make an ArrayIterator that " + type
117:                                    + "s before the start of the array. ");
118:                }
119:            }
120:
121:            // Iterator interface
122:            //-------------------------------------------------------------------------
123:
124:            /**
125:             *  Returns true if there are more elements to return from the array.
126:             *
127:             *  @return true if there is a next element to return
128:             */
129:            public boolean hasNext() {
130:                return index < length;
131:            }
132:
133:            /**
134:             *  Returns the next element in the array.
135:             *
136:             *  @return the next element in the array
137:             *  @throws NoSuchElementException if all the elements in the array
138:             *    have already been returned
139:             */
140:            public Object next() {
141:                if (!hasNext()) {
142:                    throw new NoSuchElementException();
143:                }
144:                return Array.get(array, index++);
145:            }
146:
147:            /**
148:             *  Throws {@link UnsupportedOperationException}.
149:             *
150:             *  @throws UnsupportedOperationException always
151:             */
152:            public void remove() {
153:                throw new UnsupportedOperationException(
154:                        "remove() method is not supported");
155:            }
156:
157:            // Properties
158:            //-------------------------------------------------------------------------
159:
160:            /**
161:             *  Retrieves the array that this iterator is iterating over. 
162:             *
163:             *  @return the array this iterator iterates over, or <code>null</code> if
164:             *  the no-arg constructor was used and {@link #setArray(Object)} has never
165:             *  been called with a valid array.
166:             **/
167:            public Object getArray() {
168:                return array;
169:            }
170:
171:            /**
172:             *  Changes the array that the ArrayIterator should iterate over.  If an
173:             *  array has previously been set (using the single-arg constructor or this
174:             *  method), that array along with the current iterator position within
175:             *  that array is discarded in favor of the argument to this method.  This
176:             *  method can be used in combination with {@link #getArray()} to "reset"
177:             *  the iterator to the beginning of the array:
178:             *
179:             *  <pre>
180:             *    ArrayIterator iterator = ...
181:             *    ...
182:             *    iterator.setArray(iterator.getArray());
183:             *  </pre>
184:             *
185:             *  Note: Using i.setArray(i.getArray()) may throw a NullPointerException
186:             *  if no array has ever been set for the iterator (see {@link
187:             *  #getArray()})
188:             *
189:             *  @param array the array that the iterator should iterate over.
190:             *
191:             *  @exception IllegalArgumentException if <code>array</code> is not an
192:             *  array.
193:             *
194:             *  @exception NullPointerException 
195:             *  if <code>array</code> is <code>null</code>
196:             **/
197:            public void setArray(Object array) {
198:                // Array.getLength throws IllegalArgumentException if the object is not
199:                // an array or NullPointerException if the object is null.  This call
200:                // is made before saving the array and resetting the index so that the
201:                // array iterator remains in a consistent state if the argument is not
202:                // an array or is null.
203:                this .length = Array.getLength(array);
204:                this .array = array;
205:                this .index = 0;
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.