Skip to content

Commit

Permalink
Add method
Browse files Browse the repository at this point in the history
  • Loading branch information
vshcherb committed Jul 27, 2015
1 parent 34e8d9b commit 3eb12ee
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions OsmAnd-java/src/net/osmand/util/Algorithms.java
Expand Up @@ -9,7 +9,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -42,6 +44,42 @@ public static long parseLongSilently(String input, long def) {
return def;
}

private static String simplifyName(String fn) {
String lc = fn.toLowerCase();
if (lc.indexOf(".") != -1) {
lc = lc.substring(0, lc.indexOf("."));
}
if (lc.endsWith("_2")) {
lc = lc.substring(0, lc.length() - "_2".length());
}
boolean hasTimestampEnd = false;
for(int i = 0; i < lc.length(); i++) {
if(lc.charAt(i) >= '0' && lc.charAt(i) <= '9') {
hasTimestampEnd = true;
break;
}
}
if(!hasTimestampEnd) {
lc += "_00_00_00";
}
return lc;
}

public static File[] getSortedFilesVersions(File dir){
File[] listFiles = dir.listFiles();
if (listFiles != null) {
Arrays.sort(listFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return -simplifyName(o1.getName()).compareTo(simplifyName(o2.getName()));
}


});
}
return listFiles;
}

private static final char CHAR_TOSPLIT = 0x01;

public static Map<String, String> decodeMap(String s) {
Expand Down

0 comments on commit 3eb12ee

Please sign in to comment.