Skip to content

Commit

Permalink
Minor cleanup of some OSM classes
Browse files Browse the repository at this point in the history
  • Loading branch information
habrahamsson-skanetrafiken committed Oct 8, 2024
1 parent 8ffcc55 commit 1385e4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
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

0 comments on commit 1385e4d

Please sign in to comment.