pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / AbstractAllTermDocs.java
1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.lucene.index;
19
20 import java.io.IOException;
21
22 /** Base class for enumerating all but deleted docs.
23  * 
24  * <p>NOTE: this class is meant only to be used internally
25  * by Lucene; it's only public so it can be shared across
26  * packages.  This means the API is freely subject to
27  * change, and, the class could be removed entirely, in any
28  * Lucene release.  Use directly at your own risk! */
29 public abstract class AbstractAllTermDocs implements TermDocs {
30
31   protected int maxDoc;
32   protected int doc = -1;
33
34   protected AbstractAllTermDocs(int maxDoc) {
35     this.maxDoc = maxDoc;
36   }
37
38   public void seek(Term term) throws IOException {
39     if (term==null) {
40       doc = -1;
41     } else {
42       throw new UnsupportedOperationException();
43     }
44   }
45
46   public void seek(TermEnum termEnum) throws IOException {
47     throw new UnsupportedOperationException();
48   }
49
50   public int doc() {
51     return doc;
52   }
53
54   public int freq() {
55     return 1;
56   }
57
58   public boolean next() throws IOException {
59     return skipTo(doc+1);
60   }
61
62   public int read(int[] docs, int[] freqs) throws IOException {
63     final int length = docs.length;
64     int i = 0;
65     while (i < length && doc < maxDoc) {
66       if (!isDeleted(doc)) {
67         docs[i] = doc;
68         freqs[i] = 1;
69         ++i;
70       }
71       doc++;
72     }
73     return i;
74   }
75
76   public boolean skipTo(int target) throws IOException {
77     doc = target;
78     while (doc < maxDoc) {
79       if (!isDeleted(doc)) {
80         return true;
81       }
82       doc++;
83     }
84     return false;
85   }
86
87   public void close() throws IOException {
88   }
89
90   public abstract boolean isDeleted(int doc);
91 }