X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/6def2d6fe8efb00053b750a69610c41ac4581c2e..c7a3b092ceb08ad2f74d66d660cf82244c328311:/src/third_parties/daveKoeller/AlphanumComparator.java diff --git a/src/third_parties/daveKoeller/AlphanumComparator.java b/src/third_parties/daveKoeller/AlphanumComparator.java index d0879576..03244930 100644 --- a/src/third_parties/daveKoeller/AlphanumComparator.java +++ b/src/third_parties/daveKoeller/AlphanumComparator.java @@ -23,6 +23,7 @@ */ package third_parties.daveKoeller; +import java.text.Collator; import java.io.File; import java.util.Comparator; @@ -49,14 +50,12 @@ public class AlphanumComparator implements Comparator } /** Length of string is passed in for improved efficiency (only need to calculate it once) **/ - private final String getChunk(String s, int slength, int marker) - { + private final String getChunk(String s, int slength, int marker){ StringBuilder chunk = new StringBuilder(); char c = s.charAt(marker); chunk.append(c); marker++; - if (isDigit(c)) - { + if (isDigit(c)){ while (marker < slength) { c = s.charAt(marker); @@ -65,8 +64,7 @@ public class AlphanumComparator implements Comparator chunk.append(c); marker++; } - } else - { + } else { while (marker < slength) { c = s.charAt(marker); @@ -99,8 +97,7 @@ public class AlphanumComparator implements Comparator int s1Length = s1.length(); int s2Length = s2.length(); - while (thisMarker < s1Length && thatMarker < s2Length) - { + while (thisMarker < s1Length && thatMarker < s2Length) { String thisChunk = getChunk(s1, s1Length, thisMarker); thisMarker += thisChunk.length(); @@ -109,26 +106,23 @@ public class AlphanumComparator implements Comparator // If both chunks contain numeric characters, sort them numerically int result = 0; - if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) - { + if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) { // Simple chunk comparison by length. int thisChunkLength = thisChunk.length(); result = thisChunkLength - thatChunk.length(); // If equal, the first different number counts - if (result == 0) - { - for (int i = 0; i < thisChunkLength; i++) - { + if (result == 0) { + for (int i = 0; i < thisChunkLength; i++) { result = thisChunk.charAt(i) - thatChunk.charAt(i); - if (result != 0) - { + if (result != 0) { return result; } } } - } else - { - result = thisChunk.compareTo(thatChunk); + } else { + Collator collator = Collator.getInstance(); + collator.setStrength(Collator.PRIMARY); + result = collator.compare(thisChunk, thatChunk); } if (result != 0)