Source Code Cross Referenced for IntListIteratorChain.java in  » Database-DBMS » axion » org » axiondb » 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 » Database DBMS » axion » org.axiondb.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: IntListIteratorChain.java,v 1.6 2004/09/09 23:47:45 ahimanikya Exp $
003:         * =======================================================================
004:         * Copyright (c) 2002-2003 Axion Development Team.  All rights reserved.
005:         *  
006:         * Redistribution and use in source and binary forms, with or without 
007:         * modification, are permitted provided that the following conditions 
008:         * are met:
009:         * 
010:         * 1. Redistributions of source code must retain the above 
011:         *    copyright notice, this list of conditions and the following 
012:         *    disclaimer. 
013:         *   
014:         * 2. Redistributions in binary form must reproduce the above copyright 
015:         *    notice, this list of conditions and the following disclaimer in 
016:         *    the documentation and/or other materials provided with the 
017:         *    distribution. 
018:         *   
019:         * 3. The names "Tigris", "Axion", nor the names of its contributors may 
020:         *    not be used to endorse or promote products derived from this 
021:         *    software without specific prior written permission. 
022:         *  
023:         * 4. Products derived from this software may not be called "Axion", nor 
024:         *    may "Tigris" or "Axion" appear in their names without specific prior
025:         *    written permission.
026:         *   
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
028:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030:         * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
031:         * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
032:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
033:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
034:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
035:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
036:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
037:         * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038:         * =======================================================================
039:         */
040:
041:        package org.axiondb.util;
042:
043:        import java.util.ArrayList;
044:        import java.util.List;
045:        import java.util.ListIterator;
046:        import java.util.NoSuchElementException;
047:
048:        import org.apache.commons.collections.primitives.ArrayIntList;
049:        import org.apache.commons.collections.primitives.IntList;
050:        import org.apache.commons.collections.primitives.IntListIterator;
051:
052:        /**
053:         * Concatenates multiple {@link IntListIterator}s into
054:         * a single {@link IntListIterator}.
055:         * <p/>
056:         * @version $Revision: 1.6 $ $Date: 2004/09/09 23:47:45 $
057:         * @author Chuck Burdick
058:         * @author Rodney Waldhoff
059:         */
060:        public class IntListIteratorChain implements  IntListIterator {
061:            public IntListIteratorChain() {
062:                _listOfIterators = new ArrayList();
063:            }
064:
065:            public void addIterator(IntListIterator iter) {
066:                assertNotStarted();
067:                addTempListIfNeeded();
068:                _listOfIterators.add(iter);
069:            }
070:
071:            public void addIterator(int value) {
072:                assertNotStarted();
073:                addToTempList(value);
074:            }
075:
076:            public boolean hasNext() {
077:                ensureStarted();
078:                if (_currentIterator != null && _currentIterator.hasNext()) {
079:                    return true;
080:                } else if (_iteratorOverIterators.hasNext()) {
081:                    _currentIterator = (IntListIterator) _iteratorOverIterators
082:                            .next();
083:                    return hasNext();
084:                } else {
085:                    return false;
086:                }
087:            }
088:
089:            public boolean hasPrevious() {
090:                ensureStarted();
091:                if (_currentIterator != null && _currentIterator.hasPrevious()) {
092:                    return true;
093:                } else if (_iteratorOverIterators.hasPrevious()) {
094:                    _currentIterator = (IntListIterator) _iteratorOverIterators
095:                            .previous();
096:                    return hasPrevious();
097:                } else {
098:                    return false;
099:                }
100:            }
101:
102:            public int next() {
103:                if (hasNext()) {
104:                    _nextIndex++;
105:                    return _currentIterator.next();
106:                }
107:                throw new NoSuchElementException();
108:            }
109:
110:            public int previous() {
111:                if (hasPrevious()) {
112:                    _nextIndex--;
113:                    return _currentIterator.previous();
114:                }
115:                throw new NoSuchElementException();
116:            }
117:
118:            public void add(int elt) {
119:                throw new UnsupportedOperationException();
120:            }
121:
122:            public int nextIndex() {
123:                return _nextIndex;
124:            }
125:
126:            public int previousIndex() {
127:                return _nextIndex - 1;
128:            }
129:
130:            public void remove() {
131:                throw new UnsupportedOperationException();
132:            }
133:
134:            public void set(int elt) {
135:                throw new UnsupportedOperationException();
136:            }
137:
138:            private void assertNotStarted() throws IllegalStateException {
139:                if (null != _iteratorOverIterators) {
140:                    throw new IllegalStateException("Already started iterating");
141:                }
142:            }
143:
144:            private void ensureStarted() {
145:                if (null == _iteratorOverIterators) {
146:                    addTempListIfNeeded();
147:                    _iteratorOverIterators = _listOfIterators.listIterator();
148:                }
149:            }
150:
151:            private final void addTempListIfNeeded() {
152:                if (null != _tempList) {
153:                    _listOfIterators.add(_tempList.listIterator());
154:                    _tempList = null;
155:                } else if (_tempValueSet) {
156:                    _listOfIterators.add(new SingleElementIntListIterator(
157:                            _tempValue));
158:                    _tempValueSet = false;
159:                }
160:            }
161:
162:            private final void addToTempList(int value) {
163:                if (null == _tempList) {
164:                    if (!_tempValueSet) {
165:                        _tempValue = value;
166:                        _tempValueSet = true;
167:                    } else {
168:                        _tempList = new ArrayIntList(2);
169:                        _tempList.add(_tempValue);
170:                        _tempList.add(value);
171:                        _tempValueSet = false;
172:                    }
173:                } else {
174:                    _tempList.add(value);
175:                }
176:            }
177:
178:            private List _listOfIterators = null;
179:            private IntList _tempList = null;
180:            private boolean _tempValueSet = false;
181:            private int _tempValue;
182:            private IntListIterator _currentIterator = null;
183:            private ListIterator _iteratorOverIterators = null;
184:            private int _nextIndex = 0;
185:
186:            private final class SingleElementIntListIterator implements 
187:                    IntListIterator {
188:
189:                public SingleElementIntListIterator(int value) {
190:                    _value = value;
191:                }
192:
193:                public boolean hasNext() {
194:                    return _before;
195:                }
196:
197:                public boolean hasPrevious() {
198:                    return !_before;
199:                }
200:
201:                public int next() {
202:                    if (_before) {
203:                        _before = false;
204:                        return _value;
205:                    }
206:                    throw new NoSuchElementException();
207:                }
208:
209:                public int nextIndex() {
210:                    return _before ? 0 : 1;
211:                }
212:
213:                public int previous() {
214:                    if (!_before) {
215:                        _before = true;
216:                        return _value;
217:                    }
218:                    throw new NoSuchElementException();
219:                }
220:
221:                public int previousIndex() {
222:                    return _before ? -1 : 0;
223:                }
224:
225:                public void remove() {
226:                    throw new UnsupportedOperationException();
227:                }
228:
229:                public void set(int arg0) {
230:                    throw new UnsupportedOperationException();
231:                }
232:
233:                public void add(int arg0) {
234:                    throw new UnsupportedOperationException();
235:                }
236:
237:                private boolean _before = true;
238:                private int _value = 0;
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.