1 package net.sf.saxon.sort; 2 import java.io.Serializable ; 3 import java.util.Comparator ; 4 5 6 9 10 11 16 public class CodepointCollator implements Comparator , Serializable { 17 18 private static CodepointCollator theInstance = new CodepointCollator(); 19 20 public static CodepointCollator getInstance() { 21 return theInstance; 22 } 23 24 29 30 public int compare(Object a, Object b) { 31 return ((String )a).compareTo((String )b); 32 } 33 34 40 41 public int compareCS(CharSequence a, CharSequence b) { 42 int alen = a.length(); 43 int blen = b.length(); 44 int i = 0; 45 int j = 0; 46 while (true) { 47 if (i == alen) { 48 if (j == blen) { 49 return 0; 50 } else { 51 return -1; 52 } 53 } 54 if (j == blen) { 55 return +1; 56 } 57 int c = (int)a.charAt(i++) - (int)b.charAt(j++); 58 if (c != 0) { 59 return c; 60 } 61 } 62 } 63 64 } 65 66 67 | Popular Tags |