Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup of some OSM classes #6129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public boolean isOneOfTags(String key, Set<String> oneOfTags) {
* Returns a name-like value for an entity (if one exists). The otp: namespaced tags are created
* by {@link OsmModule}
*/
@Nullable
public I18NString getAssumedName() {
if (tags == null) {
return null;
Expand Down Expand Up @@ -273,10 +274,6 @@ public I18NString getAssumedName() {
* other language found in OSM tag.
*/
public Map<String, String> generateI18NForPattern(String pattern) {
if (pattern == null) {
return null;
}

Map<String, StringBuffer> i18n = new HashMap<>();
i18n.put(null, new StringBuffer());
Matcher matcher = Pattern.compile("\\{(.*?)}").matcher(pattern);
Expand All @@ -290,17 +287,15 @@ public Map<String, String> generateI18NForPattern(String pattern) {
String defKey = matcher.group(1);
// scan all translated tags
Map<String, String> i18nTags = getTagsByPrefix(defKey);
if (i18nTags != null) {
for (Map.Entry<String, String> kv : i18nTags.entrySet()) {
if (!kv.getKey().equals(defKey)) {
String lang = kv.getKey().substring(defKey.length() + 1);
if (!i18n.containsKey(lang)) i18n.put(lang, new StringBuffer(i18n.get(null)));
}
for (Map.Entry<String, String> kv : i18nTags.entrySet()) {
if (!kv.getKey().equals(defKey)) {
String lang = kv.getKey().substring(defKey.length() + 1);
if (!i18n.containsKey(lang)) i18n.put(lang, new StringBuffer(i18n.get(null)));
}
}
// get the simple value (eg: description=...)
String defTag = getTag(defKey);
if (defTag == null && i18nTags != null && i18nTags.size() != 0) {
if (defTag == null && !i18nTags.isEmpty()) {
defTag = i18nTags.values().iterator().next();
}
// get the translated value, if exists
Expand All @@ -318,17 +313,14 @@ public Map<String, String> generateI18NForPattern(String pattern) {
return out;
}

public Map<String, String> getTagsByPrefix(String prefix) {
private Map<String, String> getTagsByPrefix(String prefix) {
Map<String, String> out = new HashMap<>();
for (Map.Entry<String, String> entry : tags.entrySet()) {
String k = entry.getKey();
if (k.equals(prefix) || k.startsWith(prefix + ":")) {
out.put(k, entry.getValue());
}
}
if (out.isEmpty()) {
return null;
}

return out;
}
Expand Down Expand Up @@ -502,6 +494,7 @@ public void setCreativeName(I18NString creativeName) {
this.creativeName = creativeName;
}

@Nullable
public String url() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class NoteProperties {

private static final Pattern patternMatcher = Pattern.compile("\\{(.*?)}");

public String notePattern;
private final String notePattern;

public StreetNoteMatcher noteMatcher;
private final StreetNoteMatcher noteMatcher;

public NoteProperties(String notePattern, StreetNoteMatcher noteMatcher) {
this.notePattern = notePattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ void testGenerateI18NForPattern() {
osmTags.addTag("wheelchair:description", "Wheelchair description EN");
osmTags.addTag("wheelchair:description:fr", "Wheelchair description FR");

assertNull(osmTags.generateI18NForPattern(null));
Map<String, String> expected = new HashMap<>();

expected.put(null, "");
Expand Down
Loading