From a05000dc9210f466161edd54761101198348e83a Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 30 Jun 2016 17:15:21 +0300 Subject: [PATCH] [Core sample] search refactoring in progress --- .../samples/android/sample1/MainActivity.java | 10 +- .../adapters/BuildingSearchListItem.java | 8 +- .../sample1/adapters/CitySearchListItem.java | 6 +- .../sample1/adapters/PoiSearchListItem.java | 12 +-- .../adapters/PostcodeSearchListItem.java | 6 +- .../adapters/SearchListPositionItem.java | 6 +- .../StreetIntersectionSearchListItem.java | 8 +- .../adapters/StreetSearchListItem.java | 8 +- .../adapters/VillageSearchListItem.java | 7 +- .../android/sample1/search/SearchAPI.java | 10 +- .../android/sample1/search/SearchScope.java | 28 +++--- .../android/sample1/search/SearchString.java | 94 +++++++++---------- .../search/objects/BuildingSearchObject.java | 12 +-- .../objects/CoordinatesSearchObject.java | 4 +- .../search/objects/PoiSearchObject.java | 12 +-- .../sample1/search/objects/PoiTypeObject.java | 25 ++++- .../search/objects/PoiTypeSearchObject.java | 18 ++-- .../sample1/search/objects/SearchObject.java | 12 +-- .../search/objects/SearchPositionObject.java | 6 +- .../objects/StreetGroupSearchObject.java | 12 +-- .../StreetIntersectionSearchObject.java | 12 +-- .../search/objects/StreetSearchObject.java | 12 +-- .../search/requests/CoreSearchRequest.java | 20 ++-- .../requests/IntermediateSearchRequest.java | 2 +- .../search/tokens/NameFilterToken.java | 2 +- .../sample1/search/tokens/ObjectToken.java | 11 ++- .../sample1/search/tokens/SearchToken.java | 23 ++--- 27 files changed, 190 insertions(+), 196 deletions(-) diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java index 3555248738..42721a1ab6 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java @@ -54,7 +54,7 @@ import net.osmand.core.samples.android.sample1.search.objects.PoiTypeSearchObjec import net.osmand.core.samples.android.sample1.search.objects.PoiTypeSearchObject.ObjectType; import net.osmand.core.samples.android.sample1.search.objects.SearchObject; import net.osmand.core.samples.android.sample1.search.objects.SearchObject.SearchObjectType; -import net.osmand.core.samples.android.sample1.search.tokens.ObjectSearchToken; +import net.osmand.core.samples.android.sample1.search.tokens.ObjectToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.PoiCategory; @@ -210,6 +210,7 @@ public class MainActivity extends Activity { res = poiTypesHelper.findPoiTypes(keyword); } + /* for (AbstractPoiType pt : res) { if (pt instanceof PoiCategory) { result.add(new PoiTypeSearchObject(ObjectType.CATEGORY, @@ -224,6 +225,7 @@ public class MainActivity extends Activity { poiType.getTranslation(), poiType.getKeyName(), poiType.getCategory().getKeyName())); } } + */ return result; } @@ -234,9 +236,9 @@ public class MainActivity extends Activity { processSearchResult(searchObjects); StringBuilder sb = new StringBuilder(); - Map objectTokensMap = searchAPI.getObjectTokens(); - ObjectSearchToken lastObjectToken = searchAPI.getLastObjectToken(); - for (SearchToken token : objectTokensMap.values()) { + Map objectTokensMap = searchAPI.getObjectTokens(); + ObjectToken lastObjectToken = searchAPI.getLastObjectToken(); + for (ObjectToken token : objectTokensMap.values()) { if (sb.length() > 0) { sb.append(" • "); } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/BuildingSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/BuildingSearchListItem.java index 148c6ecaee..d59954c8c3 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/BuildingSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/BuildingSearchListItem.java @@ -11,12 +11,12 @@ public class BuildingSearchListItem extends SearchListPositionItem { private String nameStr; private String typeStr; - public BuildingSearchListItem(SampleApplication app, BuildingSearchObject searchObject) { - super(app, searchObject); + public BuildingSearchListItem(SampleApplication app, BuildingSearchObject buildingObject) { + super(app, buildingObject); - nameStr = searchObject.getName(MapUtils.LANGUAGE); + nameStr = buildingObject.getName(MapUtils.LANGUAGE); - Building building = searchObject.getBuilding(); + Building building = buildingObject.getBaseObject(); Street street = building.getStreet(); if (street != null) { diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/CitySearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/CitySearchListItem.java index edbd00e849..46738bc4e9 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/CitySearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/CitySearchListItem.java @@ -9,10 +9,10 @@ public class CitySearchListItem extends SearchListPositionItem{ private String nameStr; private String typeStr; - public CitySearchListItem(SampleApplication app, CitySearchObject searchObject) { - super(app, searchObject); + public CitySearchListItem(SampleApplication app, CitySearchObject cityObject) { + super(app, cityObject); - nameStr = searchObject.getName(MapUtils.LANGUAGE); + nameStr = cityObject.getName(MapUtils.LANGUAGE); typeStr = "City"; } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PoiSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PoiSearchListItem.java index 3b1ce0b921..4400bef70d 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PoiSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PoiSearchListItem.java @@ -26,20 +26,20 @@ public class PoiSearchListItem extends SearchListPositionItem { private String nameStr; private String typeStr; - public PoiSearchListItem(SampleApplication app, PoiSearchObject searchObject) { - super(app, searchObject); - amenity = parseAmenity(searchObject); + public PoiSearchListItem(SampleApplication app, PoiSearchObject poiObject) { + super(app, poiObject); + amenity = parseAmenity(poiObject); nameStr = amenity.getName(MapUtils.LANGUAGE); typeStr = getTypeStr(); } - private Amenity parseAmenity(PoiSearchObject searchItem) { + private Amenity parseAmenity(PoiSearchObject poiObject) { String categoryName = ""; String subcategoryName = ""; Map values = new HashMap<>(); - net.osmand.core.jni.Amenity coreAmenity = searchItem.getAmenity(); + net.osmand.core.jni.Amenity coreAmenity = poiObject.getBaseObject(); DecodedCategoryList catList = coreAmenity.getDecodedCategories(); if (catList.size() > 0) { DecodedCategory decodedCategory = catList.get(0); @@ -63,7 +63,7 @@ public class PoiSearchListItem extends SearchListPositionItem { PoiCategory category = poiTypes.getPoiCategoryByName(categoryName); a.setType(category); a.setSubType(subcategoryName); - a.setName(searchItem.getNativeName()); + a.setName(poiObject.getNativeName()); QStringStringHash localizedNamesMap = coreAmenity.getLocalizedNames(); QStringList locNamesKeys = localizedNamesMap.keys(); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PostcodeSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PostcodeSearchListItem.java index 973e508d41..5ef9a99033 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PostcodeSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/PostcodeSearchListItem.java @@ -10,10 +10,10 @@ public class PostcodeSearchListItem extends SearchListPositionItem { private String nameStr; private String typeStr; - public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject searchObject) { - super(app, searchObject); + public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject postcodeObject) { + super(app, postcodeObject); - nameStr = searchObject.getNativeName(); + nameStr = postcodeObject.getNativeName(); typeStr = "Postcode"; } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListPositionItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListPositionItem.java index 00d12f4df6..5773a0934a 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListPositionItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListPositionItem.java @@ -11,9 +11,9 @@ public class SearchListPositionItem extends SearchListItem { private double latitude; private double longitude; - public SearchListPositionItem(SampleApplication app, SearchPositionObject searchObject) { - super(app, searchObject); - PointI position31 = searchObject.getPosition31(); + public SearchListPositionItem(SampleApplication app, SearchPositionObject positionObject) { + super(app, positionObject); + PointI position31 = positionObject.getPosition31(); LatLon latLon = Utilities.convert31ToLatLon(position31); latitude = latLon.getLatitude(); longitude = latLon.getLongitude(); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetIntersectionSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetIntersectionSearchListItem.java index 2ab6cbb85e..afd19fad0e 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetIntersectionSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetIntersectionSearchListItem.java @@ -11,12 +11,12 @@ public class StreetIntersectionSearchListItem extends SearchListPositionItem { private String nameStr; private String typeStr; - public StreetIntersectionSearchListItem(SampleApplication app, StreetIntersectionSearchObject searchObject) { - super(app, searchObject); + public StreetIntersectionSearchListItem(SampleApplication app, StreetIntersectionSearchObject intersectionObject) { + super(app, intersectionObject); - nameStr = searchObject.getName(MapUtils.LANGUAGE); + nameStr = intersectionObject.getName(MapUtils.LANGUAGE); - StreetIntersection streetIntersection = searchObject.getStreetIntersection(); + StreetIntersection streetIntersection = intersectionObject.getBaseObject(); Street street = streetIntersection.getStreet(); if (street != null) { diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetSearchListItem.java index cec23a1900..59170755a1 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/StreetSearchListItem.java @@ -10,12 +10,12 @@ public class StreetSearchListItem extends SearchListPositionItem { private String nameStr; private String typeStr; - public StreetSearchListItem(SampleApplication app, StreetSearchObject searchObject) { - super(app, searchObject); + public StreetSearchListItem(SampleApplication app, StreetSearchObject streetObject) { + super(app, streetObject); - nameStr = searchObject.getName(MapUtils.LANGUAGE); + nameStr = streetObject.getName(MapUtils.LANGUAGE); - StreetGroup streetGroup = searchObject.getStreet().getStreetGroup(); + StreetGroup streetGroup = streetObject.getBaseObject().getStreetGroup(); if (streetGroup != null) { typeStr = streetGroup.getNativeName() + " — " + getTypeStr(streetGroup); } else { diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/VillageSearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/VillageSearchListItem.java index a71dbb9891..ab866af2bc 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/VillageSearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/VillageSearchListItem.java @@ -2,7 +2,6 @@ package net.osmand.core.samples.android.sample1.adapters; import net.osmand.core.samples.android.sample1.MapUtils; import net.osmand.core.samples.android.sample1.SampleApplication; -import net.osmand.core.samples.android.sample1.search.objects.CitySearchObject; import net.osmand.core.samples.android.sample1.search.objects.VillageSearchObject; public class VillageSearchListItem extends SearchListPositionItem{ @@ -10,10 +9,10 @@ public class VillageSearchListItem extends SearchListPositionItem{ private String nameStr; private String typeStr; - public VillageSearchListItem(SampleApplication app, VillageSearchObject searchObject) { - super(app, searchObject); + public VillageSearchListItem(SampleApplication app, VillageSearchObject villageObject) { + super(app, villageObject); - nameStr = searchObject.getName(MapUtils.LANGUAGE); + nameStr = villageObject.getName(MapUtils.LANGUAGE); typeStr = "Village"; } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java index f65b1daa18..f5abf267a9 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java @@ -11,7 +11,7 @@ import net.osmand.core.samples.android.sample1.search.objects.SearchObject.Searc import net.osmand.core.samples.android.sample1.search.requests.CoreSearchRequest; import net.osmand.core.samples.android.sample1.search.requests.IntermediateSearchRequest; import net.osmand.core.samples.android.sample1.search.requests.SearchRequest; -import net.osmand.core.samples.android.sample1.search.tokens.ObjectSearchToken; +import net.osmand.core.samples.android.sample1.search.tokens.ObjectToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken; import java.util.ArrayList; @@ -115,11 +115,11 @@ public class SearchAPI { this.searchObjects = searchObjects; } - public Map getObjectTokens() { + public Map getObjectTokens() { return searchString.getCompleteObjectTokens(); } - public ObjectSearchToken getLastObjectToken() { + public ObjectToken getLastObjectToken() { return searchString.getLastObjectToken(); } @@ -127,7 +127,7 @@ public class SearchAPI { SearchApiCallback intermediateSearchCallback, SearchApiCallback coreSearchCallback) { - searchString.setQueryText(query); + searchString.setPlainText(query); startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback); } @@ -137,7 +137,7 @@ public class SearchAPI { searchString.completeQuery(searchObject); startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback); - return searchString.getQueryText(); + return searchString.getPlainText(); } private void startSearchInternal(int maxSearchResults, diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchScope.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchScope.java index 2ab2509c5b..bcaa72c88c 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchScope.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchScope.java @@ -19,7 +19,7 @@ import net.osmand.core.samples.android.sample1.search.objects.SearchObject.Searc import net.osmand.core.samples.android.sample1.search.objects.SearchPositionObject; import net.osmand.core.samples.android.sample1.search.objects.StreetGroupSearchObject; import net.osmand.core.samples.android.sample1.search.objects.StreetSearchObject; -import net.osmand.core.samples.android.sample1.search.tokens.ObjectSearchToken; +import net.osmand.core.samples.android.sample1.search.tokens.ObjectToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken; import java.util.Collections; @@ -33,7 +33,7 @@ public class SearchScope { private ObfsCollection obfsCollection; private SearchString searchString; private String lang; - private Map objectTokens; + private Map objectTokens; private PointI searchLocation31; private AreaI searchableArea; private AreaI obfAreaFilter; @@ -110,7 +110,7 @@ public class SearchScope { if (objectTokens.containsKey(SearchObjectType.STREET)) { StreetSearchObject streetSearchObject = (StreetSearchObject) objectTokens.get(SearchObjectType.STREET).getSearchObject(); - criteria.setAddressFilter(streetSearchObject.getStreet()); + criteria.setAddressFilter(streetSearchObject.getBaseObject()); if (objectTokens.containsKey(SearchObjectType.POSTCODE)) { PostcodeSearchObject postcodeSearchObject = (PostcodeSearchObject) objectTokens.get(SearchObjectType.POSTCODE).getSearchObject(); @@ -118,13 +118,13 @@ public class SearchScope { } } else if (objectTokens.containsKey(SearchObjectType.CITY)) { criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.CITY) - .getSearchObject()).getStreetGroup()); + .getSearchObject()).getBaseObject()); } else if (objectTokens.containsKey(SearchObjectType.VILLAGE)) { criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.VILLAGE) - .getSearchObject()).getStreetGroup()); + .getSearchObject()).getBaseObject()); } else if (objectTokens.containsKey(SearchObjectType.POSTCODE)) { criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.POSTCODE) - .getSearchObject()).getStreetGroup()); + .getSearchObject()).getBaseObject()); } } @@ -191,7 +191,7 @@ public class SearchScope { if (token.getType() == SearchToken.TokenType.NAME_FILTER && !token.hasEmptyQuery()) { boolean suggeston = token == searchString.getLastToken(); - newToken = new ObjectSearchToken(token, searchObjects.get(0), suggeston); + newToken = new ObjectToken(token, searchObjects.get(0), suggeston); searchString.replaceToken(token, newToken); } } @@ -220,22 +220,22 @@ public class SearchScope { case STREET: StreetSearchObject streetSearchObject = (StreetSearchObject) searchObject; - Street street = streetSearchObject.getStreet(); + Street street = streetSearchObject.getBaseObject(); if (!citySelected) { priority = getPriorityByDistance(9.0, streetSearchObject.getDistance()); } else { boolean streetFromSelectedCity = false; - for (SearchToken st : objectTokens.values()) { + for (ObjectToken st : objectTokens.values()) { if (st.getSearchObject() instanceof StreetGroupSearchObject) { StreetGroup streetGroup = - ((StreetGroupSearchObject) st.getSearchObject()).getStreetGroup(); + ((StreetGroupSearchObject) st.getSearchObject()).getBaseObject(); if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) { streetFromSelectedCity = true; break; } } else if (st.getSearchObject() instanceof StreetSearchObject) { StreetGroup streetGroup = - ((StreetSearchObject) st.getSearchObject()).getStreet().getStreetGroup(); + ((StreetSearchObject) st.getSearchObject()).getBaseObject().getStreetGroup(); if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) { streetFromSelectedCity = true; break; @@ -256,10 +256,10 @@ public class SearchScope { } private double getCityType(StreetGroupSearchObject searchObject) { - if (searchObject.getStreetGroup().getType() == ObfAddressStreetGroupType.CityOrTown) { - if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.City) { + if (searchObject.getBaseObject().getType() == ObfAddressStreetGroupType.CityOrTown) { + if (searchObject.getBaseObject().getSubtype() == ObfAddressStreetGroupSubtype.City) { return 1.0; - } else if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.Town) { + } else if (searchObject.getBaseObject().getSubtype() == ObfAddressStreetGroupSubtype.Town) { return 1.5; } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchString.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchString.java index f533ff89b2..dbd055554e 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchString.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchString.java @@ -5,8 +5,8 @@ import android.support.annotation.NonNull; import net.osmand.core.samples.android.sample1.MapUtils; import net.osmand.core.samples.android.sample1.search.objects.SearchObject; import net.osmand.core.samples.android.sample1.search.objects.SearchObject.SearchObjectType; -import net.osmand.core.samples.android.sample1.search.tokens.NameFilterSearchToken; -import net.osmand.core.samples.android.sample1.search.tokens.ObjectSearchToken; +import net.osmand.core.samples.android.sample1.search.tokens.NameFilterToken; +import net.osmand.core.samples.android.sample1.search.tokens.ObjectToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken.TokenType; import net.osmand.util.Algorithms; @@ -18,7 +18,7 @@ import java.util.Map; public class SearchString { - private String queryText = ""; + private String plainText = ""; private List tokens = new ArrayList<>(); private String lang; @@ -28,21 +28,21 @@ public class SearchString { public SearchString copy() { SearchString res = new SearchString(lang); - res.queryText = queryText; + res.plainText = plainText; res.tokens = new ArrayList<>(tokens); return res; } - public String getQueryText() { - return queryText; + public String getPlainText() { + return plainText; } - public void setQueryText(String queryText) { - int newTextLength = queryText.length(); - int currTextLength = this.queryText.length(); + public void setPlainText(String plainText) { + int newTextLength = plainText.length(); + int currTextLength = this.plainText.length(); boolean isNewText = currTextLength == 0 || newTextLength == 0 - || !this.queryText.regionMatches(0, queryText, 0, + || !this.plainText.regionMatches(0, plainText, 0, newTextLength > currTextLength ? currTextLength : newTextLength); int lastKnownTokenIndex = -1; @@ -55,7 +55,7 @@ public class SearchString { int lastTokenIndex = token.getLastIndex(); if (lastTokenIndex > newTextLength - 1 || token.hasEmptyQuery() - || (lastTokenIndex < newTextLength - 1 && !startWithDelimiter(queryText.substring(lastTokenIndex + 1)))) { + || (lastTokenIndex < newTextLength - 1 && !startWithDelimiter(plainText.substring(lastTokenIndex + 1)))) { brokenTokenIndex = i; break; } @@ -76,53 +76,53 @@ public class SearchString { if (newTextLength - 1 > lastKnownTokenIndex) { int firstWordIndex = lastKnownTokenIndex + 1; for (int i = lastKnownTokenIndex + 1; i < newTextLength; i++) { - char c = queryText.charAt(i); + char c = plainText.charAt(i); if (isDelimiterChar(c)) { if (i == firstWordIndex) { firstWordIndex++; } else { - SearchToken token = new NameFilterSearchToken(firstWordIndex, queryText.substring(firstWordIndex, i)); + SearchToken token = new NameFilterToken(firstWordIndex, plainText.substring(firstWordIndex, i)); tokens.add(token); firstWordIndex = i + 1; } } } if (firstWordIndex <= newTextLength - 1) { - SearchToken token = new NameFilterSearchToken(firstWordIndex, queryText.substring(firstWordIndex)); + SearchToken token = new NameFilterToken(firstWordIndex, plainText.substring(firstWordIndex)); tokens.add(token); - } else if (endWithDelimeter(queryText)) { + } else if (endWithDelimeter(plainText)) { SearchToken lastToken = getLastToken(); - if (lastToken.getType() == TokenType.SEARCH_OBJECT) { - ((ObjectSearchToken) lastToken).applySuggestion(); + if (lastToken.getType() == TokenType.OBJECT) { + ((ObjectToken) lastToken).applySuggestion(); } - SearchToken token = new NameFilterSearchToken(firstWordIndex, ""); + SearchToken token = new NameFilterToken(firstWordIndex, ""); tokens.add(token); } } - this.queryText = queryText; + this.plainText = plainText; } public void completeQuery(@NonNull SearchObject searchObject) { - String newQueryText; + String text; String objectName = searchObject.getName(lang); int startIndex; SearchToken lastToken = getLastToken(); if (lastToken == null || lastToken.hasEmptyQuery()) { - startIndex = queryText.length(); - newQueryText = queryText + objectName + " "; + startIndex = plainText.length(); + text = plainText + objectName + " "; } else { startIndex = lastToken.getStartIndex(); - newQueryText = queryText.substring(0, startIndex) + objectName + " "; + text = plainText.substring(0, startIndex) + objectName + " "; } - ObjectSearchToken token = new ObjectSearchToken(startIndex, objectName, searchObject, false); + ObjectToken token = new ObjectToken(startIndex, objectName, searchObject, false); if (lastToken == null) { tokens.add(token); } else { tokens.set(tokens.size() - 1, token); } - tokens.add(new NameFilterSearchToken(newQueryText.length(), "")); - queryText = newQueryText; + tokens.add(new NameFilterToken(text.length(), "")); + plainText = text; } private boolean endWithDelimeter(String text) { @@ -138,13 +138,13 @@ public class SearchString { return c == ',' || c == ' '; } - public NameFilterSearchToken getNextNameFilterToken() { - NameFilterSearchToken res = null; + public NameFilterToken getNextNameFilterToken() { + NameFilterToken res = null; if (!tokens.isEmpty()) { for (int i = tokens.size() - 1; i >= 0; i--) { SearchToken token = tokens.get(i); if (token.getType() == TokenType.NAME_FILTER) { - res = (NameFilterSearchToken) token; + res = (NameFilterToken) token; } else { break; } @@ -160,13 +160,13 @@ public class SearchString { return null; } - public ObjectSearchToken getLastObjectToken() { - ObjectSearchToken res = null; + public ObjectToken getLastObjectToken() { + ObjectToken res = null; if (!tokens.isEmpty()) { for (int i = tokens.size() - 1; i >= 0; i--) { SearchToken token = tokens.get(i); - if (token.getType() == TokenType.SEARCH_OBJECT) { - res = (ObjectSearchToken) token; + if (token.getType() == TokenType.OBJECT) { + res = (ObjectToken) token; break; } } @@ -183,11 +183,11 @@ public class SearchString { return false; } - public Map getCompleteObjectTokens() { - Map map = new LinkedHashMap<>(); + public Map getCompleteObjectTokens() { + Map map = new LinkedHashMap<>(); for (SearchToken token : tokens) { - if (token.getType() == TokenType.SEARCH_OBJECT && !((ObjectSearchToken)token).isSuggestion()) { - map.put(token.getSearchObject().getType(), token); + if (token.getType() == TokenType.OBJECT && !((ObjectToken)token).isSuggestion()) { + map.put(((ObjectToken)token).getSearchObject().getType(), (ObjectToken)token); } } return map; @@ -196,8 +196,8 @@ public class SearchString { public List getCompleteObjects() { List list = new ArrayList<>(); for (SearchToken token : tokens) { - if (token.getType() == TokenType.SEARCH_OBJECT && !((ObjectSearchToken)token).isSuggestion()) { - list.add(token.getSearchObject()); + if (token.getType() == TokenType.OBJECT && !((ObjectToken)token).isSuggestion()) { + list.add(((ObjectToken)token).getSearchObject()); } } return list; @@ -206,13 +206,13 @@ public class SearchString { public static void main(String[] args){ //test SearchString searchString = new SearchString(MapUtils.LANGUAGE); - searchString.setQueryText("cit"); - searchString.setQueryText("city"); - searchString.setQueryText("city "); - searchString.setQueryText("city s"); - searchString.setQueryText("city st"); - searchString.setQueryText("city street "); - searchString.setQueryText("city street 8"); - searchString.setQueryText("new"); + searchString.setPlainText("cit"); + searchString.setPlainText("city"); + searchString.setPlainText("city "); + searchString.setPlainText("city s"); + searchString.setPlainText("city st"); + searchString.setPlainText("city street "); + searchString.setPlainText("city street 8"); + searchString.setPlainText("new"); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/BuildingSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/BuildingSearchObject.java index 153bee68d8..e3dcdbe65c 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/BuildingSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/BuildingSearchObject.java @@ -4,28 +4,24 @@ import net.osmand.core.jni.Building; import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; -public class BuildingSearchObject extends SearchPositionObject { +public class BuildingSearchObject extends SearchPositionObject { public BuildingSearchObject(Building building) { super(SearchObjectType.BUILDING, building); } - public Building getBuilding() { - return (Building) getInternalObject(); - } - @Override public PointI getPosition31() { - return getBuilding().getPosition31(); + return getBaseObject().getPosition31(); } @Override public String getNativeName() { - return getBuilding().getNativeName(); + return getBaseObject().getNativeName(); } @Override protected QStringStringHash getLocalizedNames() { - return getBuilding().getLocalizedNames(); + return getBaseObject().getLocalizedNames(); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/CoordinatesSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/CoordinatesSearchObject.java index e5b7ef83d8..3980cef6ed 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/CoordinatesSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/CoordinatesSearchObject.java @@ -3,7 +3,7 @@ package net.osmand.core.samples.android.sample1.search.objects; import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; -public class CoordinatesSearchObject extends SearchPositionObject { +public class CoordinatesSearchObject extends SearchPositionObject { public CoordinatesSearchObject(PointI position31) { super(SearchObjectType.COORDINATES, position31); @@ -11,7 +11,7 @@ public class CoordinatesSearchObject extends SearchPositionObject { @Override public PointI getPosition31() { - return (PointI) getInternalObject(); + return getBaseObject(); } @Override diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiSearchObject.java index 8aa7589de5..83c73773b1 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiSearchObject.java @@ -4,28 +4,24 @@ import net.osmand.core.jni.Amenity; import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; -public class PoiSearchObject extends SearchPositionObject { +public class PoiSearchObject extends SearchPositionObject { public PoiSearchObject(Amenity amenity) { super(SearchObjectType.POI, amenity); } - public Amenity getAmenity() { - return (Amenity) getInternalObject(); - } - @Override public PointI getPosition31() { - return getAmenity().getPosition31(); + return getBaseObject().getPosition31(); } @Override public String getNativeName() { - return getAmenity().getNativeName(); + return getBaseObject().getNativeName(); } @Override protected QStringStringHash getLocalizedNames() { - return getAmenity().getLocalizedNames(); + return getBaseObject().getLocalizedNames(); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeObject.java index 087f1ba334..3acf8041c0 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeObject.java @@ -1,7 +1,26 @@ package net.osmand.core.samples.android.sample1.search.objects; -/** - * Created by Alexey Kulish on 30/06/16. - */ public class PoiTypeObject { + + private String name; + private String keyName; + private String categoryKeyName; + + public PoiTypeObject(String name, String keyName, String categoryKeyName) { + this.name = name; + this.keyName = keyName; + this.categoryKeyName = categoryKeyName; + } + + public String getName() { + return name; + } + + public String getKeyName() { + return keyName; + } + + public String getCategoryKeyName() { + return categoryKeyName; + } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeSearchObject.java index 8099828d57..86af7d165f 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/PoiTypeSearchObject.java @@ -2,12 +2,9 @@ package net.osmand.core.samples.android.sample1.search.objects; import net.osmand.core.jni.QStringStringHash; -public class PoiTypeSearchObject extends SearchObject { +public class PoiTypeSearchObject extends SearchObject { private ObjectType objectType; - private String name; - private String keyName; - private String categoryKeyName; public enum ObjectType { CATEGORY, @@ -15,12 +12,9 @@ public class PoiTypeSearchObject extends SearchObject { TYPE } - public PoiTypeSearchObject(ObjectType objectType, String name, String keyName, String categoryKeyName) { - super(SearchObjectType.POI_TYPE, null); + public PoiTypeSearchObject(ObjectType objectType, PoiTypeObject poiTypeObject) { + super(SearchObjectType.POI_TYPE, poiTypeObject); this.objectType = objectType; - this.name = name; - this.keyName = keyName; - this.categoryKeyName = categoryKeyName; } public ObjectType getObjectType() { @@ -28,16 +22,16 @@ public class PoiTypeSearchObject extends SearchObject { } public String getKeyName() { - return keyName; + return getBaseObject().getKeyName(); } public String getCategoryKeyName() { - return categoryKeyName; + return getBaseObject().getCategoryKeyName(); } @Override public String getNativeName() { - return name; + return getBaseObject().getName(); } @Override diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchObject.java index c392dd9f40..26251f1556 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchObject.java @@ -2,7 +2,7 @@ package net.osmand.core.samples.android.sample1.search.objects; import net.osmand.core.jni.QStringStringHash; -public abstract class SearchObject { +public abstract class SearchObject { public enum SearchObjectType { CITY, @@ -17,21 +17,21 @@ public abstract class SearchObject { } private SearchObjectType type; - private Object internalObject; + private T baseObject; private double priority; - protected SearchObject(SearchObjectType type, Object internalObject) { + protected SearchObject(SearchObjectType type, T baseObject) { this.type = type; - this.internalObject = internalObject; + this.baseObject = baseObject; } public SearchObjectType getType() { return type; } - protected Object getInternalObject() { - return internalObject; + public T getBaseObject() { + return baseObject; } public abstract String getNativeName(); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchPositionObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchPositionObject.java index 799040aef0..9c042d6186 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchPositionObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/SearchPositionObject.java @@ -2,12 +2,12 @@ package net.osmand.core.samples.android.sample1.search.objects; import net.osmand.core.jni.PointI; -public abstract class SearchPositionObject extends SearchObject { +public abstract class SearchPositionObject extends SearchObject { private double distance; - public SearchPositionObject(SearchObjectType type, Object internalObject) { - super(type, internalObject); + public SearchPositionObject(SearchObjectType type, T object) { + super(type, object); } public abstract PointI getPosition31(); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetGroupSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetGroupSearchObject.java index 39b093629d..a9a44fdc0a 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetGroupSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetGroupSearchObject.java @@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.StreetGroup; -public abstract class StreetGroupSearchObject extends SearchPositionObject { +public abstract class StreetGroupSearchObject extends SearchPositionObject { public StreetGroupSearchObject(SearchObjectType type, StreetGroup streetGroup) { super(type, streetGroup); } - public StreetGroup getStreetGroup() { - return (StreetGroup) getInternalObject(); - } - @Override public PointI getPosition31() { - return getStreetGroup().getPosition31(); + return getBaseObject().getPosition31(); } @Override public String getNativeName() { - return getStreetGroup().getNativeName(); + return getBaseObject().getNativeName(); } @Override protected QStringStringHash getLocalizedNames() { - return getStreetGroup().getLocalizedNames(); + return getBaseObject().getLocalizedNames(); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetIntersectionSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetIntersectionSearchObject.java index c20021dcc9..675873aa79 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetIntersectionSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetIntersectionSearchObject.java @@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.StreetIntersection; -public class StreetIntersectionSearchObject extends SearchPositionObject { +public class StreetIntersectionSearchObject extends SearchPositionObject { public StreetIntersectionSearchObject(StreetIntersection streetIntersection) { super(SearchObjectType.STREET_INTERSECTION, streetIntersection); } - public StreetIntersection getStreetIntersection() { - return (StreetIntersection) getInternalObject(); - } - @Override public PointI getPosition31() { - return getStreetIntersection().getPosition31(); + return getBaseObject().getPosition31(); } @Override public String getNativeName() { - return getStreetIntersection().getNativeName(); + return getBaseObject().getNativeName(); } @Override protected QStringStringHash getLocalizedNames() { - return getStreetIntersection().getLocalizedNames(); + return getBaseObject().getLocalizedNames(); } } \ No newline at end of file diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetSearchObject.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetSearchObject.java index 052860465f..be69b5d2da 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetSearchObject.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/objects/StreetSearchObject.java @@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.Street; -public class StreetSearchObject extends SearchPositionObject { +public class StreetSearchObject extends SearchPositionObject { public StreetSearchObject(Street street) { super(SearchObjectType.STREET, street); } - public Street getStreet() { - return (Street) getInternalObject(); - } - @Override public PointI getPosition31() { - return getStreet().getPosition31(); + return getBaseObject().getPosition31(); } @Override public String getNativeName() { - return getStreet().getNativeName(); + return getBaseObject().getNativeName(); } @Override protected QStringStringHash getLocalizedNames() { - return getStreet().getLocalizedNames(); + return getBaseObject().getLocalizedNames(); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/CoreSearchRequest.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/CoreSearchRequest.java index 69839e2758..9ff4f8f185 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/CoreSearchRequest.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/CoreSearchRequest.java @@ -17,10 +17,10 @@ import net.osmand.core.samples.android.sample1.search.SearchScope; import net.osmand.core.samples.android.sample1.search.SearchString; import net.osmand.core.samples.android.sample1.search.objects.PoiSearchObject; import net.osmand.core.samples.android.sample1.search.objects.SearchObject; -import net.osmand.core.samples.android.sample1.search.objects.SearchObjectsHelper; +import net.osmand.core.samples.android.sample1.search.SearchObjectsHelper; import net.osmand.core.samples.android.sample1.search.objects.SearchPositionObject; -import net.osmand.core.samples.android.sample1.search.tokens.NameFilterSearchToken; -import net.osmand.core.samples.android.sample1.search.tokens.ObjectSearchToken; +import net.osmand.core.samples.android.sample1.search.tokens.NameFilterToken; +import net.osmand.core.samples.android.sample1.search.tokens.ObjectToken; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken; import java.util.ArrayList; @@ -85,11 +85,11 @@ public class CoreSearchRequest extends SearchRequest { SearchString searchString = searchScope.getSearchString(); SearchToken lastToken = searchString.getLastToken(); - NameFilterSearchToken token = searchString.getNextNameFilterToken(); + NameFilterToken token = searchString.getNextNameFilterToken(); while (token != null && !cancelled) { if (!token.hasEmptyQuery()) { res = doCoreSearch(token); - List externalObjects = searchCallback.fetchExternalObjects(token.getQueryText(), searchString.getCompleteObjects()); + List externalObjects = searchCallback.fetchExternalObjects(token.getPlainText(), searchString.getCompleteObjects()); if (externalObjects != null) { res.addAll(externalObjects); } @@ -104,7 +104,7 @@ public class CoreSearchRequest extends SearchRequest { if (lastToken == null || lastToken.hasEmptyQuery()) { // 2.4 Search considered to be complete if there no NF in the end (not finished or not regonized objects) - ObjectSearchToken lastObjectToken = searchString.getLastObjectToken(); + ObjectToken lastObjectToken = searchString.getLastObjectToken(); if (lastObjectToken == null) { // Last object = [] - none. We display list of poi categories (recents separate tab) List externalObjects = searchCallback.fetchExternalObjects("", null); @@ -124,15 +124,15 @@ public class CoreSearchRequest extends SearchRequest { break; case CITY: // Last object - City. Display (list of streets could be quite long) - res = doCoreSearch(new NameFilterSearchToken(0, "")); + res = doCoreSearch(new NameFilterToken(0, "")); break; case STREET: // Last object - Street. Display building and intersetcting street - res = doCoreSearch(new NameFilterSearchToken(0, "")); + res = doCoreSearch(new NameFilterToken(0, "")); break; case POSTCODE: // Last object - Postcode. Display building and streets - res = doCoreSearch(new NameFilterSearchToken(0, "")); + res = doCoreSearch(new NameFilterToken(0, "")); break; case BUILDING: // Last object - Building - object is found @@ -151,7 +151,7 @@ public class CoreSearchRequest extends SearchRequest { amenityResultsCounter = 0; addressResultsCounter = 0; - String keyword = token.getQueryText(); + String keyword = token.getPlainText(); final List searchObjects = new ArrayList<>(); AmenitiesByNameSearch amByNameSearch = null; diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/IntermediateSearchRequest.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/IntermediateSearchRequest.java index 12a14a74b3..bf66e4b3e0 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/IntermediateSearchRequest.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/requests/IntermediateSearchRequest.java @@ -23,7 +23,7 @@ public class IntermediateSearchRequest extends SearchRequest { SearchToken token = searchScope.getSearchString().getLastToken(); if (token != null && token.getType() == SearchToken.TokenType.NAME_FILTER) { - keyword = token.getQueryText().toLowerCase(); + keyword = token.getPlainText().toLowerCase(); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/NameFilterToken.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/NameFilterToken.java index 055ed982a8..d7e46c4390 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/NameFilterToken.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/NameFilterToken.java @@ -3,6 +3,6 @@ package net.osmand.core.samples.android.sample1.search.tokens; public class NameFilterToken extends SearchToken { public NameFilterToken(int startIndex, String plainText) { - super(TokenType.NAME_FILTER, startIndex, plainText, null); + super(TokenType.NAME_FILTER, startIndex, plainText); } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/ObjectToken.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/ObjectToken.java index 9a6efa9bed..2b506e285a 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/ObjectToken.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/ObjectToken.java @@ -4,18 +4,25 @@ import net.osmand.core.samples.android.sample1.search.objects.SearchObject; public class ObjectToken extends SearchToken { + private SearchObject searchObject; private boolean suggestion = true; public ObjectToken(SearchToken searchToken, SearchObject searchObject, boolean suggestion) { - super(TokenType.SEARCH_OBJECT, searchToken.getStartIndex(), searchToken.getPlainText(), searchObject); + super(TokenType.OBJECT, searchToken.getStartIndex(), searchToken.getPlainText()); + this.searchObject = searchObject; this.suggestion = suggestion; } public ObjectToken(int startIndex, String plainText, SearchObject searchObject, boolean suggestion) { - super(TokenType.SEARCH_OBJECT, startIndex, plainText, searchObject); + super(TokenType.OBJECT, startIndex, plainText); + this.searchObject = searchObject; this.suggestion = suggestion; } + public SearchObject getSearchObject() { + return searchObject; + } + public boolean isSuggestion() { return suggestion; } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/SearchToken.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/SearchToken.java index 9f9c924b15..e93d2621c6 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/SearchToken.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/tokens/SearchToken.java @@ -1,25 +1,22 @@ package net.osmand.core.samples.android.sample1.search.tokens; -import net.osmand.core.samples.android.sample1.search.objects.SearchObject; import net.osmand.util.Algorithms; public abstract class SearchToken { public enum TokenType { - SEARCH_OBJECT, + OBJECT, NAME_FILTER } private TokenType type; - private SearchObject searchObject; private int startIndex; - protected String queryText; + protected String plainText; - public SearchToken(TokenType type, int startIndex, String queryText, SearchObject searchObject) { + public SearchToken(TokenType type, int startIndex, String plainText) { this.type = type; this.startIndex = startIndex; - this.queryText = queryText; - this.searchObject = searchObject; + this.plainText = plainText; } public TokenType getType() { @@ -30,19 +27,15 @@ public abstract class SearchToken { return startIndex; } - public String getQueryText() { - return queryText; + public String getPlainText() { + return plainText; } public int getLastIndex() { - return startIndex + queryText.length() - 1; - } - - public SearchObject getSearchObject() { - return searchObject; + return startIndex + plainText.length() - 1; } public boolean hasEmptyQuery() { - return Algorithms.isEmpty(queryText); + return Algorithms.isEmpty(plainText); } }