KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > search > HitIterator


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.modules.search;
14
15 import java.io.IOException JavaDoc;
16 import java.util.Iterator JavaDoc;
17
18 import org.apache.lucene.search.Hits;
19
20 import com.openedit.OpenEditRuntimeException;
21
22
23 /**
24  * DOCUMENT ME!
25  *
26  * @author cburkey
27  */

28 public class HitIterator implements Iterator JavaDoc
29 {
30     protected Hits fieldHits;
31     protected int hitCount = 0;
32     protected int startOffset = 0;
33
34     public HitIterator(Hits inHits)
35     {
36         setHits(inHits);
37     }
38
39     public HitIterator()
40     {
41     }
42     public void setStartOffset( int inStart)
43     {
44         startOffset = inStart;
45     }
46     /**
47      * DOCUMENT ME!
48      *
49      * @param inHits
50      */

51     public void setHits(Hits inHits)
52     {
53         fieldHits = inHits;
54     }
55
56     /**
57      * DOCUMENT ME!
58      *
59      * @return
60      */

61     public Hits getHits()
62     {
63         return fieldHits;
64     }
65
66     /**
67      * @see java.util.Iterator#hasNext()
68      */

69     public boolean hasNext()
70     {
71         if (hitCount < getHits().length())
72         {
73             return true;
74         }
75         else
76         {
77             return false;
78         }
79     }
80
81     /**
82      * @see java.util.Iterator#next()
83      */

84     public Object JavaDoc next()
85     {
86         try
87         {
88             return getHits().doc(startOffset + hitCount++);
89         }
90         catch (IOException JavaDoc ex)
91         {
92             throw new OpenEditRuntimeException(ex);
93         }
94     }
95
96     /**
97      * @see java.util.Iterator#remove()
98      */

99     public void remove()
100     {
101     }
102 }
103
Popular Tags