KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > fulltext > common > ByteToken


1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.common;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import com.daffodilwoods.fulltext.common._Token;
6 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
7 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
8 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
9 import com.daffodilwoods.database.resource.*;
10 import com.daffodilwoods.database.utility.P;
11
12 /**
13  *
14  * <p>Title: </p>
15  * <p>Description: </p>
16  * <p>Copyright: Copyright (c) 2003</p>
17  * <p>Company: </p>
18  * @author not attributable
19  * @version 1.0
20  */

21 public class ByteToken implements _Token,Comparable JavaDoc {
22   FieldBase term;
23   long[] location;
24   SuperComparator comp = GetByteComparator.stringComparator;
25
26
27   public ByteToken(Object JavaDoc term, long loc) {
28     this.term = (FieldBase)term;
29     location = new long[]{loc};
30   }
31   /**
32    *
33    * @return
34    */

35   public long[] getLocation() {
36     return location;
37   }
38   /**
39    * this is getter method return term
40    * @return
41    */

42   public Object JavaDoc getTerm() {
43     return term;
44   }
45
46   /**
47    * add locations of particular term into Location array
48    */

49
50   public void addLocation(long[] loc) {
51      long[] temp = new long[location.length+loc.length];
52      System.arraycopy(location,0,temp,0,location.length);
53      System.arraycopy(loc,0,temp,location.length,loc.length);
54      location = temp;
55   }
56
57   public int compareTo(Object JavaDoc o){
58    try {
59       return comp.compare(term,((ByteToken)o).getTerm());
60    }
61    catch (DException ex) {
62       throw new RuntimeException JavaDoc(ex.getMessage());
63    }
64   }
65
66   public String JavaDoc toString(){
67     Object JavaDoc obj = null;
68     try {
69       obj = term.getObject();
70     }
71     catch (DException ex) {
72       throw new RuntimeException JavaDoc(ex.getMessage());
73     }
74     String JavaDoc t = obj instanceof byte[] ? new String JavaDoc((byte[])obj) : obj.toString();
75     return "ByteTokenizer[term = "+t+" Location = "+P.print(location)+"]";
76   }
77
78
79 }
80
Popular Tags