Sort world regions

This commit is contained in:
Alexey Kulish 2015-10-19 20:20:21 +03:00
parent 15305bb846
commit 48e34264e7

View file

@ -1,5 +1,7 @@
package net.osmand.plus;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@ -196,6 +198,14 @@ public class WorldRegion {
break;
}
Comparator<WorldRegion> nameComparator = new Comparator<WorldRegion>() {
@Override
public int compare(WorldRegion w1, WorldRegion w2) {
return w1.getName().compareTo(w2.getName());
}
};
sortSubregions(this, nameComparator);
if (loadedItems.size() > 0) {
LOG.warn("Found orphaned regions: " + loadedItems.size());
for (String regionId : loadedItems.keySet()) {
@ -204,6 +214,15 @@ public class WorldRegion {
}
}
private void sortSubregions(WorldRegion region, Comparator<WorldRegion> comparator) {
Collections.sort(region.subregions, comparator);
for (WorldRegion r : region.subregions) {
if (r.subregions.size() > 0) {
sortSubregions(r, comparator);
}
}
}
private static WorldRegion createRegionAs(String regionId, Map<String, String> loadedItems,
OsmandRegions osmandRegions, String localizedName) {
WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName);