Fixed NumberFormatException when creating maps.

This commit is contained in:
Pavol Zibrita 2011-09-05 22:49:42 +02:00
parent 06ff0a29ae
commit db74682557
3 changed files with 17 additions and 5 deletions

View file

@ -49,8 +49,8 @@ import org.apache.commons.logging.LogFactory;
public class IndexAddressCreator extends AbstractIndexPartCreator{
private static final Log log = LogFactory.getLog(IndexAddressCreator.class);
private PreparedStatement addressCityStat;
private PreparedStatement addressStreetStat;
private PreparedStatement addressBuildingStat;
@ -611,7 +611,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
private String findCityPart(City city, LatLon location) {
final Boundary cityBoundary = cityBoundaries.get(city);
int greatestBoudnaryLevel = Integer.parseInt(cityAdminLevel);
int greatestBoudnaryLevel = getParsedCityAdminLevel();
Boundary greatestBoundary = cityBoundary;
if (cityBoundary != null) {
for (Boundary subB : allSubBoundaries(cityBoundary)) {
@ -624,6 +624,15 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
return greatestBoundary != cityBoundary ? findNearestCityOrSuburb(greatestBoundary, location) : city.getName();
}
private int getParsedCityAdminLevel() {
try {
return Integer.parseInt(cityAdminLevel);
} catch (NumberFormatException ex) {
return IndexCreator.DEFAULT_CITY_ADMIN_LEVEL;
}
}
private String findNearestCityOrSuburb(Boundary greatestBoundary,
LatLon location) {
String result = greatestBoundary.getName();

View file

@ -95,7 +95,9 @@ public class IndexCreator {
private File mapFile;
private RandomAccessFile mapRAFile;
private Connection mapConnection;
private String cityAdminLevel = "8";
public static final int DEFAULT_CITY_ADMIN_LEVEL = 8;
private String cityAdminLevel = "" + DEFAULT_CITY_ADMIN_LEVEL;
public IndexCreator(File workingDir) {

View file

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.prefs.Preferences;
import net.osmand.data.preparation.IndexCreator;
import net.osmand.data.preparation.MapZooms;
import net.osmand.osm.LatLon;
@ -164,7 +165,7 @@ public class DataExtractionSettings {
}
public String getCityAdminLevel(){
return preferences.get("cityAdminLevel", "8");
return preferences.get("cityAdminLevel", "" + IndexCreator.DEFAULT_CITY_ADMIN_LEVEL);
}
public void setCityAdminLevel(String s){