1 16 package scriptella.util; 17 18 import java.util.Comparator ; 19 import java.util.Map ; 20 import java.util.Properties ; 21 import java.util.TreeMap ; 22 23 29 public final class CollectionUtils { 30 private CollectionUtils() { } 32 33 37 private static final Comparator <String > ASCII_CASE_INSENSITIVE_ORDER = new Comparator <String >() { 38 public int compare(String s1, String s2) { 39 int n1=s1.length(), n2=s2.length(); 40 int n=n1<n2?n1:n2; 41 for (int i=0; i<n; i++) { 42 char c1 = s1.charAt(i); 43 char c2 = s2.charAt(i); 44 if (c1 != c2) { 45 if (c1>='A' && c1<='Z') { c1=(char)(c1|0x20); 47 } 48 if (c2>='A' && c2<='Z') { 49 c2=(char)(c2|0x20); 50 } 51 if (c1 != c2) { 52 return c1 - c2; 53 } 54 } 55 } 56 return n1 - n2; 57 } 58 }; 59 60 66 public static <V> Map <String , V> newCaseInsensitiveAsciiMap() { 67 return new TreeMap <String , V>(ASCII_CASE_INSENSITIVE_ORDER); 68 } 69 70 75 @SuppressWarnings ("unchecked") 76 public static Map <String ,String > asMap(Properties properties) { 77 return (Map )properties; 78 } 79 } 80 | Popular Tags |