Skip to content

Commit 8fa41fe

Browse files
committed
add property to Feature: isSuggestion
1 parent 2ae6ce1 commit 8fa41fe

File tree

9 files changed

+23
-5
lines changed

9 files changed

+23
-5
lines changed

library/src/main/java/de/westnordost/osmfeatures/BaseFeature.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class BaseFeature implements Feature
2222
private final double matchScore;
2323
private final Map<String,String> addTags;
2424
private final Map<String,String> removeTags;
25+
private final boolean isSuggestion;
2526

2627
private final List<String> canonicalNames;
2728
private final List<String> canonicalTerms;
@@ -30,7 +31,7 @@ public BaseFeature(
3031
String id, Map<String, String> tags, List<GeometryType> geometry,
3132
String icon, String imageURL, List<String> names, List<String> terms,
3233
List<String> includeCountryCodes, List<String> excludeCountryCodes,
33-
boolean searchable, double matchScore,
34+
boolean searchable, double matchScore, boolean isSuggestion,
3435
Map<String, String> addTags, Map<String, String> removeTags)
3536
{
3637
this.id = id;
@@ -44,6 +45,7 @@ public BaseFeature(
4445
this.excludeCountryCodes = excludeCountryCodes;
4546
this.searchable = searchable;
4647
this.matchScore = matchScore;
48+
this.isSuggestion = isSuggestion;
4749
this.addTags = addTags;
4850
this.removeTags = removeTags;
4951

@@ -78,6 +80,7 @@ public BaseFeature(
7880
@Override public Map<String, String> getRemoveTags() { return removeTags; }
7981
@Override public List<String> getCanonicalNames() { return canonicalNames; }
8082
@Override public List<String> getCanonicalTerms() { return canonicalTerms; }
83+
@Override public boolean isSuggestion() { return isSuggestion; }
8184
@Override public Locale getLocale() { return null; }
8285

8386
@Override public String toString() { return getId(); }

library/src/main/java/de/westnordost/osmfeatures/Feature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface Feature {
2525
Map<String,String> getRemoveTags();
2626
List<String> getCanonicalNames();
2727
List<String> getCanonicalTerms();
28+
boolean isSuggestion();
2829

2930
Locale getLocale();
3031
}

library/src/main/java/de/westnordost/osmfeatures/IDBrandPresetsFeatureCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private List<BaseFeature> loadFeatures(String countryCode) {
6969
try {
7070
if (!fileAccess.exists(filename)) return Collections.emptyList();
7171
try (InputStream is = fileAccess.open(filename)) {
72-
return new IDPresetsJsonParser().parse(is);
72+
return new IDPresetsJsonParser(true).parse(is);
7373
}
7474
}
7575
catch (IOException | JSONException e) {

library/src/main/java/de/westnordost/osmfeatures/IDPresetsJsonParser.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
* into map of id -> Feature. */
2323
class IDPresetsJsonParser {
2424

25+
private boolean isSuggestions = false;
26+
27+
public IDPresetsJsonParser() {}
28+
29+
public IDPresetsJsonParser(boolean isSuggestions)
30+
{
31+
this.isSuggestions = isSuggestions;
32+
}
33+
2534
public List<BaseFeature> parse(InputStream is) throws JSONException, IOException
2635
{
2736
JSONObject object = createFromInputStream(is);
@@ -83,7 +92,7 @@ private BaseFeature parseFeature(String id, JSONObject p)
8392
Collections.unmodifiableList(terms),
8493
Collections.unmodifiableList(includeCountryCodes),
8594
Collections.unmodifiableList(excludeCountryCodes),
86-
searchable, matchScore,
95+
searchable, matchScore, isSuggestions,
8796
Collections.unmodifiableMap(addTags),
8897
Collections.unmodifiableMap(removeTags)
8998
);

library/src/main/java/de/westnordost/osmfeatures/LocalizedFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public LocalizedFeature(BaseFeature p, Locale locale, List<String> names, List<S
5656
@Override public Map<String, String> getRemoveTags() { return p.getRemoveTags(); }
5757
@Override public List<String> getCanonicalNames() { return canonicalNames; }
5858
@Override public List<String> getCanonicalTerms() { return canonicalTerms; }
59+
@Override public boolean isSuggestion() { return p.isSuggestion(); }
5960
@Override public Locale getLocale() { return locale; }
6061

6162
@Override public String toString() { return getId(); }

library/src/test/java/de/westnordost/osmfeatures/FeatureDictionaryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ excludeCountryCodes, searchable, matchScore, addTags, mapOf()
662662
} else {
663663
BaseFeature f = new BaseFeature(
664664
id, tags, POINT, null, null, names, terms, countryCodes,
665-
excludeCountryCodes, searchable, matchScore, addTags, mapOf()
665+
excludeCountryCodes, searchable, matchScore, false, addTags, mapOf()
666666
);
667667
if (locale != null) {
668668
return new LocalizedFeature(f, locale, f.getNames(), f.getTerms());
@@ -688,7 +688,7 @@ public SuggestionFeature(
688688
Map<String, String> addTags,
689689
Map<String, String> removeTags
690690
) {
691-
super(id, tags, geometry, icon, imageURL, names, terms, includeCountryCodes, excludeCountryCodes, searchable, matchScore, addTags, removeTags);
691+
super(id, tags, geometry, icon, imageURL, names, terms, includeCountryCodes, excludeCountryCodes, searchable, matchScore, true, addTags, removeTags);
692692
}
693693
}
694694
}

library/src/test/java/de/westnordost/osmfeatures/FeatureTagsIndexTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private static Feature feature(MapEntry... mapEntries)
5656
listOf(),
5757
true,
5858
1.0,
59+
false,
5960
mapOf(),
6061
mapOf()
6162
);

library/src/test/java/de/westnordost/osmfeatures/FeatureTermIndexTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private static Feature feature(String... terms)
8080
listOf(),
8181
true,
8282
1.0,
83+
false,
8384
mapOf(),
8485
mapOf()
8586
);

library/src/test/java/de/westnordost/osmfeatures/IDBrandPresetsFeatureCollectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.westnordost.osmfeatures;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
45
import static de.westnordost.osmfeatures.TestUtils.assertEqualsIgnoreOrder;
56
import static de.westnordost.osmfeatures.TestUtils.listOf;
67

@@ -53,6 +54,7 @@ public class IDBrandPresetsFeatureCollectionTest {
5354

5455
assertEqualsIgnoreOrder(listOf("Talespin"), getNames(c.getAll(listOf("DE"))));
5556
assertEquals("Talespin", c.get("yet_another/brand", listOf("DE")).getName());
57+
assertTrue(c.get("yet_another/brand", listOf("DE")).isSuggestion());
5658
}
5759

5860
private InputStream getStream(String file)

0 commit comments

Comments
 (0)