KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > fulltext > dql > iterator > AnyWordsAbstractIterator


1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
5 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
7 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass;
8 import com.daffodilwoods.database.utility.*;
9 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
10 import java.util.Arrays JavaDoc;
11
12 /**
13  * <p>Title: AnyWordsAbstractIterator</p>
14  * <p>Description:
15  * This Class handles the common code corresponding to Rank4
16  * and AnyKeyWords iterator.
17  * </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23 public abstract class AnyWordsAbstractIterator extends FTException {
24
25   /**
26    * A boolean variable to maintain the navigation direction. This variable is
27    * true if iterator is navigating from top to bottom and false otherwise.
28    */

29   protected boolean direction;
30   /**
31    * An Ith Iterator Index having some ( or all records in case of rank 4)
32    */

33   protected int iterIndex = -1;
34   /**
35    * An integer variable to maintain mixed fetching.
36    */

37   protected int state = -1;
38
39   public Object JavaDoc getColumnValues() throws DException {
40     return fullTextIndex[iterIndex].getColumnValues();
41   }
42
43   public Object JavaDoc getColumnValues(int[] columns) throws DException {
44     return fullTextIndex[iterIndex].getColumnValues(columns);
45   }
46
47   public Object JavaDoc getColumnValues(_Reference[] references) throws DException {
48     Object JavaDoc[] fbsToRet = new Object JavaDoc[references.length];
49     for (int i = 0; i < references.length; i++) {
50       fbsToRet[i] = getColumnValues(references[i]);
51     }
52     return fbsToRet;
53   }
54
55   public Object JavaDoc getColumnValues(_Reference reference) throws DException {
56     return fullTextIndex[iterIndex].getColumnValues(reference);
57   }
58
59   public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException {
60     return fullTextIndex[iterIndex].field(reference);
61   }
62
63   public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException {
64     FieldBase[] fbsToRet = new FieldBase[references.length];
65     for (int i = 0; i < references.length; i++) {
66       fbsToRet[i] = field(references[i]);
67     }
68     return fbsToRet;
69   }
70
71   public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException {
72     return (FieldBase[]) getColumnValues(columns);
73   }
74
75   /**
76    * Returns the comparision result
77    * @param b1 first value
78    * @param b2 second value
79    * @return 0 if value are same, -1 if b1 < b2 , 1 IF b1 > b2.
80    */

81   public int compare(Object JavaDoc ob1, Object JavaDoc ob2 ) throws DException{
82     return GetByteComparator.sameComparator.compare(ob1,ob2);
83   }
84
85   /**
86    * This method returns true if all the token iterators are at invalid
87    * position, dalse, otherwise.
88    * @return
89    * @throws DException
90    */

91
92   protected boolean allFalse() throws DException{
93      for (int i = 0; i < fullTextIndex.length; i++) {
94         try {
95           fullTextIndex[i].getColumnValues(documentIdColumn);
96         }
97         catch (DException ex) {
98            continue;
99         }
100         return false;
101      }
102      return true;
103   }
104
105   /**
106    * This method checks whether all the token table iterators have the same
107    * document id. This method marks the iterator having the minimum document
108    * id by maintaining its index.
109    * @return true if all the iterator corresponds to same document id, false
110    * ohterwise.
111    * @throws DException
112    */

113   protected boolean allSameWithSmallest() throws DException {
114     Object JavaDoc min = null;
115     boolean allSame = true;
116     for (int i = 0; i < fullTextIndex.length; i++) {
117       Object JavaDoc nValue = null;
118       try {
119         nValue = fullTextIndex[i].getColumnValues(documentIdColumn);
120       }
121       catch (DException ex) {
122          allSame = false;
123          continue;
124       }
125       if (min == null) {
126         min = nValue;
127         iterIndex = i;
128         continue;
129       }
130       int cmp = compare(nValue, min);
131       if(cmp < 0) {
132          iterIndex = i;
133          min = nValue;
134          allSame = false;
135       }
136       else if( cmp > 0) {
137          allSame = false;
138       }
139     }
140 if(allSame){
141 }
142 else{
143 }
144     return allSame;
145   }
146
147
148   /**
149    * This method checks whether all the token table iterators have the same
150    * document id. This method marks the iterator having the maximum document
151    * id by maintaining its index.
152    * @return true if all the iterator corresponds to same document id, false
153    * ohterwise.
154    * @throws DException
155    */

156   protected boolean allSameWithLargest() throws DException {
157            Object JavaDoc max = null;
158            boolean allSame = true;
159            for (int i = 0; i < fullTextIndex.length; i++) {
160              Object JavaDoc nValue = null;
161              try {
162                nValue = fullTextIndex[i].getColumnValues(documentIdColumn);
163              }
164              catch (DException ex) {
165                 allSame = false;
166                 continue;
167              }
168              if (max == null) {
169                max = nValue;
170                iterIndex = i;
171                continue;
172              }
173              int cmp = compare(nValue, max);
174              if(cmp > 0) {
175                 iterIndex = i;
176                 max = nValue;
177                 allSame = false;
178              }
179              else if( cmp < 0) {
180                 allSame = false;
181              }
182            }
183 if(allSame){
184 }
185 else{
186 }
187            return allSame;
188   }
189
190   /**
191    * This method returns an array of iterator indexes having the minimum
192    * document - id. This method is called while reversing the traversing
193    * direction.
194    * @return
195    * @throws DException
196    */

197   protected boolean[] getSmallest() throws DException {
198     Object JavaDoc minValue = null;
199     int len = fullTextIndex.length;
200     boolean[] isMinimum = new boolean[len];
201     for (int i = 0; i < fullTextIndex.length; i++) {
202       Object JavaDoc nValue = null;
203       try {
204         nValue = fullTextIndex[i].getColumnValues(documentIdColumn);
205       }
206       catch (Exception JavaDoc ex) {
207          continue;
208       }
209       if (minValue == null) {
210         minValue = nValue;
211         isMinimum[i] = true;
212         continue;
213       }
214       int cmp = compare(nValue, minValue);
215       if(cmp < 0){
216          java.util.Arrays.fill(isMinimum, false);
217          minValue = nValue;
218          isMinimum[i] = true;
219       }
220       else if(cmp == 0){
221          isMinimum[i] = true;
222       }
223     }
224     return isMinimum;
225   }
226
227   /**
228    * This method handles the iterator indexes that have the record
229    * with the maximum document id during backward fetching.
230    * @return an array of boolean having corresponding iterators
231    * having true for minimum documentid, false otherwise.
232    * @throws DException
233    */

234   protected boolean[] getLargest() throws DException {
235     Object JavaDoc maxValue = null;
236     int len = fullTextIndex.length;
237     boolean[] isMaximum = new boolean[len];
238     for (int i = 0; i < fullTextIndex.length; i++) {
239       Object JavaDoc nValue = null;
240       try {
241         nValue = fullTextIndex[i].getColumnValues(documentIdColumn);
242       }
243       catch (Exception JavaDoc ex) {
244          continue;
245       }
246       if (maxValue == null) {
247         maxValue = nValue;
248         isMaximum[i] = true;
249         continue;
250       }
251       int cmp = compare(nValue, maxValue);
252       if(cmp > 0){
253          java.util.Arrays.fill(isMaximum, false);
254          maxValue = nValue;
255          isMaximum[i] = true;
256       }
257       else if(cmp == 0){
258          isMaximum[i] = true;
259       }
260     }
261     return isMaximum;
262   }
263 }
264
Popular Tags