View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   package org.galagosearch.core.retrieval.structured;
3   
4   import org.galagosearch.core.util.ExtentArray;
5   
6   /***
7    *
8    * @author trevor
9    */
10  public class ExtentArrayIterator implements Comparable<ExtentArrayIterator> {
11      ExtentArray array;
12      int index;
13  
14      public ExtentArrayIterator(ExtentArray array) {
15          this.array = array;
16      }
17  
18      public Extent current() {
19          return array.getBuffer()[index];
20      }
21  
22      public boolean next() {
23          index += 1;
24          return index < array.getPosition();
25      }
26  
27      public boolean isDone() {
28          return array.getPosition() <= index;
29      }
30  
31      public int compareTo(ExtentArrayIterator iterator) {
32          int result = current().document - iterator.current().document;
33  
34          if (result != 0) {
35              return result;
36          }
37          return current().begin - iterator.current().begin;
38      }
39  }