Simplify processOdvNameElem()

This commit is contained in:
Andreas Schildbach 2013-09-02 12:44:49 +02:00
parent 7e5ca005ae
commit 5b098e1268

View file

@ -765,15 +765,20 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final String stopIdStr = pp.getAttributeValue(null, "stopID"); final String stopIdStr = pp.getAttributeValue(null, "stopID");
final String poiIdStr = pp.getAttributeValue(null, "poiID"); final String poiIdStr = pp.getAttributeValue(null, "poiID");
final String streetIdStr = pp.getAttributeValue(null, "streetID"); final String streetIdStr = pp.getAttributeValue(null, "streetID");
final String place = !"loc".equals(anyType) ? normalizeLocationName(pp.getAttributeValue(null, "locality")) : null; final String locality = normalizeLocationName(pp.getAttributeValue(null, "locality"));
final String name = normalizeLocationName(pp.getAttributeValue(null, "objectName")); final String objectName = normalizeLocationName(pp.getAttributeValue(null, "objectName"));
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null); final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0); final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0); final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
XmlPullUtil.enter(pp, "odvNameElem");
final String elemName = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvNameElem");
final int lat; final int lat;
final int lon; final int lon;
if (mapName == null || (x == 0 && y == 0)) if (mapName == null || (x == 0 && y == 0))
{ {
lat = 0; lat = 0;
@ -791,26 +796,44 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final LocationType type; final LocationType type;
final int id; final int id;
final String place;
final String name;
if ("stop".equals(anyType)) if ("stop".equals(anyType))
{ {
type = LocationType.STATION; type = LocationType.STATION;
id = Integer.parseInt(idStr); id = Integer.parseInt(idStr);
place = locality;
name = objectName;
} }
else if ("poi".equals(anyType) || "poiHierarchy".equals(anyType)) else if ("poi".equals(anyType) || "poiHierarchy".equals(anyType))
{ {
type = LocationType.POI; type = LocationType.POI;
id = Integer.parseInt(idStr); id = Integer.parseInt(idStr);
place = locality;
name = objectName;
} }
else if ("loc".equals(anyType)) else if ("loc".equals(anyType))
{ {
type = LocationType.ANY; type = LocationType.ANY;
id = 0; id = 0;
place = locality;
name = locality;
} }
else if ("postcode".equals(anyType) || "street".equals(anyType) || "crossing".equals(anyType) || "address".equals(anyType) else if ("address".equals(anyType))
|| "singlehouse".equals(anyType) || "buildingname".equals(anyType))
{ {
type = LocationType.ADDRESS; type = LocationType.ADDRESS;
id = 0; id = 0;
place = locality;
name = objectName;
}
else if ("postcode".equals(anyType) || "street".equals(anyType) || "crossing".equals(anyType) || "singlehouse".equals(anyType)
|| "buildingname".equals(anyType))
{
type = LocationType.ADDRESS;
id = 0;
place = locality;
name = objectName;
} }
else if (anyType == null || "unknown".equals(anyType)) else if (anyType == null || "unknown".equals(anyType))
{ {
@ -838,17 +861,16 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
{ {
throw new IllegalArgumentException("cannot substitute type"); throw new IllegalArgumentException("cannot substitute type");
} }
place = locality;
name = objectName;
} }
else else
{ {
throw new IllegalArgumentException("unknown type: " + anyType); throw new IllegalArgumentException("unknown type: " + anyType);
} }
XmlPullUtil.enter(pp, "odvNameElem"); return new Location(type, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : elemName);
final String longName = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvNameElem");
return new Location(type, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : longName);
} }
private Location processItdOdvAssignedStop(final XmlPullParser pp) throws XmlPullParserException, IOException private Location processItdOdvAssignedStop(final XmlPullParser pp) throws XmlPullParserException, IOException