Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart8.png 55% of files have more coverage
26   91   14   4.33
14   48   0.54   6
6     2.33  
1    
 
  FilteredTermEnum       Line # 27 26 14 76.1% 0.76086956
 
  (5)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 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 java.io.IOException;
20    import org.apache.lucene.index.Term;
21    import org.apache.lucene.index.TermEnum;
22   
23    /** Abstract class for enumerating a subset of all terms.
24   
25    <p>Term enumerations are always ordered by Term.compareTo(). Each term in
26    the enumeration is greater than all that precede it. */
 
27    public abstract class FilteredTermEnum extends TermEnum {
28    private Term currentTerm = null;
29    private TermEnum actualEnum = null;
30   
 
31  57 toggle public FilteredTermEnum() {}
32   
33    /** Equality compare on the term */
34    protected abstract boolean termCompare(Term term);
35   
36    /** Equality measure on the term */
37    public abstract float difference();
38   
39    /** Indicates the end of the enumeration has been reached */
40    protected abstract boolean endEnum();
41   
 
42  57 toggle protected void setEnum(TermEnum actualEnum) throws IOException {
43  57 this.actualEnum = actualEnum;
44    // Find the first term that matches
45  57 Term term = actualEnum.term();
46  57 if (term != null && termCompare(term))
47  29 currentTerm = term;
48  28 else next();
49    }
50   
51    /**
52    * Returns the docFreq of the current Term in the enumeration.
53    * Returns -1 if no Term matches or all terms have been enumerated.
54    */
 
55  0 toggle public int docFreq() {
56  0 if (actualEnum == null) return -1;
57  0 return actualEnum.docFreq();
58    }
59   
60    /** Increments the enumeration to the next element. True if one exists. */
 
61  111 toggle public boolean next() throws IOException {
62  0 if (actualEnum == null) return false; // the actual enumerator is not initialized!
63  111 currentTerm = null;
64  212 while (currentTerm == null) {
65  212 if (endEnum()) return false;
66  182 if (actualEnum.next()) {
67  139 Term term = actualEnum.term();
68  139 if (termCompare(term)) {
69  38 currentTerm = term;
70  38 return true;
71    }
72    }
73  43 else return false;
74    }
75  0 currentTerm = null;
76  0 return false;
77    }
78   
79    /** Returns the current Term in the enumeration.
80    * Returns null if no Term matches or all terms have been enumerated. */
 
81  83 toggle public Term term() {
82  83 return currentTerm;
83    }
84   
85    /** Closes the enumeration to further activity, freeing resources. */
 
86  57 toggle public void close() throws IOException {
87  57 actualEnum.close();
88  57 currentTerm = null;
89  57 actualEnum = null;
90    }
91    }