Coverage Report - org.paneris.bibliomania.fti.ScoredHitTextsEnumeration
 
Classes in this File Line Coverage Branch Coverage Complexity
ScoredHitTextsEnumeration
0%
0/43
0%
0/20
2.071
 
 1  
 package org.paneris.bibliomania.fti;
 2  
 
 3  
 import java.util.Enumeration;
 4  
 import java.util.Vector;
 5  
 
 6  
 import org.melati.util.PagedEnumeration;
 7  
 
 8  
 import com.sleepycat.db.DatabaseException;
 9  
 
 10  
 public class ScoredHitTextsEnumeration implements PagedEnumeration {
 11  
   private ContextSearchResults results;
 12  
 
 13  
   private int pageStart, pageSize, requestedPageSize;
 14  
 
 15  
   // private HitText hitText = null;
 16  
   private boolean totalCountIsMinimum;
 17  
 
 18  
   private Enumeration us;
 19  
 
 20  
   public ScoredHitTextsEnumeration(ContextSearchResults resultsP,
 21  
       Score.Hit[] scores, int pageStart, int requestedPageSize, int hitsPerText)
 22  0
       throws FTIException {
 23  
     try {
 24  0
       this.results = resultsP;
 25  0
       this.pageStart = pageStart = Math.max(pageStart, 1);
 26  0
       this.requestedPageSize = requestedPageSize;
 27  
 
 28  0
       int h = 0;
 29  0
       int areaCount = 0, areasInThisText = 0;
 30  0
       while (areaCount + 1 < pageStart) {
 31  0
         if (results.nextArea() == null || areasInThisText >= hitsPerText) {
 32  0
           if (h >= scores.length)
 33  0
             break;
 34  0
           results.gotoText(scores[h++].textID);
 35  0
           areasInThisText = 0;
 36  
         } else {
 37  0
           ++areaCount;
 38  0
           ++areasInThisText;
 39  
         }
 40  
       }
 41  
 
 42  0
       Vector texts = new Vector();
 43  
       int a;
 44  0
       for (a = 0; a < requestedPageSize && h < scores.length; ++h) {
 45  0
         results.gotoText(scores[h].textID);
 46  
 
 47  
         // Just make sure the text exists---we let old indexings hang around
 48  
         // rather than expend effort deleting them
 49  
 
 50  0
         if (results.currentText() != null) {
 51  0
           HitText text = new HitText(scores[h].score, results, Math.min(
 52  
               requestedPageSize - a, hitsPerText - areasInThisText));
 53  0
           areasInThisText = 0;
 54  0
           texts.addElement(text);
 55  0
           a += text.areas;
 56  
         }
 57  
       }
 58  
 
 59  0
       totalCountIsMinimum = a == requestedPageSize;
 60  0
       pageSize = a;
 61  
 
 62  0
       us = texts.elements();
 63  0
     } catch (DatabaseException e) {
 64  0
       throw new FTIException(e);
 65  0
     }
 66  0
   }
 67  
 
 68  
   // 
 69  
   // -------------
 70  
   // Enumeration
 71  
   // -------------
 72  
   // 
 73  
 
 74  
   public boolean hasMoreElements() {
 75  0
     return us.hasMoreElements();
 76  
   }
 77  
 
 78  
   public Object nextElement() {
 79  0
     return us.nextElement();
 80  
   }
 81  
 
 82  
   // 
 83  
   // -----------------
 84  
   // PageEnumeration
 85  
   // -----------------
 86  
   // 
 87  
 
 88  
   public int getPageStart() {
 89  0
     return pageStart;
 90  
   }
 91  
 
 92  
   public int getPageSize() {
 93  0
     return pageSize;
 94  
   }
 95  
 
 96  
   public int getPageEnd() {
 97  0
     return pageStart + pageSize - 1;
 98  
   }
 99  
 
 100  
   public int getTotalCount() {
 101  0
     return getPageEnd();
 102  
   }
 103  
 
 104  
   public boolean getTotalCountIsMinimum() {
 105  0
     return totalCountIsMinimum;
 106  
   }
 107  
 
 108  
   public Integer getPrevPageStart() {
 109  0
     int it = pageStart - requestedPageSize;
 110  0
     return it < 0 ? null : new Integer(it);
 111  
   }
 112  
 
 113  
   public Integer getNextPageStart() {
 114  0
     return totalCountIsMinimum ? new Integer(pageStart + requestedPageSize)
 115  
         : null;
 116  
   }
 117  
 
 118  
   public int getCurrentPosition() {
 119  0
     throw new RuntimeException("No one else has ever called this method.");
 120  
   }
 121  
 
 122  
   public int getNextPosition() {
 123  0
     throw new RuntimeException("No one else has ever called this method.");
 124  
   }
 125  
 
 126  
   public Vector getPages() {
 127  0
     throw new RuntimeException("No one else has ever called this method.");
 128  
   }
 129  
 
 130  
   public boolean nextElementOnThisPage() {
 131  0
     throw new RuntimeException("No one else has ever called this method.");
 132  
   }
 133  
 }