Coverage Report - org.galagosearch.core.retrieval.structured.SynonymIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
SynonymIterator
95%
21/22
86%
12/14
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 package org.galagosearch.core.retrieval.structured;
 3  
 
 4  
 import java.util.ArrayList;
 5  
 import java.util.PriorityQueue;
 6  
 import org.galagosearch.tupleflow.Parameters;
 7  
 
 8  
 /**
 9  
  *
 10  
  * @author trevor
 11  
  */
 12  
 public class SynonymIterator extends ExtentDisjunctionIterator {
 13  
     public SynonymIterator(Parameters parameters, ExtentIterator[] iterators) {
 14  8
         super(iterators);
 15  8
         loadExtents();
 16  8
     }
 17  
 
 18  
     public void loadExtents() {
 19  12
         ExtentIterator iter = iterators.poll();
 20  12
         document = iter.document();
 21  
 
 22  
         // get all the iteators that point to this document
 23  12
         ArrayList<ExtentIterator> useable = new ArrayList<ExtentIterator>();
 24  16
         while (iterators.size() > 0 && iterators.peek().document() == document) {
 25  4
             useable.add(iterators.poll());
 26  
         }
 27  12
         useable.add(iter);
 28  
 
 29  
         // make a priority queue of these ExtentArrayIterators
 30  12
         PriorityQueue<ExtentArrayIterator> arrayIterators = new PriorityQueue<ExtentArrayIterator>();
 31  12
         for (ExtentIterator iterator : useable) {
 32  16
             arrayIterators.offer(new ExtentArrayIterator(iterator.extents()));
 33  
         }
 34  28
         while (arrayIterators.size() > 0) {
 35  16
             ExtentArrayIterator top = arrayIterators.poll();
 36  16
             extents.add(top.current());
 37  
 
 38  16
             if (top.next()) {
 39  0
                 arrayIterators.offer(top);
 40  
             }
 41  16
         }
 42  
 
 43  
         // put back the ones we used
 44  12
         for (ExtentIterator i : useable) {
 45  16
             if (!i.isDone()) {
 46  16
                 iterators.offer(i);
 47  
             }
 48  
         }
 49  12
     }
 50  
 }