Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-06-30 16:16:24 +02:00
commit 74f6a15333
27 changed files with 190 additions and 196 deletions

View file

@ -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.PoiTypeSearchObject.ObjectType;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject; 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.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.core.samples.android.sample1.search.tokens.SearchToken;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
@ -210,6 +210,7 @@ public class MainActivity extends Activity {
res = poiTypesHelper.findPoiTypes(keyword); res = poiTypesHelper.findPoiTypes(keyword);
} }
/*
for (AbstractPoiType pt : res) { for (AbstractPoiType pt : res) {
if (pt instanceof PoiCategory) { if (pt instanceof PoiCategory) {
result.add(new PoiTypeSearchObject(ObjectType.CATEGORY, result.add(new PoiTypeSearchObject(ObjectType.CATEGORY,
@ -224,6 +225,7 @@ public class MainActivity extends Activity {
poiType.getTranslation(), poiType.getKeyName(), poiType.getCategory().getKeyName())); poiType.getTranslation(), poiType.getKeyName(), poiType.getCategory().getKeyName()));
} }
} }
*/
return result; return result;
} }
@ -234,9 +236,9 @@ public class MainActivity extends Activity {
processSearchResult(searchObjects); processSearchResult(searchObjects);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Map<SearchObjectType, SearchToken> objectTokensMap = searchAPI.getObjectTokens(); Map<SearchObjectType, ObjectToken> objectTokensMap = searchAPI.getObjectTokens();
ObjectSearchToken lastObjectToken = searchAPI.getLastObjectToken(); ObjectToken lastObjectToken = searchAPI.getLastObjectToken();
for (SearchToken token : objectTokensMap.values()) { for (ObjectToken token : objectTokensMap.values()) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(""); sb.append("");
} }

View file

@ -11,12 +11,12 @@ public class BuildingSearchListItem extends SearchListPositionItem {
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public BuildingSearchListItem(SampleApplication app, BuildingSearchObject searchObject) { public BuildingSearchListItem(SampleApplication app, BuildingSearchObject buildingObject) {
super(app, searchObject); 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(); Street street = building.getStreet();
if (street != null) { if (street != null) {

View file

@ -9,10 +9,10 @@ public class CitySearchListItem extends SearchListPositionItem{
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public CitySearchListItem(SampleApplication app, CitySearchObject searchObject) { public CitySearchListItem(SampleApplication app, CitySearchObject cityObject) {
super(app, searchObject); super(app, cityObject);
nameStr = searchObject.getName(MapUtils.LANGUAGE); nameStr = cityObject.getName(MapUtils.LANGUAGE);
typeStr = "City"; typeStr = "City";
} }

View file

@ -26,20 +26,20 @@ public class PoiSearchListItem extends SearchListPositionItem {
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public PoiSearchListItem(SampleApplication app, PoiSearchObject searchObject) { public PoiSearchListItem(SampleApplication app, PoiSearchObject poiObject) {
super(app, searchObject); super(app, poiObject);
amenity = parseAmenity(searchObject); amenity = parseAmenity(poiObject);
nameStr = amenity.getName(MapUtils.LANGUAGE); nameStr = amenity.getName(MapUtils.LANGUAGE);
typeStr = getTypeStr(); typeStr = getTypeStr();
} }
private Amenity parseAmenity(PoiSearchObject searchItem) { private Amenity parseAmenity(PoiSearchObject poiObject) {
String categoryName = ""; String categoryName = "";
String subcategoryName = ""; String subcategoryName = "";
Map<String, String> values = new HashMap<>(); Map<String, String> values = new HashMap<>();
net.osmand.core.jni.Amenity coreAmenity = searchItem.getAmenity(); net.osmand.core.jni.Amenity coreAmenity = poiObject.getBaseObject();
DecodedCategoryList catList = coreAmenity.getDecodedCategories(); DecodedCategoryList catList = coreAmenity.getDecodedCategories();
if (catList.size() > 0) { if (catList.size() > 0) {
DecodedCategory decodedCategory = catList.get(0); DecodedCategory decodedCategory = catList.get(0);
@ -63,7 +63,7 @@ public class PoiSearchListItem extends SearchListPositionItem {
PoiCategory category = poiTypes.getPoiCategoryByName(categoryName); PoiCategory category = poiTypes.getPoiCategoryByName(categoryName);
a.setType(category); a.setType(category);
a.setSubType(subcategoryName); a.setSubType(subcategoryName);
a.setName(searchItem.getNativeName()); a.setName(poiObject.getNativeName());
QStringStringHash localizedNamesMap = coreAmenity.getLocalizedNames(); QStringStringHash localizedNamesMap = coreAmenity.getLocalizedNames();
QStringList locNamesKeys = localizedNamesMap.keys(); QStringList locNamesKeys = localizedNamesMap.keys();

View file

@ -10,10 +10,10 @@ public class PostcodeSearchListItem extends SearchListPositionItem {
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject searchObject) { public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject postcodeObject) {
super(app, searchObject); super(app, postcodeObject);
nameStr = searchObject.getNativeName(); nameStr = postcodeObject.getNativeName();
typeStr = "Postcode"; typeStr = "Postcode";
} }

View file

@ -11,9 +11,9 @@ public class SearchListPositionItem extends SearchListItem {
private double latitude; private double latitude;
private double longitude; private double longitude;
public SearchListPositionItem(SampleApplication app, SearchPositionObject searchObject) { public SearchListPositionItem(SampleApplication app, SearchPositionObject positionObject) {
super(app, searchObject); super(app, positionObject);
PointI position31 = searchObject.getPosition31(); PointI position31 = positionObject.getPosition31();
LatLon latLon = Utilities.convert31ToLatLon(position31); LatLon latLon = Utilities.convert31ToLatLon(position31);
latitude = latLon.getLatitude(); latitude = latLon.getLatitude();
longitude = latLon.getLongitude(); longitude = latLon.getLongitude();

View file

@ -11,12 +11,12 @@ public class StreetIntersectionSearchListItem extends SearchListPositionItem {
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public StreetIntersectionSearchListItem(SampleApplication app, StreetIntersectionSearchObject searchObject) { public StreetIntersectionSearchListItem(SampleApplication app, StreetIntersectionSearchObject intersectionObject) {
super(app, searchObject); 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(); Street street = streetIntersection.getStreet();
if (street != null) { if (street != null) {

View file

@ -10,12 +10,12 @@ public class StreetSearchListItem extends SearchListPositionItem {
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public StreetSearchListItem(SampleApplication app, StreetSearchObject searchObject) { public StreetSearchListItem(SampleApplication app, StreetSearchObject streetObject) {
super(app, searchObject); 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) { if (streetGroup != null) {
typeStr = streetGroup.getNativeName() + "" + getTypeStr(streetGroup); typeStr = streetGroup.getNativeName() + "" + getTypeStr(streetGroup);
} else { } else {

View file

@ -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.MapUtils;
import net.osmand.core.samples.android.sample1.SampleApplication; 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; import net.osmand.core.samples.android.sample1.search.objects.VillageSearchObject;
public class VillageSearchListItem extends SearchListPositionItem{ public class VillageSearchListItem extends SearchListPositionItem{
@ -10,10 +9,10 @@ public class VillageSearchListItem extends SearchListPositionItem{
private String nameStr; private String nameStr;
private String typeStr; private String typeStr;
public VillageSearchListItem(SampleApplication app, VillageSearchObject searchObject) { public VillageSearchListItem(SampleApplication app, VillageSearchObject villageObject) {
super(app, searchObject); super(app, villageObject);
nameStr = searchObject.getName(MapUtils.LANGUAGE); nameStr = villageObject.getName(MapUtils.LANGUAGE);
typeStr = "Village"; typeStr = "Village";
} }

View file

@ -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.CoreSearchRequest;
import net.osmand.core.samples.android.sample1.search.requests.IntermediateSearchRequest; 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.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 net.osmand.core.samples.android.sample1.search.tokens.SearchToken;
import java.util.ArrayList; import java.util.ArrayList;
@ -115,11 +115,11 @@ public class SearchAPI {
this.searchObjects = searchObjects; this.searchObjects = searchObjects;
} }
public Map<SearchObjectType, SearchToken> getObjectTokens() { public Map<SearchObjectType, ObjectToken> getObjectTokens() {
return searchString.getCompleteObjectTokens(); return searchString.getCompleteObjectTokens();
} }
public ObjectSearchToken getLastObjectToken() { public ObjectToken getLastObjectToken() {
return searchString.getLastObjectToken(); return searchString.getLastObjectToken();
} }
@ -127,7 +127,7 @@ public class SearchAPI {
SearchApiCallback intermediateSearchCallback, SearchApiCallback intermediateSearchCallback,
SearchApiCallback coreSearchCallback) { SearchApiCallback coreSearchCallback) {
searchString.setQueryText(query); searchString.setPlainText(query);
startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback); startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback);
} }
@ -137,7 +137,7 @@ public class SearchAPI {
searchString.completeQuery(searchObject); searchString.completeQuery(searchObject);
startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback); startSearchInternal(maxSearchResults, intermediateSearchCallback, coreSearchCallback);
return searchString.getQueryText(); return searchString.getPlainText();
} }
private void startSearchInternal(int maxSearchResults, private void startSearchInternal(int maxSearchResults,

View file

@ -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.SearchPositionObject;
import net.osmand.core.samples.android.sample1.search.objects.StreetGroupSearchObject; 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.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 net.osmand.core.samples.android.sample1.search.tokens.SearchToken;
import java.util.Collections; import java.util.Collections;
@ -33,7 +33,7 @@ public class SearchScope {
private ObfsCollection obfsCollection; private ObfsCollection obfsCollection;
private SearchString searchString; private SearchString searchString;
private String lang; private String lang;
private Map<SearchObjectType, SearchToken> objectTokens; private Map<SearchObjectType, ObjectToken> objectTokens;
private PointI searchLocation31; private PointI searchLocation31;
private AreaI searchableArea; private AreaI searchableArea;
private AreaI obfAreaFilter; private AreaI obfAreaFilter;
@ -110,7 +110,7 @@ public class SearchScope {
if (objectTokens.containsKey(SearchObjectType.STREET)) { if (objectTokens.containsKey(SearchObjectType.STREET)) {
StreetSearchObject streetSearchObject = StreetSearchObject streetSearchObject =
(StreetSearchObject) objectTokens.get(SearchObjectType.STREET).getSearchObject(); (StreetSearchObject) objectTokens.get(SearchObjectType.STREET).getSearchObject();
criteria.setAddressFilter(streetSearchObject.getStreet()); criteria.setAddressFilter(streetSearchObject.getBaseObject());
if (objectTokens.containsKey(SearchObjectType.POSTCODE)) { if (objectTokens.containsKey(SearchObjectType.POSTCODE)) {
PostcodeSearchObject postcodeSearchObject = PostcodeSearchObject postcodeSearchObject =
(PostcodeSearchObject) objectTokens.get(SearchObjectType.POSTCODE).getSearchObject(); (PostcodeSearchObject) objectTokens.get(SearchObjectType.POSTCODE).getSearchObject();
@ -118,13 +118,13 @@ public class SearchScope {
} }
} else if (objectTokens.containsKey(SearchObjectType.CITY)) { } else if (objectTokens.containsKey(SearchObjectType.CITY)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.CITY) criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.CITY)
.getSearchObject()).getStreetGroup()); .getSearchObject()).getBaseObject());
} else if (objectTokens.containsKey(SearchObjectType.VILLAGE)) { } else if (objectTokens.containsKey(SearchObjectType.VILLAGE)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.VILLAGE) criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.VILLAGE)
.getSearchObject()).getStreetGroup()); .getSearchObject()).getBaseObject());
} else if (objectTokens.containsKey(SearchObjectType.POSTCODE)) { } else if (objectTokens.containsKey(SearchObjectType.POSTCODE)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(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 if (token.getType() == SearchToken.TokenType.NAME_FILTER
&& !token.hasEmptyQuery()) { && !token.hasEmptyQuery()) {
boolean suggeston = token == searchString.getLastToken(); 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); searchString.replaceToken(token, newToken);
} }
} }
@ -220,22 +220,22 @@ public class SearchScope {
case STREET: case STREET:
StreetSearchObject streetSearchObject = (StreetSearchObject) searchObject; StreetSearchObject streetSearchObject = (StreetSearchObject) searchObject;
Street street = streetSearchObject.getStreet(); Street street = streetSearchObject.getBaseObject();
if (!citySelected) { if (!citySelected) {
priority = getPriorityByDistance(9.0, streetSearchObject.getDistance()); priority = getPriorityByDistance(9.0, streetSearchObject.getDistance());
} else { } else {
boolean streetFromSelectedCity = false; boolean streetFromSelectedCity = false;
for (SearchToken st : objectTokens.values()) { for (ObjectToken st : objectTokens.values()) {
if (st.getSearchObject() instanceof StreetGroupSearchObject) { if (st.getSearchObject() instanceof StreetGroupSearchObject) {
StreetGroup streetGroup = StreetGroup streetGroup =
((StreetGroupSearchObject) st.getSearchObject()).getStreetGroup(); ((StreetGroupSearchObject) st.getSearchObject()).getBaseObject();
if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) { if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) {
streetFromSelectedCity = true; streetFromSelectedCity = true;
break; break;
} }
} else if (st.getSearchObject() instanceof StreetSearchObject) { } else if (st.getSearchObject() instanceof StreetSearchObject) {
StreetGroup streetGroup = StreetGroup streetGroup =
((StreetSearchObject) st.getSearchObject()).getStreet().getStreetGroup(); ((StreetSearchObject) st.getSearchObject()).getBaseObject().getStreetGroup();
if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) { if (streetGroup.getId().getId().equals(street.getStreetGroup().getId().getId())) {
streetFromSelectedCity = true; streetFromSelectedCity = true;
break; break;
@ -256,10 +256,10 @@ public class SearchScope {
} }
private double getCityType(StreetGroupSearchObject searchObject) { private double getCityType(StreetGroupSearchObject searchObject) {
if (searchObject.getStreetGroup().getType() == ObfAddressStreetGroupType.CityOrTown) { if (searchObject.getBaseObject().getType() == ObfAddressStreetGroupType.CityOrTown) {
if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.City) { if (searchObject.getBaseObject().getSubtype() == ObfAddressStreetGroupSubtype.City) {
return 1.0; return 1.0;
} else if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.Town) { } else if (searchObject.getBaseObject().getSubtype() == ObfAddressStreetGroupSubtype.Town) {
return 1.5; return 1.5;
} }
} }

View file

@ -5,8 +5,8 @@ import android.support.annotation.NonNull;
import net.osmand.core.samples.android.sample1.MapUtils; 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;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject.SearchObjectType; 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.NameFilterToken;
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.core.samples.android.sample1.search.tokens.SearchToken;
import net.osmand.core.samples.android.sample1.search.tokens.SearchToken.TokenType; import net.osmand.core.samples.android.sample1.search.tokens.SearchToken.TokenType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -18,7 +18,7 @@ import java.util.Map;
public class SearchString { public class SearchString {
private String queryText = ""; private String plainText = "";
private List<SearchToken> tokens = new ArrayList<>(); private List<SearchToken> tokens = new ArrayList<>();
private String lang; private String lang;
@ -28,21 +28,21 @@ public class SearchString {
public SearchString copy() { public SearchString copy() {
SearchString res = new SearchString(lang); SearchString res = new SearchString(lang);
res.queryText = queryText; res.plainText = plainText;
res.tokens = new ArrayList<>(tokens); res.tokens = new ArrayList<>(tokens);
return res; return res;
} }
public String getQueryText() { public String getPlainText() {
return queryText; return plainText;
} }
public void setQueryText(String queryText) { public void setPlainText(String plainText) {
int newTextLength = queryText.length(); int newTextLength = plainText.length();
int currTextLength = this.queryText.length(); int currTextLength = this.plainText.length();
boolean isNewText = currTextLength == 0 boolean isNewText = currTextLength == 0
|| newTextLength == 0 || newTextLength == 0
|| !this.queryText.regionMatches(0, queryText, 0, || !this.plainText.regionMatches(0, plainText, 0,
newTextLength > currTextLength ? currTextLength : newTextLength); newTextLength > currTextLength ? currTextLength : newTextLength);
int lastKnownTokenIndex = -1; int lastKnownTokenIndex = -1;
@ -55,7 +55,7 @@ public class SearchString {
int lastTokenIndex = token.getLastIndex(); int lastTokenIndex = token.getLastIndex();
if (lastTokenIndex > newTextLength - 1 if (lastTokenIndex > newTextLength - 1
|| token.hasEmptyQuery() || token.hasEmptyQuery()
|| (lastTokenIndex < newTextLength - 1 && !startWithDelimiter(queryText.substring(lastTokenIndex + 1)))) { || (lastTokenIndex < newTextLength - 1 && !startWithDelimiter(plainText.substring(lastTokenIndex + 1)))) {
brokenTokenIndex = i; brokenTokenIndex = i;
break; break;
} }
@ -76,53 +76,53 @@ public class SearchString {
if (newTextLength - 1 > lastKnownTokenIndex) { if (newTextLength - 1 > lastKnownTokenIndex) {
int firstWordIndex = lastKnownTokenIndex + 1; int firstWordIndex = lastKnownTokenIndex + 1;
for (int i = lastKnownTokenIndex + 1; i < newTextLength; i++) { for (int i = lastKnownTokenIndex + 1; i < newTextLength; i++) {
char c = queryText.charAt(i); char c = plainText.charAt(i);
if (isDelimiterChar(c)) { if (isDelimiterChar(c)) {
if (i == firstWordIndex) { if (i == firstWordIndex) {
firstWordIndex++; firstWordIndex++;
} else { } else {
SearchToken token = new NameFilterSearchToken(firstWordIndex, queryText.substring(firstWordIndex, i)); SearchToken token = new NameFilterToken(firstWordIndex, plainText.substring(firstWordIndex, i));
tokens.add(token); tokens.add(token);
firstWordIndex = i + 1; firstWordIndex = i + 1;
} }
} }
} }
if (firstWordIndex <= newTextLength - 1) { if (firstWordIndex <= newTextLength - 1) {
SearchToken token = new NameFilterSearchToken(firstWordIndex, queryText.substring(firstWordIndex)); SearchToken token = new NameFilterToken(firstWordIndex, plainText.substring(firstWordIndex));
tokens.add(token); tokens.add(token);
} else if (endWithDelimeter(queryText)) { } else if (endWithDelimeter(plainText)) {
SearchToken lastToken = getLastToken(); SearchToken lastToken = getLastToken();
if (lastToken.getType() == TokenType.SEARCH_OBJECT) { if (lastToken.getType() == TokenType.OBJECT) {
((ObjectSearchToken) lastToken).applySuggestion(); ((ObjectToken) lastToken).applySuggestion();
} }
SearchToken token = new NameFilterSearchToken(firstWordIndex, ""); SearchToken token = new NameFilterToken(firstWordIndex, "");
tokens.add(token); tokens.add(token);
} }
} }
this.queryText = queryText; this.plainText = plainText;
} }
public void completeQuery(@NonNull SearchObject searchObject) { public void completeQuery(@NonNull SearchObject searchObject) {
String newQueryText; String text;
String objectName = searchObject.getName(lang); String objectName = searchObject.getName(lang);
int startIndex; int startIndex;
SearchToken lastToken = getLastToken(); SearchToken lastToken = getLastToken();
if (lastToken == null || lastToken.hasEmptyQuery()) { if (lastToken == null || lastToken.hasEmptyQuery()) {
startIndex = queryText.length(); startIndex = plainText.length();
newQueryText = queryText + objectName + " "; text = plainText + objectName + " ";
} else { } else {
startIndex = lastToken.getStartIndex(); 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) { if (lastToken == null) {
tokens.add(token); tokens.add(token);
} else { } else {
tokens.set(tokens.size() - 1, token); tokens.set(tokens.size() - 1, token);
} }
tokens.add(new NameFilterSearchToken(newQueryText.length(), "")); tokens.add(new NameFilterToken(text.length(), ""));
queryText = newQueryText; plainText = text;
} }
private boolean endWithDelimeter(String text) { private boolean endWithDelimeter(String text) {
@ -138,13 +138,13 @@ public class SearchString {
return c == ',' || c == ' '; return c == ',' || c == ' ';
} }
public NameFilterSearchToken getNextNameFilterToken() { public NameFilterToken getNextNameFilterToken() {
NameFilterSearchToken res = null; NameFilterToken res = null;
if (!tokens.isEmpty()) { if (!tokens.isEmpty()) {
for (int i = tokens.size() - 1; i >= 0; i--) { for (int i = tokens.size() - 1; i >= 0; i--) {
SearchToken token = tokens.get(i); SearchToken token = tokens.get(i);
if (token.getType() == TokenType.NAME_FILTER) { if (token.getType() == TokenType.NAME_FILTER) {
res = (NameFilterSearchToken) token; res = (NameFilterToken) token;
} else { } else {
break; break;
} }
@ -160,13 +160,13 @@ public class SearchString {
return null; return null;
} }
public ObjectSearchToken getLastObjectToken() { public ObjectToken getLastObjectToken() {
ObjectSearchToken res = null; ObjectToken res = null;
if (!tokens.isEmpty()) { if (!tokens.isEmpty()) {
for (int i = tokens.size() - 1; i >= 0; i--) { for (int i = tokens.size() - 1; i >= 0; i--) {
SearchToken token = tokens.get(i); SearchToken token = tokens.get(i);
if (token.getType() == TokenType.SEARCH_OBJECT) { if (token.getType() == TokenType.OBJECT) {
res = (ObjectSearchToken) token; res = (ObjectToken) token;
break; break;
} }
} }
@ -183,11 +183,11 @@ public class SearchString {
return false; return false;
} }
public Map<SearchObjectType, SearchToken> getCompleteObjectTokens() { public Map<SearchObjectType, ObjectToken> getCompleteObjectTokens() {
Map<SearchObjectType, SearchToken> map = new LinkedHashMap<>(); Map<SearchObjectType, ObjectToken> map = new LinkedHashMap<>();
for (SearchToken token : tokens) { for (SearchToken token : tokens) {
if (token.getType() == TokenType.SEARCH_OBJECT && !((ObjectSearchToken)token).isSuggestion()) { if (token.getType() == TokenType.OBJECT && !((ObjectToken)token).isSuggestion()) {
map.put(token.getSearchObject().getType(), token); map.put(((ObjectToken)token).getSearchObject().getType(), (ObjectToken)token);
} }
} }
return map; return map;
@ -196,8 +196,8 @@ public class SearchString {
public List<SearchObject> getCompleteObjects() { public List<SearchObject> getCompleteObjects() {
List<SearchObject> list = new ArrayList<>(); List<SearchObject> list = new ArrayList<>();
for (SearchToken token : tokens) { for (SearchToken token : tokens) {
if (token.getType() == TokenType.SEARCH_OBJECT && !((ObjectSearchToken)token).isSuggestion()) { if (token.getType() == TokenType.OBJECT && !((ObjectToken)token).isSuggestion()) {
list.add(token.getSearchObject()); list.add(((ObjectToken)token).getSearchObject());
} }
} }
return list; return list;
@ -206,13 +206,13 @@ public class SearchString {
public static void main(String[] args){ public static void main(String[] args){
//test //test
SearchString searchString = new SearchString(MapUtils.LANGUAGE); SearchString searchString = new SearchString(MapUtils.LANGUAGE);
searchString.setQueryText("cit"); searchString.setPlainText("cit");
searchString.setQueryText("city"); searchString.setPlainText("city");
searchString.setQueryText("city "); searchString.setPlainText("city ");
searchString.setQueryText("city s"); searchString.setPlainText("city s");
searchString.setQueryText("city st"); searchString.setPlainText("city st");
searchString.setQueryText("city street "); searchString.setPlainText("city street ");
searchString.setQueryText("city street 8"); searchString.setPlainText("city street 8");
searchString.setQueryText("new"); searchString.setPlainText("new");
} }
} }

View file

@ -4,28 +4,24 @@ import net.osmand.core.jni.Building;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
public class BuildingSearchObject extends SearchPositionObject { public class BuildingSearchObject extends SearchPositionObject<Building> {
public BuildingSearchObject(Building building) { public BuildingSearchObject(Building building) {
super(SearchObjectType.BUILDING, building); super(SearchObjectType.BUILDING, building);
} }
public Building getBuilding() {
return (Building) getInternalObject();
}
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return getBuilding().getPosition31(); return getBaseObject().getPosition31();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return getBuilding().getNativeName(); return getBaseObject().getNativeName();
} }
@Override @Override
protected QStringStringHash getLocalizedNames() { protected QStringStringHash getLocalizedNames() {
return getBuilding().getLocalizedNames(); return getBaseObject().getLocalizedNames();
} }
} }

View file

@ -3,7 +3,7 @@ package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
public class CoordinatesSearchObject extends SearchPositionObject { public class CoordinatesSearchObject extends SearchPositionObject<PointI> {
public CoordinatesSearchObject(PointI position31) { public CoordinatesSearchObject(PointI position31) {
super(SearchObjectType.COORDINATES, position31); super(SearchObjectType.COORDINATES, position31);
@ -11,7 +11,7 @@ public class CoordinatesSearchObject extends SearchPositionObject {
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return (PointI) getInternalObject(); return getBaseObject();
} }
@Override @Override

View file

@ -4,28 +4,24 @@ import net.osmand.core.jni.Amenity;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
public class PoiSearchObject extends SearchPositionObject { public class PoiSearchObject extends SearchPositionObject<Amenity> {
public PoiSearchObject(Amenity amenity) { public PoiSearchObject(Amenity amenity) {
super(SearchObjectType.POI, amenity); super(SearchObjectType.POI, amenity);
} }
public Amenity getAmenity() {
return (Amenity) getInternalObject();
}
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return getAmenity().getPosition31(); return getBaseObject().getPosition31();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return getAmenity().getNativeName(); return getBaseObject().getNativeName();
} }
@Override @Override
protected QStringStringHash getLocalizedNames() { protected QStringStringHash getLocalizedNames() {
return getAmenity().getLocalizedNames(); return getBaseObject().getLocalizedNames();
} }
} }

View file

@ -1,7 +1,26 @@
package net.osmand.core.samples.android.sample1.search.objects; package net.osmand.core.samples.android.sample1.search.objects;
/**
* Created by Alexey Kulish on 30/06/16.
*/
public class PoiTypeObject { 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;
}
} }

View file

@ -2,12 +2,9 @@ package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
public class PoiTypeSearchObject extends SearchObject { public class PoiTypeSearchObject extends SearchObject<PoiTypeObject> {
private ObjectType objectType; private ObjectType objectType;
private String name;
private String keyName;
private String categoryKeyName;
public enum ObjectType { public enum ObjectType {
CATEGORY, CATEGORY,
@ -15,12 +12,9 @@ public class PoiTypeSearchObject extends SearchObject {
TYPE TYPE
} }
public PoiTypeSearchObject(ObjectType objectType, String name, String keyName, String categoryKeyName) { public PoiTypeSearchObject(ObjectType objectType, PoiTypeObject poiTypeObject) {
super(SearchObjectType.POI_TYPE, null); super(SearchObjectType.POI_TYPE, poiTypeObject);
this.objectType = objectType; this.objectType = objectType;
this.name = name;
this.keyName = keyName;
this.categoryKeyName = categoryKeyName;
} }
public ObjectType getObjectType() { public ObjectType getObjectType() {
@ -28,16 +22,16 @@ public class PoiTypeSearchObject extends SearchObject {
} }
public String getKeyName() { public String getKeyName() {
return keyName; return getBaseObject().getKeyName();
} }
public String getCategoryKeyName() { public String getCategoryKeyName() {
return categoryKeyName; return getBaseObject().getCategoryKeyName();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return name; return getBaseObject().getName();
} }
@Override @Override

View file

@ -2,7 +2,7 @@ package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
public abstract class SearchObject { public abstract class SearchObject<T> {
public enum SearchObjectType { public enum SearchObjectType {
CITY, CITY,
@ -17,21 +17,21 @@ public abstract class SearchObject {
} }
private SearchObjectType type; private SearchObjectType type;
private Object internalObject; private T baseObject;
private double priority; private double priority;
protected SearchObject(SearchObjectType type, Object internalObject) { protected SearchObject(SearchObjectType type, T baseObject) {
this.type = type; this.type = type;
this.internalObject = internalObject; this.baseObject = baseObject;
} }
public SearchObjectType getType() { public SearchObjectType getType() {
return type; return type;
} }
protected Object getInternalObject() { public T getBaseObject() {
return internalObject; return baseObject;
} }
public abstract String getNativeName(); public abstract String getNativeName();

View file

@ -2,12 +2,12 @@ package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
public abstract class SearchPositionObject extends SearchObject { public abstract class SearchPositionObject<T> extends SearchObject<T> {
private double distance; private double distance;
public SearchPositionObject(SearchObjectType type, Object internalObject) { public SearchPositionObject(SearchObjectType type, T object) {
super(type, internalObject); super(type, object);
} }
public abstract PointI getPosition31(); public abstract PointI getPosition31();

View file

@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.StreetGroup; import net.osmand.core.jni.StreetGroup;
public abstract class StreetGroupSearchObject extends SearchPositionObject { public abstract class StreetGroupSearchObject extends SearchPositionObject<StreetGroup> {
public StreetGroupSearchObject(SearchObjectType type, StreetGroup streetGroup) { public StreetGroupSearchObject(SearchObjectType type, StreetGroup streetGroup) {
super(type, streetGroup); super(type, streetGroup);
} }
public StreetGroup getStreetGroup() {
return (StreetGroup) getInternalObject();
}
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return getStreetGroup().getPosition31(); return getBaseObject().getPosition31();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return getStreetGroup().getNativeName(); return getBaseObject().getNativeName();
} }
@Override @Override
protected QStringStringHash getLocalizedNames() { protected QStringStringHash getLocalizedNames() {
return getStreetGroup().getLocalizedNames(); return getBaseObject().getLocalizedNames();
} }
} }

View file

@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.StreetIntersection; import net.osmand.core.jni.StreetIntersection;
public class StreetIntersectionSearchObject extends SearchPositionObject { public class StreetIntersectionSearchObject extends SearchPositionObject<StreetIntersection> {
public StreetIntersectionSearchObject(StreetIntersection streetIntersection) { public StreetIntersectionSearchObject(StreetIntersection streetIntersection) {
super(SearchObjectType.STREET_INTERSECTION, streetIntersection); super(SearchObjectType.STREET_INTERSECTION, streetIntersection);
} }
public StreetIntersection getStreetIntersection() {
return (StreetIntersection) getInternalObject();
}
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return getStreetIntersection().getPosition31(); return getBaseObject().getPosition31();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return getStreetIntersection().getNativeName(); return getBaseObject().getNativeName();
} }
@Override @Override
protected QStringStringHash getLocalizedNames() { protected QStringStringHash getLocalizedNames() {
return getStreetIntersection().getLocalizedNames(); return getBaseObject().getLocalizedNames();
} }
} }

View file

@ -4,28 +4,24 @@ import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.Street; import net.osmand.core.jni.Street;
public class StreetSearchObject extends SearchPositionObject { public class StreetSearchObject extends SearchPositionObject<Street> {
public StreetSearchObject(Street street) { public StreetSearchObject(Street street) {
super(SearchObjectType.STREET, street); super(SearchObjectType.STREET, street);
} }
public Street getStreet() {
return (Street) getInternalObject();
}
@Override @Override
public PointI getPosition31() { public PointI getPosition31() {
return getStreet().getPosition31(); return getBaseObject().getPosition31();
} }
@Override @Override
public String getNativeName() { public String getNativeName() {
return getStreet().getNativeName(); return getBaseObject().getNativeName();
} }
@Override @Override
protected QStringStringHash getLocalizedNames() { protected QStringStringHash getLocalizedNames() {
return getStreet().getLocalizedNames(); return getBaseObject().getLocalizedNames();
} }
} }

View file

@ -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.SearchString;
import net.osmand.core.samples.android.sample1.search.objects.PoiSearchObject; 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.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.objects.SearchPositionObject;
import net.osmand.core.samples.android.sample1.search.tokens.NameFilterSearchToken; import net.osmand.core.samples.android.sample1.search.tokens.NameFilterToken;
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.core.samples.android.sample1.search.tokens.SearchToken;
import java.util.ArrayList; import java.util.ArrayList;
@ -85,11 +85,11 @@ public class CoreSearchRequest extends SearchRequest {
SearchString searchString = searchScope.getSearchString(); SearchString searchString = searchScope.getSearchString();
SearchToken lastToken = searchString.getLastToken(); SearchToken lastToken = searchString.getLastToken();
NameFilterSearchToken token = searchString.getNextNameFilterToken(); NameFilterToken token = searchString.getNextNameFilterToken();
while (token != null && !cancelled) { while (token != null && !cancelled) {
if (!token.hasEmptyQuery()) { if (!token.hasEmptyQuery()) {
res = doCoreSearch(token); res = doCoreSearch(token);
List<SearchObject> externalObjects = searchCallback.fetchExternalObjects(token.getQueryText(), searchString.getCompleteObjects()); List<SearchObject> externalObjects = searchCallback.fetchExternalObjects(token.getPlainText(), searchString.getCompleteObjects());
if (externalObjects != null) { if (externalObjects != null) {
res.addAll(externalObjects); res.addAll(externalObjects);
} }
@ -104,7 +104,7 @@ public class CoreSearchRequest extends SearchRequest {
if (lastToken == null || lastToken.hasEmptyQuery()) { 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) // 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) { if (lastObjectToken == null) {
// Last object = [] - none. We display list of poi categories (recents separate tab) // Last object = [] - none. We display list of poi categories (recents separate tab)
List<SearchObject> externalObjects = searchCallback.fetchExternalObjects("", null); List<SearchObject> externalObjects = searchCallback.fetchExternalObjects("", null);
@ -124,15 +124,15 @@ public class CoreSearchRequest extends SearchRequest {
break; break;
case CITY: case CITY:
// Last object - City. Display (list of streets could be quite long) // Last object - City. Display (list of streets could be quite long)
res = doCoreSearch(new NameFilterSearchToken(0, "")); res = doCoreSearch(new NameFilterToken(0, ""));
break; break;
case STREET: case STREET:
// Last object - Street. Display building and intersetcting street // Last object - Street. Display building and intersetcting street
res = doCoreSearch(new NameFilterSearchToken(0, "")); res = doCoreSearch(new NameFilterToken(0, ""));
break; break;
case POSTCODE: case POSTCODE:
// Last object - Postcode. Display building and streets // Last object - Postcode. Display building and streets
res = doCoreSearch(new NameFilterSearchToken(0, "")); res = doCoreSearch(new NameFilterToken(0, ""));
break; break;
case BUILDING: case BUILDING:
// Last object - Building - object is found // Last object - Building - object is found
@ -151,7 +151,7 @@ public class CoreSearchRequest extends SearchRequest {
amenityResultsCounter = 0; amenityResultsCounter = 0;
addressResultsCounter = 0; addressResultsCounter = 0;
String keyword = token.getQueryText(); String keyword = token.getPlainText();
final List<SearchObject> searchObjects = new ArrayList<>(); final List<SearchObject> searchObjects = new ArrayList<>();
AmenitiesByNameSearch amByNameSearch = null; AmenitiesByNameSearch amByNameSearch = null;

View file

@ -23,7 +23,7 @@ public class IntermediateSearchRequest extends SearchRequest {
SearchToken token = searchScope.getSearchString().getLastToken(); SearchToken token = searchScope.getSearchString().getLastToken();
if (token != null && token.getType() == SearchToken.TokenType.NAME_FILTER) { if (token != null && token.getType() == SearchToken.TokenType.NAME_FILTER) {
keyword = token.getQueryText().toLowerCase(); keyword = token.getPlainText().toLowerCase();
} }
} }

View file

@ -3,6 +3,6 @@ package net.osmand.core.samples.android.sample1.search.tokens;
public class NameFilterToken extends SearchToken { public class NameFilterToken extends SearchToken {
public NameFilterToken(int startIndex, String plainText) { public NameFilterToken(int startIndex, String plainText) {
super(TokenType.NAME_FILTER, startIndex, plainText, null); super(TokenType.NAME_FILTER, startIndex, plainText);
} }
} }

View file

@ -4,18 +4,25 @@ import net.osmand.core.samples.android.sample1.search.objects.SearchObject;
public class ObjectToken extends SearchToken { public class ObjectToken extends SearchToken {
private SearchObject searchObject;
private boolean suggestion = true; private boolean suggestion = true;
public ObjectToken(SearchToken searchToken, SearchObject searchObject, boolean suggestion) { 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; this.suggestion = suggestion;
} }
public ObjectToken(int startIndex, String plainText, SearchObject searchObject, boolean 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; this.suggestion = suggestion;
} }
public SearchObject getSearchObject() {
return searchObject;
}
public boolean isSuggestion() { public boolean isSuggestion() {
return suggestion; return suggestion;
} }

View file

@ -1,25 +1,22 @@
package net.osmand.core.samples.android.sample1.search.tokens; package net.osmand.core.samples.android.sample1.search.tokens;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public abstract class SearchToken { public abstract class SearchToken {
public enum TokenType { public enum TokenType {
SEARCH_OBJECT, OBJECT,
NAME_FILTER NAME_FILTER
} }
private TokenType type; private TokenType type;
private SearchObject searchObject;
private int startIndex; 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.type = type;
this.startIndex = startIndex; this.startIndex = startIndex;
this.queryText = queryText; this.plainText = plainText;
this.searchObject = searchObject;
} }
public TokenType getType() { public TokenType getType() {
@ -30,19 +27,15 @@ public abstract class SearchToken {
return startIndex; return startIndex;
} }
public String getQueryText() { public String getPlainText() {
return queryText; return plainText;
} }
public int getLastIndex() { public int getLastIndex() {
return startIndex + queryText.length() - 1; return startIndex + plainText.length() - 1;
}
public SearchObject getSearchObject() {
return searchObject;
} }
public boolean hasEmptyQuery() { public boolean hasEmptyQuery() {
return Algorithms.isEmpty(queryText); return Algorithms.isEmpty(plainText);
} }
} }