I make my special sort with the following code:
import java.util.Arrays;
import java.util.Comparator;
public class SpecialSort implements Comparator<String> {
private static final char[] knownChars = {'A', 'Ä', 'a', 'ä', 'á', 'à', 'â', 'å', 'ã', //
'B', 'b', 'в',//
'C', 'Ç', 'c', 'ç',//
'D', 'd',//
'E', 'É', 'e', 'ë', 'é', 'è', 'ê',//
'F', 'f',//
'G', 'g',//
'H', 'h',//
'I', 'i', 'ï', 'î', 'í', 'ì',//
'J', 'j',//
'K', 'k',//
'L', 'l',//
'M', 'm',//
'N', 'n', 'ñ',//
'O', 'Ö', 'Ó', 'Ò', 'o', 'о', 'ö', 'ó', 'ò', 'ô',//
'P', 'p', 'р', 'π',//
'Q', 'q',//
'R', 'r',//
'S', 's', 'ß', 'β',//
'T', 't', 'т',//
'U', 'Ü', 'u', 'ü', 'ú', 'ù', 'û',//
'V', 'v',//
'W', 'w',//
'X', 'x',//
'Y', 'y', 'ÿ',//
'Z', 'z',//
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',//
' ', ',', '+', '-', '–', '*', '_', '#', '´',//
'½', '¼', '@', '¹', '²', '>', '<', '’', '“', '„', '³',//
'\'', '`', '"', '§', '○',//
'?', '!', '\t', ((char) 10), '♕', '/', '\\',//
'.', '·', ':', ';', '=', '&', '¶',//
'(', ')', '[', ']',//
' ', '%', '»', '«', '®', '€', '£', 'ø',//
'°', 'и', 'щ', '瘐', 'ɸ'//
};
private static final int[] mapping = new int[0x10000];
public static boolean simpleSort = true;// if false compare deliver the special sort else normal sort using string.compareTo(otherString)
public static boolean firstLetterIgnoreUpperCase = false;// if true first Letter uppercase will ignored.
private static int lastGoodChar;
static {
Arrays.fill(mapping, Integer.MAX_VALUE);
for (int i = 0; i < knownChars.length; i++) {
if (knownChars[i] == ' ') {
lastGoodChar = i;
}
mapping[knownChars[i]] = i;
}
}
public static int staticCompare(@NonNull String one, @NonNull String two) {
if (simpleSort)
return one.compareTo(two);
char[] chars1 = one.toCharArray();
char[] chars2 = two.toCharArray();
if (firstLetterIgnoreUpperCase) {
if (chars1.length > 0)
chars1[0] = ("" + chars1[0]).toLowerCase().charAt(0);
if (chars2.length > 0)
chars2[0] = ("" + chars2[0]).toLowerCase().charAt(0);
}
int[] ref1 = new int[1];
int[] ref2 = new int[1];
do {
int c1 = getCharValue(chars1, ref1);
int c2 = getCharValue(chars2, ref2);
if (c1 != c2)
return c1 - c2;
} while ((ref1[0] < chars1.length) && (ref2[0] < chars2.length));
if (ref1[0] < chars1.length)
return Integer.MAX_VALUE;
return Integer.MIN_VALUE;
}
private static int getCharValue(@NonNull char[] all, @NonNull int[] index) {
if (index[0] == all.length) return 0;
int ord = mapping[all[index[0]++]];
if (ord < lastGoodChar)
return ord;
return getCharValue(all, index);
}
public int compare(@NonNull String one, @NonNull String two) {
return staticCompare(one, two);
}
}