001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb;
032:
033: /*
034: * This class introduces iterator functionality to Result.
035: *
036: * @author fredt@users
037: * @version 1.7.2
038: * @since 1.7.2
039: */
040: public class ResultBase {
041:
042: public Record rRoot;
043: protected Record rTail;
044: protected int iSize;
045:
046: public ResultBase() {
047: }
048:
049: public ResultIterator iterator() {
050: return new ResultIterator();
051: }
052:
053: public class ResultIterator {
054:
055: boolean removed;
056: int counter;
057: Record current = rRoot;
058: Record last;
059:
060: public boolean hasNext() {
061: return counter < iSize;
062: }
063:
064: public boolean next() {
065:
066: if (hasNext()) {
067: removed = false;
068:
069: if (counter != 0) {
070: last = current;
071: current = current.next;
072: }
073:
074: counter++;
075:
076: return true;
077: } else {
078: return false;
079: }
080: }
081:
082: public boolean previous() {
083: return false;
084: }
085:
086: public boolean absolute(int rows) {
087: return false;
088: }
089:
090: public boolean relative(int rows) {
091: return false;
092: }
093:
094: public boolean beforeFirst() {
095: return false;
096: }
097:
098: public boolean afterLast() {
099: return false;
100: }
101:
102: public boolean isBeforeFirst() {
103: return false;
104: }
105:
106: public boolean isAfterLast() {
107: return false;
108: }
109:
110: public void remove() {
111:
112: if (counter <= iSize && counter != 0 && !removed) {
113: removed = true;
114:
115: if (current == rTail) {
116: rTail = last;
117: }
118:
119: if (current == rRoot) {
120: current = rRoot = rRoot.next;
121: } else {
122: current = last;
123: last = null;
124: current.next = current.next.next;
125: }
126:
127: iSize--;
128: counter--;
129:
130: return;
131: }
132: }
133: }
134: }
|