1
2 package org.galagosearch.core.retrieval.structured;
3
4 import java.io.IOException;
5
6 /***
7 * This is base interface for all inverted lists that return count information.
8 *
9 * @see ExtentIterator
10 * @author trevor
11 */
12 public abstract class CountIterator implements StructuredIterator, Comparable<CountIterator> {
13 /***
14 * Skips forward in the list until a document is found that is
15 * greater than or equal to the parameter. If the
16 * iterator is currently pointing to a document that is greater
17 * than or equal to the parameter, nothing happens.
18 *
19 * @return true, if the iterator is now pointing at the desired document, or false otherwise.
20 */
21 public boolean skipToDocument(int document) throws IOException {
22 while (!isDone() && document > document()) {
23 nextDocument();
24 }
25 return document == document();
26 }
27
28 /***
29 * Moves the iterator to the next document in the list. If
30 * no such document is available, isDone() will return true
31 * after this method is called.
32 */
33 public abstract void nextDocument() throws IOException;
34
35 /***
36 * Returns the current document.
37 */
38 public abstract int document();
39
40 /***
41 * Returns the number of occurrences of this iterator's term in
42 * the current document.
43 */
44 public abstract int count();
45
46 /***
47 * Returns true if there is no data left in the list and false otherwise.
48 * If the result of this method is true, the data returned from document()
49 * and count() is meaningless.
50 */
51 public abstract boolean isDone();
52
53 /***
54 * Resets the position of this iterator to the start of the list.
55 */
56 public abstract void reset() throws IOException;
57
58 /***
59 * Compares the current document of two iterators. This is primarily
60 * useful for adding iterators to a PriorityQueue object for use during
61 * retrieval.
62 *
63 * @see PriorityQueue
64 */
65 public int compareTo(CountIterator other) {
66 if (isDone() && !other.isDone()) {
67 return 1;
68 }
69 if (other.isDone() && !isDone()) {
70 return -1;
71 }
72 if (isDone() && other.isDone()) {
73 return 0;
74 }
75 return document() - other.document();
76 }
77 }