Coverage Report - org.galagosearch.core.retrieval.structured.ExtentConjunctionIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtentConjunctionIterator
76%
22/29
60%
6/10
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 package org.galagosearch.core.retrieval.structured;
 3  
 
 4  
 import java.io.IOException;
 5  
 import java.util.ArrayList;
 6  
 import org.galagosearch.core.util.ExtentArray;
 7  
 
 8  
 /**
 9  
  *
 10  
  * @author trevor
 11  
  */
 12  
 public abstract class ExtentConjunctionIterator extends ExtentIterator {
 13  
     protected ExtentIterator[] extentIterators;
 14  
     protected ExtentArray extents;
 15  
     protected int document;
 16  
     protected boolean done;
 17  
 
 18  28
     public ExtentConjunctionIterator(ExtentIterator[] extIterators) {
 19  28
         this.done = false;
 20  28
         this.extentIterators = extIterators;
 21  28
         this.extents = new ExtentArray();
 22  28
     }
 23  
 
 24  
     public abstract void loadExtents();
 25  
 
 26  
     public void nextDocument() throws IOException {
 27  16
         if (!done) {
 28  16
             extentIterators[0].nextDocument();
 29  16
             findDocument();
 30  
         }
 31  16
     }
 32  
 
 33  
     public void findDocument() throws IOException {
 34  48
         while (!done) {
 35  
             // find a document that might have some matches
 36  48
             document = MoveIterators.moveAllToSameDocument(extentIterators);
 37  
 
 38  
             // if we're done, quit now
 39  48
             if (document == Integer.MAX_VALUE) {
 40  24
                 done = true;
 41  24
                 break;
 42  
             }
 43  
 
 44  
             // try to load some extents (subclass does this)
 45  24
             extents.reset();
 46  24
             loadExtents();
 47  
 
 48  
             // were we successful? if so, quit, otherwise keep looking for documents
 49  24
             if (extents.getPosition() > 0) {
 50  20
                 break;
 51  
             }
 52  4
             extentIterators[0].nextDocument();
 53  
         }
 54  44
     }
 55  
 
 56  
     public ExtentArray extents() {
 57  24
         return extents;
 58  
     }
 59  
 
 60  
     public int document() {
 61  0
         return document;
 62  
     }
 63  
 
 64  
     public int count() {
 65  0
         return extents().getPosition();
 66  
     }
 67  
 
 68  
     public boolean isDone() {
 69  32
         return done;
 70  
     }
 71  
 
 72  
     public void reset() throws IOException {
 73  0
         for (ExtentIterator iterator : extentIterators) {
 74  0
             iterator.reset();
 75  
         }
 76  
 
 77  0
         done = false;
 78  0
         findDocument();
 79  0
     }
 80  
 }