1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator; 2 3 4 import java.util.*; 5 import com.daffodilwoods.daffodildb.utils.BufferRange; 6 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 7 import com.daffodilwoods.database.resource.DException; 8 import com.daffodilwoods.daffodildb.utils.*; 9 import com.daffodilwoods.daffodildb.utils.comparator.*; 10 11 public class FTComparator extends SuperComparator { 12 13 public FTComparator() { 14 } 15 16 public int compare1(_DComparator b1, _DComparator b2) { 17 int compareSign = b1.getByte(0) - b2.getByte(0); 18 if(compareSign != 0) 19 return compareSign < 0 ? -1 : 1; 20 for (int i = 1 , length = b1.getLength(); i < length; i++) { 21 byte ib1 = b1.getByte(i); 22 byte ib2 = b2.getByte(i); 23 compareSign = ib1 - ib2; 24 if(compareSign != 0){ 25 int s = getSign(ib2)-getSign(ib1); 26 return s != 0 ? s : compareSign ; 27 } 28 } 29 return 0; 30 } 31 32 38 public int compare(_DComparator b1, _DComparator b2) { 39 try { 40 long l1 = getLongValue( ((FieldBase) b1).getBufferRange(), 0); 41 long l2 = getLongValue( ((FieldBase) b2).getBufferRange(), 0); 42 return (int)(l1 - l2); 43 } 44 catch (DException ex) { 45 throw new RuntimeException (ex.getMessage()); 46 } 47 } 48 49 private boolean compareSign(byte b1, byte b2){ 50 return getSign(b1) == getSign(b2); 51 } 52 53 private byte getSign(byte b){ 54 return (byte)((b >> 7) & 0xff); 55 } 56 57 private static long getLongValue(BufferRange bytes,int position)throws DException{ 58 long a=0; 59 for(int i=position,k=position+8,j=56;i < k; i++,j-=8) 60 a += ((long)bytes.getByte(i) & 0xFF) << j; 61 return a; 62 } 63 } 64 | Popular Tags |