Coverage Report - org.paneris.bibliomania.fti.GroupTextSearchResults
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupTextSearchResults
0%
0/37
0%
0/18
2.25
 
 1  
 package org.paneris.bibliomania.fti;
 2  
 
 3  
 class GroupTextSearchResults extends TextSearchResultsBase {
 4  
   private TextSearchResults[] streams;
 5  
   private int[] positions;
 6  
   private TextSearchResults leadStream;
 7  
   private int currentWordIndex;
 8  
 
 9  0
   public GroupTextSearchResults(TextSearchResults[] streams) {
 10  0
     this.streams = streams;
 11  0
     positions = new int[streams.length];
 12  0
     for (int i = 0; i < positions.length; ++i)
 13  0
       positions[i] = i;
 14  
 
 15  
     // FIXME sort them, actually
 16  
 
 17  0
     if (streams.length > 0)
 18  0
       leadStream = streams[0];
 19  0
   }
 20  
 
 21  
   /**
 22  
    * FIXME won't work if doing goups of not just single words, but then
 23  
    * positions can't be static either
 24  
    */
 25  
 
 26  
   public int hitWordsCount() {
 27  0
     return streams.length;
 28  
   }
 29  
 
 30  
   private void findHit() {
 31  0
     for (int w = 0; w < streams.length;) {
 32  0
       TextSearchResults stream = streams[w];
 33  0
       int wantedIndex = currentWordIndex + positions[w];
 34  0
       stream.skipToWordIndex(wantedIndex);
 35  0
       int streamIndex = stream.currentWordIndex();
 36  0
       if (streamIndex == -1) {
 37  0
         currentWordIndex = -1;
 38  0
         return;
 39  
       }
 40  
 
 41  0
       if (streamIndex == wantedIndex)
 42  0
         ++w;
 43  
       else {
 44  0
         currentWordIndex = streamIndex - positions[w];
 45  0
         w = 0;
 46  
       }
 47  0
     }
 48  0
   }
 49  
 
 50  
   public void init() {
 51  0
     for (int w = 0; w < streams.length; ++w)
 52  0
       streams[w].init();
 53  0
     currentWordIndex = 0;
 54  0
     findHit();
 55  0
   }
 56  
 
 57  
   public void skipToNextHit() {
 58  0
     if (currentWordIndex != -1) {
 59  0
       ++currentWordIndex;
 60  0
       findHit();
 61  
     }
 62  0
   }
 63  
 
 64  
   public int currentOffset() {
 65  0
     return currentWordIndex == -1 ? -1 : leadStream.currentOffset();
 66  
   }
 67  
 
 68  
   public int currentWordIndex() {
 69  0
     return currentWordIndex;
 70  
   }
 71  
 
 72  
   public void close() {
 73  0
     for (int i = 0; i < streams.length; ++i)
 74  0
       streams[i].close();
 75  0
   }
 76  
 }