Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../../img/srcFileCovDistChart9.png 37% of files have more coverage
97   250   57   4.04
56   186   0.59   8
24     2.38  
3    
 
  NearSpansUnordered       Line # 27 74 40 85.3% 0.85294116
  NearSpansUnordered.CellQueue       Line # 44 6 3 100% 1.0
  NearSpansUnordered.SpansCell       Line # 62 17 14 93.5% 0.9354839
 
  (5)
 
1    package org.apache.lucene.search.spans;
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 java.io.IOException;
20   
21    import java.util.List;
22    import java.util.ArrayList;
23   
24    import org.apache.lucene.index.IndexReader;
25    import org.apache.lucene.util.PriorityQueue;
26   
 
27    class NearSpansUnordered implements Spans {
28    private SpanNearQuery query;
29   
30    private List ordered = new ArrayList(); // spans in query order
31    private int slop; // from query
32   
33    private SpansCell first; // linked list of spans
34    private SpansCell last; // sorted by doc only
35   
36    private int totalLength; // sum of current lengths
37   
38    private CellQueue queue; // sorted queue of spans
39    private SpansCell max; // max element in queue
40   
41    private boolean more = true; // true iff not done
42    private boolean firstTime = true; // true before first next()
43   
 
44    private class CellQueue extends PriorityQueue {
 
45  21 toggle public CellQueue(int size) {
46  21 initialize(size);
47    }
48   
 
49  292 toggle protected final boolean lessThan(Object o1, Object o2) {
50  292 SpansCell spans1 = (SpansCell)o1;
51  292 SpansCell spans2 = (SpansCell)o2;
52  292 if (spans1.doc() == spans2.doc()) {
53  149 return NearSpansOrdered.docSpansOrdered(spans1, spans2);
54    } else {
55  143 return spans1.doc() < spans2.doc();
56    }
57    }
58    }
59   
60   
61    /** Wraps a Spans, and can be used to form a linked list. */
 
62    private class SpansCell implements Spans {
63    private Spans spans;
64    private SpansCell next;
65    private int length = -1;
66    private int index;
67   
 
68  50 toggle public SpansCell(Spans spans, int index) {
69  50 this.spans = spans;
70  50 this.index = index;
71    }
72   
 
73  149 toggle public boolean next() throws IOException {
74  149 return adjust(spans.next());
75    }
76   
 
77  959 toggle public boolean skipTo(int target) throws IOException {
78  959 return adjust(spans.skipTo(target));
79    }
80   
 
81  1108 toggle private boolean adjust(boolean condition) {
82  1108 if (length != -1) {
83  1058 totalLength -= length; // subtract old length
84    }
85  1108 if (condition) {
86  1087 length = end() - start();
87  1087 totalLength += length; // add new length
88   
89  1087 if (max == null || doc() > max.doc()
90    || (doc() == max.doc()) && (end() > max.end())) {
91  954 max = this;
92    }
93    }
94  1108 more = condition;
95  1108 return condition;
96    }
97   
 
98  7167 toggle public int doc() { return spans.doc(); }
 
99  1609 toggle public int start() { return spans.start(); }
 
100  1581 toggle public int end() { return spans.end(); }
101   
 
102  0 toggle public String toString() { return spans.toString() + "#" + index; }
103    }
104   
105