001: /*
002: * $Id: RowIterator.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;
042:
043: import java.util.NoSuchElementException;
044:
045: /**
046: * A bidirectional iterator over a collection of {@link Row}s.
047: *
048: * @version $Revision: 1.12 $ $Date: 2005/04/22 02:28:53 $
049: * @author Rodney Waldhoff
050: * @author Ahimanikya Satapathy
051: */
052: public interface RowIterator {
053:
054: /**
055: * Add a {@link Row}at the current position in my underlying collection, or throw
056: * {@link UnsupportedOperationException}. (Optional operation.)
057: */
058: void add(Row row) throws UnsupportedOperationException,
059: AxionException;
060:
061: /**
062: * Returns the last {@link Row}returned by me (by {@link #next},{@link #previous},
063: * {@link #first},{@link #last}, etc.).
064: *
065: * @throws NoSuchElementException when no {@link Row}has yet been returned
066: */
067: Row current() throws NoSuchElementException;
068:
069: /**
070: * Returns the index of the {@link #current}row, if any.
071: *
072: * @throws NoSuchElementException when no {@link Row}has yet been returned
073: */
074: int currentIndex() throws NoSuchElementException;
075:
076: /**
077: * Returns the first {@link Row}in the list, positioning the cursor to just before
078: * the first {@link Row}in the list. (In other words, after <code>first</code> is
079: * called both {@link #next}and {@link #current}will return the first row in the
080: * list.)
081: *
082: * @throws NoSuchElementException when there is no first {@link Row}
083: * @throws AxionException when a problem occurs accessing the {@link Row}
084: */
085: Row first() throws NoSuchElementException, AxionException;
086:
087: /**
088: * Returns <code>true</code> if I have a current {@link Row}. (In other words,
089: * returns <code>true</code> iff {@link #current}would return a {@link Row}rather
090: * than throwing an exception.)
091: */
092: boolean hasCurrent();
093:
094: /**
095: * Returns <code>true</code> if I have more {@link Row}s when traversing the list
096: * in the forward direction. (In other words, returns <code>true</code> iff
097: * {@link #next}would return a {@link Row}rather than throwing an exception.)
098: */
099: boolean hasNext();
100:
101: /**
102: * Returns <code>true</code> if I have more {@link Row}s when traversing the list
103: * in the reverse direction. (In other words, returns <code>true</code> iff
104: * {@link #previous}would return a {@link Row}rather than throwing an exception.)
105: */
106: boolean hasPrevious();
107:
108: /**
109: * Returns <code>true</code> if there are no rows to report with this iterator.
110: */
111: boolean isEmpty();
112:
113: /**
114: * Returns the last {@link Row}in the list, positioning the cursor to just after the
115: * last {@link Row}in the list. (In other words, after <code>last</code> is called
116: * both {@link #previous}and {@link #current}will return the last row in the list.)
117: *
118: * @throws NoSuchElementException when there is no last {@link Row}
119: * @throws AxionException when a problem occurs accessing the {@link Row}
120: */
121: Row last() throws NoSuchElementException, AxionException;
122:
123: /**
124: * Returns the next {@link Row}in the list, or throws
125: * {@link java.util.NoSuchElementException}if no next <code>Row</code> exists.
126: *
127: * @throws NoSuchElementException when there is no next {@link Row}
128: * @throws AxionException when a problem occurs accessing the {@link Row}
129: */
130: Row next() throws NoSuchElementException, AxionException;
131:
132: /**
133: * Sets the current iterator position to currentIndex() + count; this will not set the
134: * current row, peekPrevious() may be used to return the current row. This will
135: * provide random access e.g one can postion the cursor before the desired row and
136: * then call next().
137: */
138: int next(int count) throws AxionException;
139:
140: /**
141: * Returns the index of the {@link #next}row, if any, or the number of elements is
142: * the iterator if we've reached the end.
143: */
144: int nextIndex();
145:
146: /**
147: * Return the value that would be returned by a call to {@link #next}, if any, but
148: * don't update my position.
149: *
150: * @throws NoSuchElementException when there is no next {@link Row}
151: * @throws AxionException when a problem occurs accessing the {@link Row}
152: */
153: Row peekNext() throws NoSuchElementException, AxionException;
154:
155: /**
156: * Return the value that would be returned by a call to {@link #previous}, if any,
157: * but don't update my position.
158: *
159: * @throws NoSuchElementException when there is no previous {@link Row}
160: * @throws AxionException when a problem occurs accessing the {@link Row}
161: */
162: Row peekPrevious() throws NoSuchElementException, AxionException;
163:
164: /**
165: * Returns the previous {@link Row}in the list, or throws
166: * {@link java.util.NoSuchElementException}if no next <code>Row</code> exists.
167: *
168: * @throws NoSuchElementException when there is no next {@link Row}
169: * @throws AxionException when a problem occurs accessing the {@link Row}
170: */
171: Row previous() throws NoSuchElementException, AxionException;
172:
173: /**
174: * Sets the current iterator position to currentIndex() - count; this will not set the
175: * current row, peekNext() may be used to return the current row. This will provide
176: * random access e.g one can postion the cursor after the desired row and then call
177: * previous().
178: */
179: int previous(int count) throws AxionException;
180:
181: /**
182: * Returns the index of the {@link #previous}row, if any, or -1 if we're add the
183: * beginning of the list.
184: */
185: int previousIndex();
186:
187: /**
188: * Set the {@link Row}at the current position in my underlying collection, or throw
189: * {@link UnsupportedOperationException}. (Optional operation.)
190: */
191: void remove() throws UnsupportedOperationException, AxionException;
192:
193: /**
194: * Re-initialize this <code>RowIterator</code> to its initial state (positioned just
195: * before the first {@link Row}in the list).
196: */
197: void reset() throws AxionException;
198:
199: /**
200: * Set the {@link Row}at the current position in my underlying collection, or throw
201: * {@link UnsupportedOperationException}. (Optional operation.)
202: */
203: void set(Row row) throws UnsupportedOperationException,
204: AxionException;
205:
206: /**
207: * Retunrs the current size of the underlaying row collection
208: */
209: int size() throws AxionException;
210:
211: }
|