01: /*
02: This source file is part of Smyle, a database library.
03: For up-to-date information, see http://www.drjava.de/smyle
04: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
05:
06: This library is free software; you can redistribute it and/or
07: modify it under the terms of the GNU Lesser General Public
08: License as published by the Free Software Foundation; either
09: version 2.1 of the License, or (at your option) any later version.
10:
11: This library is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public
17: License along with this library; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19:
20: For full license text, see doc/license/lgpl.txt in this distribution
21: */
22:
23: package drjava.smyle.core;
24:
25: import java.io.*;
26: import java.util.*;
27: import java.lang.Object;
28: import org.artsProject.mcop.*;
29: import org.artsProject.mcop.core.*;
30: import org.artsProject.util.*;
31: import drjava.smyle.*;
32: import drjava.smyle.meta.*;
33:
34: final class FilteredIterator<T extends Struct<T>> implements
35: TableIterator<T> {
36: TableImpl<T> table;
37: Filter<T> filter;
38: TableIterator<T> iterator;
39: ChunkRef chunk;
40: T t;
41:
42: FilteredIterator(TableImpl<T> table, TableIterator<T> iterator,
43: Filter<T> filter) {
44: this .table = table;
45: this .iterator = iterator;
46: this .filter = filter;
47: findNext();
48: }
49:
50: public boolean hasNext() {
51: return chunk != null;
52: }
53:
54: public T next() {
55: T t = this .t;
56: findNext();
57: return t;
58: }
59:
60: public ChunkRef nextChunk() {
61: ChunkRef chunk = this .chunk;
62: findNext();
63: return chunk;
64: }
65:
66: public void remove() {
67: throw new RuntimeException("not implemented");
68: }
69:
70: void findNext() {
71: while (iterator.hasNext()) {
72: chunk = iterator.nextChunk();
73: t = table.loadElement(chunk);
74: if (filter.matches(t))
75: return;
76: }
77: chunk = null;
78: t = null;
79: }
80: }
|