001: /*
002: * $Id: SingleRowIterator.java,v 1.12 2005/04/22 02:28:53 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2005 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.engine.rowiterators;
042:
043: import java.util.NoSuchElementException;
044:
045: import org.axiondb.AxionException;
046: import org.axiondb.Row;
047: import org.axiondb.RowIterator;
048:
049: /**
050: * A {@link RowIterator}over a single {@link Row}.
051: *
052: * @version $Revision: 1.12 $ $Date: 2005/04/22 02:28:53 $
053: * @author Rodney Waldhoff
054: * @author Ahimanikya Satapathy
055: */
056: public class SingleRowIterator implements RowIterator {
057:
058: public SingleRowIterator(Row row) {
059: _row = row;
060: }
061:
062: public void add(Row row) {
063: throw new UnsupportedOperationException();
064: }
065:
066: public Row current() {
067: if (_currentSet) {
068: return _row;
069: }
070: throw new NoSuchElementException();
071: }
072:
073: public int currentIndex() {
074: if (_currentSet) {
075: return 0;
076: }
077: return -1;
078: }
079:
080: public Row first() {
081: _currentSet = true;
082: _before = true;
083: return _row;
084: }
085:
086: public boolean hasCurrent() {
087: return _currentSet;
088: }
089:
090: public boolean hasNext() {
091: return _before;
092: }
093:
094: public boolean hasPrevious() {
095: return !_before;
096: }
097:
098: public boolean isEmpty() {
099: return false;
100: }
101:
102: public Row last() {
103: _currentSet = true;
104: _before = false;
105: return _row;
106: }
107:
108: public Row next() {
109: if (_before) {
110: return last();
111: }
112: throw new NoSuchElementException();
113: }
114:
115: public int next(int count) throws AxionException {
116: throw new UnsupportedOperationException();
117: }
118:
119: public int nextIndex() {
120: if (_before) {
121: return 0;
122: }
123: return 1;
124: }
125:
126: public Row peekNext() {
127: if (_before) {
128: return _row;
129: }
130: throw new NoSuchElementException();
131: }
132:
133: public Row peekPrevious() {
134: if (!_before) {
135: return _row;
136: }
137: throw new NoSuchElementException();
138: }
139:
140: public Row previous() {
141: if (!_before) {
142: return first();
143: }
144: throw new NoSuchElementException();
145: }
146:
147: public int previous(int count) throws AxionException {
148: throw new UnsupportedOperationException();
149: }
150:
151: public int previousIndex() {
152: if (_before) {
153: return -1;
154: }
155: return 0;
156: }
157:
158: public void remove() {
159: throw new UnsupportedOperationException();
160: }
161:
162: public void reset() {
163: _currentSet = false;
164: _before = true;
165: }
166:
167: public void set(Row row) {
168: throw new UnsupportedOperationException();
169: }
170:
171: public int size() throws AxionException {
172: return 1;
173: }
174:
175: public String toString() {
176: return "SingleRowIterator(" + _row + ")";
177: }
178:
179: private boolean _before = true;
180: private boolean _currentSet = false;
181: private Row _row = null;
182: }
|