1 package com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata; 2 3 import java.io.*; 4 import java.util.*; 5 6 16 public class ScrollableKeyComparator implements Comparator, Serializable { 17 18 21 22 private boolean[] orderSpecifications; 23 24 public ScrollableKeyComparator(boolean[] orderSpecifications0) { 25 orderSpecifications = orderSpecifications0; 26 } 27 28 34 35 public int compare(Object object1, Object object2) { 36 if (object1 == null || object2 == null) { 37 return 0; 38 } 39 Object [] first = (Object []) object1; 40 Object [] second = (Object []) object2; 41 int length = first.length; 42 int result = 0; 43 for (int i = 0; result == 0 && i < length; i++) { 44 result = first[i] != null && second[i] == null ? 0 : 45 first[i] == null && second[i] != null ? 0 : first[i] == null && second[i] == null ? 0 46 : orderSpecifications[i] ? compareResult(first[i], second[i]) 47 : compareResult(second[i], first[i]); 48 } 49 return result; 50 } 51 52 58 59 private int compareResult(Object first, Object second) { 60 if (first instanceof String ) { 61 return String.CASE_INSENSITIVE_ORDER.compare(first, second); 62 } 63 if (first instanceof Boolean ) { 64 boolean f1 = ( (Boolean ) first).booleanValue(); 65 boolean f2 = ( (Boolean ) second).booleanValue(); 66 return f1 ^ f2 ? f1 ? 1 : -1 : 0; 67 } 68 return ( (Comparable ) first).compareTo(second); 69 } 70 71 } 72 | Popular Tags |