1 6 7 package com.daffodilwoods.daffodildb.utils.comparator; 8 9 import java.sql.*; 10 11 import com.daffodilwoods.daffodildb.utils.*; 12 import com.daffodilwoods.database.resource.*; 13 14 29 30 public class DateComparator extends SuperComparator { 31 34 public DateComparator(boolean nullSortedHigh) { 35 super(nullSortedHigh); 36 } 37 38 42 43 public DateComparator() { 44 } 45 46 55 public int compare(_DComparator b1, _DComparator b2) throws DException { 56 long l1 = getLongValue(b1.getBytes(), 0); 57 long l2 = getLongValue(b2.getBytes(), 0); 58 return comparedates(new Date(l1), new Date(l2)); 59 } 60 61 private int comparedates(Date d1, Date d2) { 62 return ( (d1.getYear() == d2.getYear()) ? 63 (d1.getMonth() == d2.getMonth()) ? 64 (d1.getDate() == d2.getDate()) ? 0 : 65 ( (d1.getDate() > d2.getDate()) ? 1 : -1) 66 : (d1.getMonth() > d2.getMonth() ? 1 : -1) 67 : d1.getYear() > d2.getYear() ? 1 : -1); 68 } 69 70 private long getLongValue(byte[] bytes, int position) throws DException { 71 long a = ( (bytes[position + 7] & 0xFFL) << 0) | 72 ( (bytes[position + 6] & 0xFFL) << 8) | 73 ( (bytes[position + 5] & 0xFFL) << 16) | 74 ( (bytes[position + 4] & 0xFFL) << 24) | 75 ( (bytes[position + 3] & 0xFFL) << 32) | 76 ( (bytes[position + 2] & 0xFFL) << 40) | 77 ( (bytes[position + 1] & 0xFFL) << 48) | 78 ( (bytes[position + 0] & 0xFFL) << 56); 79 80 return a; 81 } 82 83 84 } 85 | Popular Tags |