01: package it.unimi.dsi.mg4j.index;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2006-2007 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import java.io.IOException;
25:
26: import it.unimi.dsi.fastutil.ints.AbstractIntIterator;
27: import it.unimi.dsi.mg4j.search.IntervalIterator;
28: import it.unimi.dsi.mg4j.search.visitor.DocumentIteratorVisitor;
29:
30: /** A very basic abstract implementation of an index interator,
31: * providing an obvious implementation of {@link #term()}, {@link #id()},
32: * and of the {@linkplain #accept(DocumentIteratorVisitor) visiting methods}.
33: *
34: */
35:
36: public abstract class AbstractIndexIterator extends AbstractIntIterator
37: implements IndexIterator {
38: protected String term;
39: protected int id;
40:
41: public void term(final CharSequence term) {
42: this .term = term == null ? null : term.toString();
43: }
44:
45: public String term() {
46: return term;
47: }
48:
49: public void id(final int id) {
50: this .id = id;
51: }
52:
53: public int id() {
54: return id;
55: }
56:
57: public boolean accept(DocumentIteratorVisitor visitor)
58: throws IOException {
59: // TODO: there used to be a visitPost(); check that this works
60: return visitor.visit(this );
61: }
62:
63: public boolean acceptOnTruePaths(DocumentIteratorVisitor visitor)
64: throws IOException {
65: return visitor.visit(this );
66: }
67:
68: @Deprecated
69: public IntervalIterator iterator() {
70: try {
71: return intervalIterator();
72: } catch (IOException e) {
73: throw new RuntimeException(e);
74: }
75: }
76:
77: }
|