add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / instantiated / src / java / org / apache / lucene / store / instantiated / InstantiatedTermEnum.java
1 package org.apache.lucene.store.instantiated;
2
3 /**
4  * Copyright 2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import org.apache.lucene.index.Term;
20 import org.apache.lucene.index.TermEnum;
21
22 /**
23  * A {@link org.apache.lucene.index.TermEnum} navigating an {@link org.apache.lucene.store.instantiated.InstantiatedIndexReader}.
24  */
25 public class InstantiatedTermEnum extends TermEnum {
26
27   private final InstantiatedIndexReader reader;
28
29   public InstantiatedTermEnum(InstantiatedIndexReader reader) {
30     this.nextTermIndex = 0;
31     this.reader = reader;
32   }
33
34   public InstantiatedTermEnum(InstantiatedIndexReader reader, int startPosition) {
35     this.reader = reader;
36     this.nextTermIndex = startPosition;
37     next();
38   }
39
40   private int nextTermIndex;
41   private InstantiatedTerm term;
42
43   /**
44    * Increments the enumeration to the next element.  True if one exists.
45    */
46   @Override
47   public boolean next() {
48     if (reader.getIndex().getOrderedTerms().length <= nextTermIndex) {
49       return false;
50     } else {
51       term = reader.getIndex().getOrderedTerms()[nextTermIndex];
52       nextTermIndex++;
53       return true;
54     }
55   }
56
57   /**
58    * Returns the current Term in the enumeration.
59    */
60   @Override
61   public Term term() {
62     return term == null ? null : term.getTerm();
63   }
64
65   /**
66    * Returns the docFreq of the current Term in the enumeration.
67    */
68   @Override
69   public int docFreq() {
70     return term.getAssociatedDocuments().length;
71   }
72
73   /**
74    * Closes the enumeration to further activity, freeing resources.
75    */
76   @Override
77   public void close() {
78   }
79
80 }
81
82
83