KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > field > FieldTimeLiteral


1 package com.daffodilwoods.daffodildb.utils.field;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype;
6 import com.daffodilwoods.daffodildb.utils.BufferRange;
7 import java.sql.Time JavaDoc;
8
9 public class FieldTimeLiteral extends FieldBase implements Comparable JavaDoc{
10
11   public FieldTimeLiteral(Object JavaDoc object0){
12     object = object0;
13     datatype = Datatype.TIME;
14   }
15
16   public FieldTimeLiteral(BufferRange bufferRange0) {
17     bufferRange = bufferRange0;
18     datatype = Datatype.TIME;
19   }
20
21   public Object JavaDoc getObject() throws DException{
22     return object;
23   }
24
25   public BufferRange getBufferRange() {
26     if(bufferRange == null)
27       bufferRange = new BufferRange(getBytes((Time JavaDoc)object));
28     return bufferRange;
29   }
30
31   public byte[] getBytes(Time JavaDoc time)
32   {
33      if( time == null)
34        return null;
35      byte b[] = new byte[8];
36      long a1 = time.getTime();
37      for(int i = 56 , j=0 ; i >= 0 ; i-= 8)
38          b[j++]=(byte)((a1 >> i) & 0xFF);
39      return b;
40   }
41
42   public boolean equals(Object JavaDoc fieldBase){
43       try {
44           return (getDatatype() != ((FieldBase)fieldBase).getDatatype()) ? false :
45                   GetByteComparator.sameComparator.compare(this,fieldBase) == 0;
46       }catch (DException ex) {
47           return false;
48       }
49   }
50
51   public int compareTo(Object JavaDoc fieldBase){
52       try {
53           return GetByteComparator.sameComparator.compare(this,fieldBase);
54       }catch (DException ex) {
55           return -1;
56       }
57   }
58
59
60   public boolean isNull() {
61       return object == null;
62   }
63
64   public boolean getNull() {
65       return object == null;
66   }
67
68   public void setDatatype(int type) throws DException{
69   }
70   public void setBufferRange(BufferRange range) {
71    throw new RuntimeException JavaDoc("Create new instance of FieldTimeLiteral instead of setting the bufferrange. Discuss with Neeraj or Parveen Sir ");
72 }
73
74 }
75
Popular Tags