Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart3.png 83% of files have more coverage
25   89   13   3.12
14   50   0.52   8
8     1.62  
1    
 
  SegmentTermVector       Line # 23 25 13 27.7% 0.27659574
 
  (15)
 
1    package org.apache.lucene.index;
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.util.*;
20   
21    /**
22    */
 
23    class SegmentTermVector implements TermFreqVector {
24    private String field;
25    private String terms[];
26    private int termFreqs[];
27   
 
28  135671 toggle SegmentTermVector(String field, String terms[], int termFreqs[]) {
29  135671 this.field = field;
30  135671 this.terms = terms;
31  135671 this.termFreqs = termFreqs;
32    }
33   
34    /**
35    *
36    * @return The number of the field this vector is associated with
37    */
 
38  15412 toggle public String getField() {
39  15412 return field;
40    }
41   
 
42  0 toggle public String toString() {
43  0 StringBuffer sb = new StringBuffer();
44  0 sb.append('{');
45  0 sb.append(field).append(": ");
46  0 if(terms != null){
47  0 for (int i=0; i<terms.length; i++) {
48  0 if (i>0) sb.append(", ");
49  0 sb.append(terms[i]).append('/').append(termFreqs[i]);
50    }
51    }
52  0 sb.append('}');
53   
54  0 return sb.toString();
55    }
56   
 
57  87633 toggle public int size() {
58  87633 return terms == null ? 0 : terms.length;
59    }
60   
 
61  171975 toggle public String [] getTerms() {
62  171976 return terms;
63    }
64   
 
65  51927 toggle public int[] getTermFrequencies() {
66  51927 return termFreqs;
67    }
68   
 
69  0 toggle public int indexOf(String termText) {
70  0 if(terms == null)
71  0 return -1;
72  0 int res = Arrays.binarySearch(terms, termText);
73  0 return res >= 0 ? res : -1;
74    }
75   
 
76  0 toggle public int[] indexesOf(String [] termNumbers, int start, int len) {
77    // TODO: there must be a more efficient way of doing this.
78    // At least, we could advance the lower bound of the terms array
79    // as we find valid indexes. Also, it might be possible to leverage
80    // this even more by starting in the middle of the termNumbers array
81    // and thus dividing the terms array maybe in half with each found index.
82  0 int res[] = new int[len];
83   
84  0 for (int i=0; i < len; i++) {
85  0 res[i] = indexOf(termNumbers[start+ i]);
86    }
87  0 return res;
88    }
89    }