Skip to content

Commit

Permalink
Update order to initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
vshcherb committed Jul 28, 2015
1 parent 3eb12ee commit 55dc79e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
60 changes: 32 additions & 28 deletions OsmAnd-java/src/net/osmand/util/Algorithms.java
Expand Up @@ -44,41 +44,45 @@ 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()));
}


});
Arrays.sort(listFiles, getFileVersionComparator());
}
return listFiles;
}

public static Comparator<File> getFileVersionComparator() {
return new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return -simplifyFileName(o1.getName()).compareTo(simplifyFileName(o2.getName()));
}

public String simplifyFileName(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;
}
};
}

private static final char CHAR_TOSPLIT = 0x01;

Expand Down
12 changes: 8 additions & 4 deletions OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java
Expand Up @@ -14,6 +14,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -39,7 +40,6 @@
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class MapRenderRepositories {
private final static int zoomOnlyForBasemaps = 11;
static int zoomForBaseRouteRendering = 14;
private Handler handler;
private Map<String, BinaryMapIndexReader> files = new ConcurrentHashMap<String, BinaryMapIndexReader>();
private Map<String, BinaryMapIndexReader> files = new LinkedHashMap<String, BinaryMapIndexReader>();
private Set<String> nativeFiles = new HashSet<String>();
private OsmandRenderer renderer;

Expand Down Expand Up @@ -131,7 +131,9 @@ public void initializeNewResource(final IProgress progress, File file, BinaryMap
closeConnection(files.get(file.getAbsolutePath()), file.getAbsolutePath());

}
files.put(file.getAbsolutePath(), reader);
LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files);
cpfiles.put(file.getAbsolutePath(), reader);
files = cpfiles;
}

public RotatedTileBox getBitmapLocation() {
Expand All @@ -143,7 +145,9 @@ public RotatedTileBox getPrevBmpLocation() {
}

protected void closeConnection(BinaryMapIndexReader c, String file) {
files.remove(file);
LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files);
cpfiles.remove(file);
files = cpfiles;
if(nativeFiles.contains(file)){
NativeOsmandLibrary lib = NativeOsmandLibrary.getLoadedLibrary();
if(lib != null) {
Expand Down
2 changes: 2 additions & 0 deletions OsmAnd/src/net/osmand/plus/resources/ResourceManager.java
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -601,6 +602,7 @@ public List<String> indexingMaps(final IProgress progress) {
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
}
Collections.sort(files, Algorithms.getFileVersionComparator());
List<String> warnings = new ArrayList<String>();
renderer.clearAllResources();
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
Expand Down

0 comments on commit 55dc79e

Please sign in to comment.