Coverage Report - org.galagosearch.core.retrieval.structured.ExtentDisjunctionIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtentDisjunctionIterator
67%
20/30
67%
12/18
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 java.util.PriorityQueue;
 7  
 import org.galagosearch.core.util.ExtentArray;
 8  
 
 9  
 /**
 10  
  * This class is meant to be a base class for many kinds of
 11  
  * iterators that require at least one of their children to be
 12  
  * present in the document for a match to happen.  This class
 13  
  * will call loadExtents once for each document that has a
 14  
  * match on any child iterator.
 15  
  * 
 16  
  * @author trevor
 17  
  */
 18  
 public abstract class ExtentDisjunctionIterator extends ExtentIterator {
 19  
     protected ExtentIterator[] original;
 20  
     protected PriorityQueue<ExtentIterator> iterators;
 21  
     protected int document;
 22  
     protected ExtentArray extents;
 23  
 
 24  8
     public ExtentDisjunctionIterator(ExtentIterator[] iterators) {
 25  8
         this.original = iterators;
 26  8
         this.iterators = new PriorityQueue<ExtentIterator>(iterators.length);
 27  
 
 28  8
         this.extents = new ExtentArray();
 29  8
         this.document = 0;
 30  
 
 31  24
         for (ExtentIterator iterator : original) {
 32  16
             if (!iterator.isDone()) {
 33  16
                 this.iterators.add(iterator);
 34  
             }
 35  
         }
 36  8
     }
 37  
     
 38  
     public abstract void loadExtents();
 39  
 
 40  
     public void nextDocument() throws IOException {
 41  
         // find all iterators on the current document and move them forward
 42  28
         while (iterators.size() > 0 && iterators.peek().document() == document) {
 43  16
             ExtentIterator iter = iterators.poll();
 44  16
             iter.nextDocument();
 45  
 
 46  16
             if (!iter.isDone()) {
 47  0
                 iterators.offer(iter);
 48  
             }
 49  16
         }
 50  
 
 51  12
         if (!isDone()) {
 52  4
             extents.reset();
 53  4
             loadExtents();
 54  
         }
 55  12
     }
 56  
 
 57  
     public boolean isDone() {
 58  32
         return iterators.size() == 0;
 59  
     }
 60  
 
 61  
     public ExtentArray extents() {
 62  8
         return extents;
 63  
     }
 64  
 
 65  
     public int document() {
 66  0
         return document;
 67  
     }
 68  
 
 69  
     public int count() {
 70  0
         return extents.getPosition();
 71  
     }
 72  
 
 73  
     public void reset() throws IOException {
 74  0
         iterators.clear();
 75  0
         for (ExtentIterator iterator : original) {
 76  0
             iterator.reset();
 77  0
             if (!iterator.isDone()) {
 78  0
                 iterators.add(iterator);
 79  
             }
 80  
         }
 81  
 
 82  0
         loadExtents();
 83  0
     }
 84  
 }