Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart9.png 37% of files have more coverage
9   77   6   1.8
2   26   0.67   5
5     1.2  
1    
 
  HitIterator       Line # 29 9 6 87.5% 0.875
 
  (1)
 
1    /**
2    * Copyright 2005 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.apache.lucene.search;
18   
19    import java.util.Iterator;
20    import java.util.NoSuchElementException;
21   
22    /**
23    * An iterator over {@link Hits} that provides lazy fetching of each document.
24    * {@link Hits#iterator()} returns an instance of this class. Calls to {@link #next()}
25    * return a {@link Hit} instance.
26    *
27    * @author Jeremy Rayner
28    */
 
29    public class HitIterator implements Iterator {
30    private Hits hits;
31    private int hitNumber = 0;
32   
33    /**
34    * Constructed from {@link Hits#iterator()}.
35    */
 
36  1 toggle HitIterator(Hits hits) {
37  1 this.hits = hits;
38    }
39   
40    /**
41    * @return true if current hit is less than the total number of {@link Hits}.
42    */
 
43  3 toggle public boolean hasNext() {
44  3 return hitNumber < hits.length();
45    }
46   
47    /**
48    * Returns a {@link Hit} instance representing the next hit in {@link Hits}.
49    *
50    * @return Next {@link Hit}.
51    */
 
52  3 toggle public Object next() {
53  3 if (hitNumber == hits.length())
54  1 throw new NoSuchElementException();
55   
56  2 Object next = new Hit(hits, hitNumber);
57  2 hitNumber++;
58  2 return next;
59    }
60   
61    /**
62    * Unsupported operation.
63    *
64    * @throws UnsupportedOperationException
65    */
 
66  0 toggle public void remove() {
67  0 throw new UnsupportedOperationException();
68    }
69   
70    /**
71    * Returns the total number of hits.
72    */
 
73  1 toggle public int length() {
74  1 return hits.length();
75    }
76    }
77