Coverage Report - org.paneris.bibliomania.fti.OrTextSearchResults
 
Classes in this File Line Coverage Branch Coverage Complexity
OrTextSearchResults
0%
0/30
0%
0/18
2.125
 
 1  
 package org.paneris.bibliomania.fti;
 2  
 
 3  
 class OrTextSearchResults extends TextSearchResultsBase {
 4  
   private TextSearchResults[] streams;
 5  0
   private TextSearchResults currentStream = null;
 6  
   private int hitWordsCount;
 7  
 
 8  0
   public OrTextSearchResults(TextSearchResults[] streams) {
 9  0
     this.streams = streams;
 10  0
     hitWordsCount = 0;
 11  0
     for (int i = 0; i < streams.length; ++i)
 12  0
       hitWordsCount = Math.max(hitWordsCount, streams[i].hitWordsCount());
 13  0
   }
 14  
 
 15  
   public int hitWordsCount() {
 16  0
     return hitWordsCount;
 17  
   }
 18  
 
 19  
   public void init() {
 20  
     // FIXME sort streams by local count, but into a copied array
 21  0
     for (int w = 0; w < streams.length; ++w)
 22  0
       streams[w].init();
 23  0
     findHit();
 24  0
   }
 25  
 
 26  
   private void findHit() {
 27  0
     int firstIndex = Integer.MAX_VALUE;
 28  0
     currentStream = null;
 29  0
     for (int w = 0; w < streams.length; ++w) {
 30  0
       TextSearchResults stream = streams[w];
 31  0
       int streamIndex = stream.currentWordIndex();
 32  0
       if (streamIndex != -1 && streamIndex < firstIndex) {
 33  0
         firstIndex = streamIndex;
 34  0
         currentStream = stream;
 35  
       }
 36  
     }
 37  0
   }
 38  
 
 39  
   public void skipToNextHit() {
 40  0
     if (currentStream != null) {
 41  0
       currentStream.skipToNextHit();
 42  0
       findHit();
 43  
     }
 44  0
   }
 45  
 
 46  
   public int currentWordIndex() {
 47  0
     return currentStream == null ? -1 : currentStream.currentWordIndex();
 48  
   }
 49  
 
 50  
   public int currentOffset() {
 51  0
     return currentStream == null ? -1 : currentStream.currentOffset();
 52  
   }
 53  
 
 54  
   public void close() {
 55  0
     for (int i = 0; i < streams.length; ++i)
 56  0
       streams[i].close();
 57  0
   }
 58  
 }