001: /*
002: * $Id: ListIteratorRowIterator.java,v 1.9 2005/04/09 01:52:42 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.ListIterator;
044: import java.util.NoSuchElementException;
045:
046: import org.axiondb.AxionException;
047: import org.axiondb.Row;
048: import org.axiondb.RowIterator;
049:
050: /**
051: * A {@link RowIterator}that simply wraps a {@link ListIterator}.
052: *
053: * @version $Revision: 1.9 $ $Date: 2005/04/09 01:52:42 $
054: * @author Rodney Waldhoff
055: * @author Ahimanikya Satapathy
056: */
057: public class ListIteratorRowIterator extends BaseRowIterator {
058:
059: public ListIteratorRowIterator(ListIterator iter) {
060: _iterator = iter;
061: }
062:
063: public void add(Row row) throws AxionException {
064: _iterator.add(row);
065: }
066:
067: public Row current() {
068: if (hasCurrent()) {
069: return _currentRow;
070: }
071: throw new NoSuchElementException("No current row has been set.");
072: }
073:
074: public int currentIndex() {
075: return _currentIndex;
076: }
077:
078: public boolean hasCurrent() {
079: return _currentRowSet;
080: }
081:
082: public boolean hasNext() {
083: return _iterator.hasNext();
084: }
085:
086: public boolean hasPrevious() {
087: return _iterator.hasPrevious();
088: }
089:
090: public Row next() {
091: _currentIndex = _iterator.nextIndex();
092: _currentRow = (Row) (_iterator.next());
093: _currentRowSet = true;
094: return _currentRow;
095: }
096:
097: public int nextIndex() {
098: return _iterator.nextIndex();
099: }
100:
101: public Row previous() {
102: _currentRow = (Row) (_iterator.previous());
103: _currentRowSet = true;
104: _currentIndex = _iterator.nextIndex();
105: return _currentRow;
106: }
107:
108: public int previousIndex() {
109: return _iterator.previousIndex();
110: }
111:
112: public void remove() {
113: if (!hasCurrent()) {
114: throw new IllegalStateException("No current row.");
115: }
116: _iterator.remove();
117: _currentRow = null;
118: _currentRowSet = false;
119: _currentIndex = -1;
120: }
121:
122: public void reset() {
123: while (_iterator.hasPrevious()) {
124: _iterator.previous();
125: }
126: _currentRow = null;
127: _currentRowSet = false;
128: _currentIndex = -1;
129: }
130:
131: public void set(Row row) {
132: if (!hasCurrent()) {
133: throw new IllegalStateException("No current row.");
134: }
135: _iterator.set(row);
136: _currentRow = row;
137: }
138:
139: public String toString() {
140: return "ListIterator";
141: }
142:
143: private int _currentIndex = -1;
144: private Row _currentRow = null;
145: private boolean _currentRowSet = false;
146: private ListIterator _iterator = null;
147: }
|