001: /*
002: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
003:
004: This file is part of the JODB (Java Objects Database) open source project.
005:
006: JODB is free software; you can redistribute it and/or modify it under
007: the terms of version 2 of the GNU General Public License as published
008: by the Free Software Foundation.
009:
010: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
011: WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013: for more details.
014:
015: You should have received a copy of the GNU General Public License along
016: with this program; if not, write to the Free Software Foundation, Inc.,
017: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019: package com.mobixess.jodb.core.transaction;
020:
021: import java.io.IOException;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.ListIterator;
026:
027: import com.mobixess.jodb.soda.api.ObjectSet;
028:
029: public class JODBQueryList implements ObjectSet, Iterable {
030: private long[] _offsets;
031: private JODBSession _session;
032: private int _iteratorIndex;
033:
034: /**
035: * @param offsets
036: */
037: public JODBQueryList(long[] offsets, JODBSession session) {
038: super ();
039: _offsets = offsets;
040: _session = session;
041: }
042:
043: public boolean add(Object o) {
044: throw new UnsupportedOperationException();
045: }
046:
047: public void add(int index, Object element) {
048: throw new UnsupportedOperationException();
049: }
050:
051: public boolean addAll(Collection c) {
052:
053: throw new UnsupportedOperationException();
054: //return false;
055: }
056:
057: public boolean addAll(int index, Collection c) {
058:
059: throw new UnsupportedOperationException();
060: //return false;
061: }
062:
063: public void clear() {
064:
065: throw new UnsupportedOperationException();
066: //
067: }
068:
069: public boolean contains(Object o) {
070:
071: throw new UnsupportedOperationException();
072: //return false;
073: }
074:
075: public boolean containsAll(Collection c) {
076:
077: throw new UnsupportedOperationException();
078: //return false;
079: }
080:
081: public Object get(int index) {
082: long offset = _offsets[index];
083: try {
084: return _session.getObjectForOffset(offset);
085: } catch (IOException e) {
086: throw new RuntimeException(e);
087: }
088: }
089:
090: public int indexOf(Object o) {
091: for (int i = 0; i < _offsets.length; i++) {
092: Object next = get(i);
093: if (next == null && o != null) {
094: continue;
095: }
096: if (o == next || o.equals(next)) {
097: return i;
098: }
099: }
100: return -1;
101: }
102:
103: public boolean isEmpty() {
104: return _offsets == null || _offsets.length == 0;
105: }
106:
107: public Iterator iterator() {
108: return new JODBQueryList(_offsets, _session);
109: }
110:
111: public int lastIndexOf(Object o) {
112: for (int i = _offsets.length - 1; i >= 0; i--) {
113: Object next = get(i);
114: if (o == next || o.equals(next)) {
115: return i;
116: }
117: }
118: return -1;
119: }
120:
121: public ListIterator listIterator() {
122:
123: throw new UnsupportedOperationException();
124: //return null;
125: }
126:
127: public ListIterator listIterator(int index) {
128:
129: throw new UnsupportedOperationException();
130: //return null;
131: }
132:
133: public boolean remove(Object o) {
134:
135: throw new UnsupportedOperationException();
136: //return false;
137: }
138:
139: public Object remove(int index) {
140:
141: throw new UnsupportedOperationException();
142: //return null;
143: }
144:
145: public boolean removeAll(Collection c) {
146:
147: throw new UnsupportedOperationException();
148: //return false;
149: }
150:
151: public boolean retainAll(Collection c) {
152:
153: throw new UnsupportedOperationException();
154: //return false;
155: }
156:
157: public Object set(int index, Object element) {
158:
159: throw new UnsupportedOperationException();
160: //return null;
161: }
162:
163: public int size() {
164: return _offsets.length;
165: }
166:
167: public List subList(int fromIndex, int toIndex) {
168:
169: throw new UnsupportedOperationException();
170: //return null;
171: }
172:
173: public Object[] toArray() {
174:
175: throw new UnsupportedOperationException();
176: //return null;
177: }
178:
179: @SuppressWarnings("unchecked")
180: public Object[] toArray(Object[] a) {
181:
182: throw new UnsupportedOperationException();
183: //return null;
184: }
185:
186: public boolean hasNext() {
187: return _iteratorIndex < _offsets.length;
188: }
189:
190: public Object next() {
191: return get(_iteratorIndex++);
192: }
193:
194: public void reset() {
195: _iteratorIndex = 0;
196: }
197:
198: public void remove() {
199: throw new UnsupportedOperationException();
200: }
201:
202: public long[] getAllObjectIds() {
203: long[] result = new long[_offsets.length];
204: System.arraycopy(_offsets, 0, result, 0, _offsets.length);
205: return result;
206: }
207:
208: }
|