1 package net.sf.saxon.sort; 2 import java.text.Collator ; 3 import java.util.Comparator ; 4 5 11 12 public class LowercaseFirstComparer implements Comparator , java.io.Serializable { 13 14 private Collator baseCollator; 15 16 public LowercaseFirstComparer(Collator base) { 17 baseCollator = base; 18 baseCollator.setStrength(Collator.SECONDARY); 19 } 20 21 27 28 public int compare(Object a, Object b) { 29 30 int diff = baseCollator.compare(a, b); 31 if (diff != 0) { 32 return diff; 33 } 34 char[] a1 = ((String )a).toCharArray(); 35 char[] b1 = ((String )b).toCharArray(); 36 int alen = a1.length; 37 int blen = b1.length; 38 int i = 0; 39 int j = 0; 40 41 while (true) { 42 if (i==alen) return 0; 43 diff = a1[i++] - b1[j++]; 44 if (diff!=0) { 45 return (Character.isLowerCase(a1[i-1]) ? -1 : +1); 46 } 47 } 48 49 } 50 51 } 52 53 | Popular Tags |