diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapAddressReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapAddressReaderAdapter.java index 2f059d0552..32085f4d0d 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapAddressReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapAddressReaderAdapter.java @@ -271,9 +271,9 @@ public class BinaryMapAddressReaderAdapter { break; case OsmandOdb.CityIndex.ATTRIBUTEVALUES_FIELD_NUMBER: String nm = codedIS.readString(); - if(additionalTags != null && additionalTags.size() > 0) { + if (additionalTags != null && additionalTags.size() > 0) { String tg = additionalTags.pollFirst(); - if(tg.startsWith("name:")) { + if (tg.startsWith("name:")) { c.setName(tg.substring("name:".length()), nm); } } diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index 82e8234851..aaed7cd3a6 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -131,8 +131,6 @@ public class Amenity extends MapObject { public void setAdditionalInfo(String tag, String value) { if ("name".equals(tag)) { setName(value); - } else if ("name:en".equals(tag)) { - setEnName(value); } else if (tag.startsWith("name:")) { setName(tag.substring("name:".length()), value); } else { diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index 9daad4e2e7..007f9fc4c8 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -22,6 +22,10 @@ public abstract class MapObject implements Comparable { protected String name = null; protected String enName = null; + /** + * Looks like: {ru=Москва, dz=མོསི་ཀོ...} and does not contain values of OSM tags "name" and "name:en", + * see {@link name} and {@link enName} respectively. + */ protected Map names = null; protected LatLon location = null; protected int fileOffset = 0; @@ -40,8 +44,8 @@ public abstract class MapObject implements Comparable { } public String getName() { - if (this.name != null) { - return this.name; + if (name != null) { + return name; } return ""; //$NON-NLS-1$ } @@ -51,11 +55,16 @@ public abstract class MapObject implements Comparable { } public void setName(String lang, String name) { - if (names == null) { - names = new HashMap(); - + if (Algorithms.isEmpty(lang)) { + setName(name); + } else if (lang.equals("en")) { + setEnName(name); + } else { + if (names == null) { + names = new HashMap(); + } + names.put(lang, name); } - names.put(lang, name); } public Map getNamesMap(boolean includeEn) { @@ -84,37 +93,45 @@ public abstract class MapObject implements Comparable { return l; } - public void copyNames(MapObject s) { - if (Algorithms.isEmpty(name)) { - name = s.name; + public void copyNames(String otherName, String otherEnName, Map otherNames, boolean overwrite) { + if (!Algorithms.isEmpty(otherName) && (overwrite || Algorithms.isEmpty(name))) { + name = otherName; } - if (Algorithms.isEmpty(enName)) { - enName = s.enName; + if (!Algorithms.isEmpty(otherEnName) && (overwrite || Algorithms.isEmpty(enName))) { + enName = otherEnName; + } + if (!Algorithms.isEmpty(otherNames)) { + if (otherNames.containsKey("name:en")) { + enName = otherNames.get("name:en"); + } else if (otherNames.containsKey("en")) { + enName = otherNames.get("en"); + } + + for (Entry e : otherNames.entrySet()) { + String key = e.getKey(); + if (key.startsWith("name:")) { + key = key.substring("name:".length()); + } + if (names == null) { + names = new HashMap(); + } + if (overwrite || Algorithms.isEmpty(names.get(key))) { + names.put(key, e.getValue()); + } + } } - copyNames(s.names); } - public void copyNames(Map snames) { - if (Algorithms.isEmpty(snames)) { - return; - } - if (snames.containsKey("name:en")) { - enName = snames.get("name:en"); - } else if (snames.containsKey("en")) { - enName = snames.get("en"); - } - for (Entry e : snames.entrySet()) { - String key = e.getKey(); - if (key.startsWith("name:")) { - key = key.substring("name:".length()); - } - if (names == null) { - names = new HashMap(); - } - if (Algorithms.isEmpty(names.get(key))) { - names.put(key, e.getValue()); - } - } + public void copyNames(String otherName, String otherEnName, Map otherNames) { + copyNames(otherName, otherEnName, otherNames, false); + } + + public void copyNames(MapObject s, boolean copyName, boolean copyEnName, boolean overwrite) { + copyNames((copyName ? s.name : null), (copyEnName ? s.enName : null), s.names, overwrite); + } + + public void copyNames(MapObject s) { + copyNames(s, true, true, false); } public String getName(String lang) { diff --git a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java index f6f30ccdbe..476ccd2093 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/Entity.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/Entity.java @@ -172,7 +172,17 @@ public abstract class Entity implements Serializable { } return tags.get(key); } - + + public Map getNameTags() { + Map result = new LinkedHashMap(); + for (Map.Entry e : tags.entrySet()) { + if (e.getKey().startsWith("name:")) { + result.put(e.getKey(), e.getValue()); + } + } + return result; + } + public int getVersion() { return version; } @@ -274,4 +284,5 @@ public abstract class Entity implements Serializable { } return tags; } + } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index d9759463a9..e39a5b8f99 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -31,8 +31,8 @@ public class EntityParser { if (mo.getEnName(false).length() == 0) { mo.setEnName(tags.get(OSMTagKey.NAME_EN.getValue())); } - for(String ts : tags.keySet()) { - if(ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) { + for (String ts : tags.keySet()) { + if (ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) { mo.setName(ts.substring(("name:").length()), tags.get(ts)); } }