KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.utils.field;
2
3 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes;
4 import com.daffodilwoods.database.resource.DException;
5 import com.daffodilwoods.daffodildb.utils.BufferRange;
6 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
7 import java.util.*;
8
9 public class FieldDouble
10     extends FieldBase
11     implements Datatypes, Comparable JavaDoc {
12
13   public FieldDouble(BufferRange bufferRange0, int datatype0) {
14     bufferRange = bufferRange0;
15     datatype = datatype0;
16   }
17
18   public Object JavaDoc getObject() throws DException {
19
20     if (bufferRange.getNull())
21       return null;
22     if (object != null)
23       return object;
24     long a = 0;
25     for (int i = 0, j = 56; i < 8; i++, j -= 8)
26       a += ( (long) bufferRange.getByte(i) & 0xFF) << j;
27     double f = Double.longBitsToDouble(a);
28     return object = new Double JavaDoc(f);
29
30   }
31
32   public boolean equals(Object JavaDoc fieldBase) {
33     try {
34       return (getDatatype() != ( (FieldBase) fieldBase).getDatatype()) ? false :
35           GetByteComparator.sameComparator.compare(this, fieldBase) == 0;
36     }
37     catch (DException ex) {
38       return false;
39     }
40   }
41
42   public int compareTo(Object JavaDoc fieldBase) {
43     try {
44       return GetByteComparator.sameComparator.compare(this, fieldBase);
45     }
46     catch (DException ex) {
47       return -1;
48     }
49   }
50
51   public String JavaDoc toString() {
52     try {
53       return "FieldDouble [ Object = " + getObject() + " DataType = " +
54           datatype + " ]";
55     }
56     catch (DException ex) {
57       throw new RuntimeException JavaDoc(ex.getMessage());
58     }
59   }
60 }
61
Popular Tags