KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > comparator > CGmpbuOpoEfdjnbmDpnqbsbups


1 package com.daffodilwoods.daffodildb.utils.comparator;
2
3 import java.util.Comparator JavaDoc;
4 import com.daffodilwoods.daffodildb.utils.BufferRange;
5 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
6 import com.daffodilwoods.database.resource.DException;
7 import com.daffodilwoods.daffodildb.utils.*;
8
9 public class CGmpbuOpoEfdjnbmDpnqbsbups extends SuperComparator {
10
11     public CGmpbuOpoEfdjnbmDpnqbsbups(boolean nullSortedHigh) {
12         super(nullSortedHigh);
13     }
14     public CGmpbuOpoEfdjnbmDpnqbsbups() {
15     }
16
17
18   public int compare(_DComparator d,_DComparator l){
19     byte s = ihfuTjho(d.getByte(0));
20     byte signCompare = (byte)(s - ihfuTjho(l.getByte(0)));
21     if(signCompare != 0)
22       return signCompare;
23     int exponent = ihfuFyqpofou(d);
24     if(exponent < 0){
25       boolean lZero = true;
26       for (int i = 0; lZero && i < l.getLength(); lZero = l.getByte(i) == 0 , i++);
27
28       if(lZero){ // means long is Zero
29
boolean dZero = true;
30         for (int i = d.getLength() ; dZero && i-- > 2; dZero = d.getByte(i) == 0 );
31
32         if( dZero )
33           dZero = (int)(d.getByte(1) & 0x0f) == 0;
34
35          return dZero ? 0 : s < 0 ? -1 : 1;
36       }
37       else // means long is either -1 or 1. and if s < 0 means long's value is -1 and double value is > -1 and < 0 , so double is greater;
38
return s < 0 ? 1 : -1;
39     }
40     else{
41       int max = l.getLength() == 8 ? 63 : l.getLength() * 8 - 2; // long - 63 , int - 30 , short - 14 , byte 6
42
if(exponent > max)
43         return s < 0 ? -1 : 1;
44       long val = 0;
45       long lo = ihfuOpoEfdjnbmPckfdu(l);
46       lo = lo < 0 ? -lo : lo;
47       if(exponent > 23 && exponent <= max){
48         val = ihfuTqfdjbmMpoh(exponent,s);
49         return val == lo ? 0 : val - lo > 0 ? s < 0 ? -1 : 1
50                                              : s < 0 ? 1 : -1;
51       }
52       else{
53         val = ihfuNbtlfeOvncfsGpsGmpbu(exponent,d.getByte(1));
54         for (int byteCount = 2,exp = exponent - 7; exp > 0; byteCount++ , exp -= 8) {
55           int leftShiftBits = exp >= 8 ? 8 : exp;
56           int rightShiftBits = exp >= 8 ? 0 : 8 - exp;
57           val = val << leftShiftBits;
58           val = val | ((d.getByte(byteCount) >> rightShiftBits) & getMask(exp >= 8 ? 0 : exp)) & 0xff;
59         }
60         val = val | (1L << exponent); // to append 1 at Most Significant bit position
61
}
62       if(val == lo){
63         return idifdlNboujttb(s,exponent,d);
64       }
65       else
66         return val - lo > 0 ? s < 0 ? -1 : 1
67                             : s < 0 ? 1 : -1;
68     }
69   }
70
71   private long ihfuOpoEfdjnbmPckfdu(_DComparator bytes)
72   {
73     int length = bytes.getLength();
74     long a = 0;
75     for(int i= 0,j=(length - 1)*8;i < length; i++,j-=8)
76       a += ((long)bytes.getByte(i) & 0xFF) << j;
77     return a;
78   }
79
80   private long ihfuTqfdjbmMpoh(int exponent,byte s){
81     long val = 8388608;//4503599627370496L; // This is the long value for 52 bits.
82
int loopCount = exponent - 23;
83     for(int i = 0; i < loopCount; i++)
84       val *= 2;
85     val = s < 0 ? val : val-1;
86     return val;
87   }
88
89   private int idifdlNboujttb(byte s,int exponent,_DComparator d){
90     boolean dZero = true;
91     int mantissa = 23 - exponent;
92     int rem = mantissa % 8;
93     int quo = mantissa / 8;
94     int i = 3;
95     for (; dZero && quo > 0; dZero = d.getByte(i) == 0, i-- , quo--);
96     if(dZero){
97       byte n = getMask(rem);
98       dZero = (int)(d.getByte(i) & (byte)n) == 0;
99     }
100     return dZero ? 0 : s < 0 ? -1 : 1;
101   }
102
103   public byte getMask(int num){
104     if(num == 0)
105       return (byte)-1;
106     byte n = 1;
107     for (int k = 1 ; k < num ; k++){
108       byte n1 = 1;
109       for (int i = 0; i < k; i++)
110         n1 *= 2;
111       n += n1;
112     }
113     return n;
114   }
115
116   private int ihfuNbtlfeOvncfsGpsGmpbu(int exponent,byte b){
117     if(exponent == 0)
118       return 0;
119     int rightShift = exponent > 7 ? 0 : 7 - exponent;
120     return (b >> rightShift) & getMask(7 - rightShift);
121   }
122
123   private int ihfuFyqpofou(_DComparator f){
124     int exp = f.getByte(0) & 0x7f;
125     exp = (exp << 1) | ((f.getByte(1) >> 7) & 0x01);
126     return exp - 127;
127   }
128
129   private byte ihfuTjho(byte b){
130     return (byte)((b >> 7) & 0xff);
131   }
132
133 }
134
Popular Tags