Coverage Report - org.galagosearch.core.retrieval.structured.CountIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
CountIterator
45%
5/11
17%
3/18
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 package org.galagosearch.core.retrieval.structured;
 3  
 
 4  
 import java.io.IOException;
 5  
 
 6  
 /**
 7  
  * This is base interface for all inverted lists that return count information.
 8  
  *
 9  
  * @see ExtentIterator
 10  
  * @author trevor
 11  
  */
 12  192
 public abstract class CountIterator implements StructuredIterator, Comparable<CountIterator> {
 13  
     /**
 14  
      * Skips forward in the list until a document is found that is
 15  
      * greater than or equal to the parameter.  If the
 16  
      * iterator is currently pointing to a document that is greater
 17  
      * than or equal to the parameter, nothing happens.
 18  
      * 
 19  
      * @return true, if the iterator is now pointing at the desired document, or false otherwise.
 20  
      */
 21  
     public boolean skipToDocument(int document) throws IOException {
 22  0
         while (!isDone() && document > document()) {
 23  0
             nextDocument();
 24  
         }
 25  0
         return document == document();
 26  
     }
 27  
 
 28  
     /**
 29  
      * Moves the iterator to the next document in the list.  If
 30  
      * no such document is available, isDone() will return true
 31  
      * after this method is called.
 32  
      */
 33  
     public abstract void nextDocument() throws IOException;
 34  
 
 35  
     /**
 36  
      * Returns the current document.
 37  
      */
 38  
     public abstract int document();
 39  
 
 40  
     /**
 41  
      * Returns the number of occurrences of this iterator's term in
 42  
      * the current document.
 43  
      */
 44  
     public abstract int count();
 45  
 
 46  
     /**
 47  
      * Returns true if there is no data left in the list and false otherwise.
 48  
      * If the result of this method is true, the data returned from document()
 49  
      * and count() is meaningless.
 50  
      */
 51  
     public abstract boolean isDone();
 52  
 
 53  
     /**
 54  
      * Resets the position of this iterator to the start of the list.
 55  
      */
 56  
     public abstract void reset() throws IOException;
 57  
 
 58  
     /**
 59  
      * Compares the current document of two iterators.  This is primarily
 60  
      * useful for adding iterators to a PriorityQueue object for use during
 61  
      * retrieval.
 62  
      * 
 63  
      * @see PriorityQueue
 64  
      */
 65  
     public int compareTo(CountIterator other) {
 66  16
         if (isDone() && !other.isDone()) {
 67  0
             return 1;
 68  
         }
 69  16
         if (other.isDone() && !isDone()) {
 70  0
             return -1;
 71  
         }
 72  16
         if (isDone() && other.isDone()) {
 73  0
             return 0;
 74  
         }
 75  16
         return document() - other.document();
 76  
     }
 77  
 }