1 package com.quadcap.sql.types; 2 3 40 41 import java.io.ByteArrayInputStream ; 42 import java.io.ByteArrayOutputStream ; 43 44 import com.quadcap.sql.index.Comparator; 45 46 import com.quadcap.sql.io.ObjectInputStream; 47 import com.quadcap.sql.io.ObjectOutputStream; 48 49 import com.quadcap.util.Debug; 50 import com.quadcap.util.Util; 51 52 57 public class CompareValues extends Comparator { 58 int directions; 59 int cnt; 60 61 public CompareValues() {} 62 63 public CompareValues(int count) { 64 this.cnt = count; 65 this.directions = ~((~0) << count); 66 } 67 68 public void addField(boolean asc) { 69 directions <<= 1; 70 if (asc) directions |= 1; 71 cnt++; 72 } 73 74 110 111 public int compare(byte[] a, int aoff, int alen, 112 byte[] b, int boff, int blen) { 113 try { 114 ByteArrayInputStream ai = new ByteArrayInputStream (a, aoff, alen); 115 ObjectInputStream aoi = new ObjectInputStream(ai); 116 ByteArrayInputStream bi = new ByteArrayInputStream (b, boff, blen); 117 ObjectInputStream boi = new ObjectInputStream(bi); 118 for (int i = 0; i < cnt; i++) { 119 Value va = (Value)aoi.readObject(); 120 Value vb = (Value)boi.readObject(); 121 Value cmp = Value.binop(Op.COMPARE, va, vb); 122 ValueInteger vi = (ValueInteger)cmp; 124 int ret = vi.intValue(); 125 if (ret != 0) { 126 boolean asc = ((directions >> (cnt - i - 1)) & 1) != 0; 127 ret = asc ? ret : 0 - ret; 128 return ret; 129 } 130 } 131 return 0; 132 } catch (Exception e) { 133 Debug.print(e); 135 Debug.println("a = " + Util.hexBytes(a, aoff, alen)); 136 Debug.println("b = " + Util.hexBytes(b, boff, blen)); 137 throw new RuntimeException (e.toString()); 139 } 140 } 141 } 142 | Popular Tags |