01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.io.IOException;
21:
22: /** Abstract class for enumerating terms.
23:
24: <p>Term enumerations are always ordered by Term.compareTo(). Each term in
25: the enumeration is greater than all that precede it. */
26:
27: public abstract class TermEnum {
28: /** Increments the enumeration to the next element. True if one exists.*/
29: public abstract boolean next() throws IOException;
30:
31: /** Returns the current Term in the enumeration.*/
32: public abstract Term term();
33:
34: /** Returns the docFreq of the current Term in the enumeration.*/
35: public abstract int docFreq();
36:
37: /** Closes the enumeration to further activity, freeing resources. */
38: public abstract void close() throws IOException;
39:
40: // Term Vector support
41:
42: /** Skips terms to the first beyond the current whose value is
43: * greater or equal to <i>target</i>. <p>Returns true iff there is such
44: * an entry. <p>Behaves as if written: <pre>
45: * public boolean skipTo(Term target) {
46: * do {
47: * if (!next())
48: * return false;
49: * } while (target > term());
50: * return true;
51: * }
52: * </pre>
53: * Some implementations are considerably more efficient than that.
54: */
55: public boolean skipTo(Term target) throws IOException {
56: do {
57: if (!next())
58: return false;
59: } while (target.compareTo(term()) > 0);
60: return true;
61: }
62: }
|