From 9dbcf312df815a6e59d9e133f2644d16b81155c3 Mon Sep 17 00:00:00 2001 From: sergdevosm Date: Thu, 20 Aug 2020 21:07:51 +0300 Subject: [PATCH] Casting to an int implicitly --- .../osmand/search/core/SearchCoreFactory.java | 82 +++++++++---------- .../net/osmand/search/core/SearchResult.java | 3 +- .../net/osmand/util/GeoPointParserUtil.java | 37 ++++----- .../osmand/util/GeoPointParserUtilTest.java | 8 +- .../search/QuickSearchDialogFragment.java | 4 +- .../plus/search/QuickSearchListFragment.java | 2 +- 6 files changed, 67 insertions(+), 69 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index d9bef77fc2..a4916d4187 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -133,19 +133,19 @@ public class SearchCoreFactory { public int getMinimalSearchRadius(SearchPhrase phrase) { return 0; } - + @Override public int getNextSearchRadius(SearchPhrase phrase) { return 0; } - protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) throws IOException { subSearchApiOrPublish(phrase, resultMatcher, res, api, true); } - + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api, - boolean publish) + boolean publish) throws IOException { phrase.countUnknownWordsMatchMainResult(res); boolean firstUnknownWordMatches = res.firstUnknownWordMatches; @@ -154,7 +154,7 @@ public class SearchCoreFactory { leftUnknownSearchWords.removeAll(res.otherWordsMatch); } SearchResult newParentSearchResult = null; - if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null && + if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null && res.objectType == ObjectType.STREET && res.object instanceof Street && ((Street) res.object).getCity() != null) { City ct = ((Street) res.object).getCity(); SearchResult cityResult = new SearchResult(phrase); @@ -204,15 +204,15 @@ public class SearchCoreFactory { } } if (!leftUnknownSearchWords.isEmpty() && api != null && api.isSearchAvailable(phrase)) { - SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords, - phrase.isLastUnknownSearchWordComplete() || - !leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord())); - SearchResult prev = resultMatcher.setParentSearchResult(publish ? res : - resultMatcher.getParentSearchResult()); + SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords, + phrase.isLastUnknownSearchWordComplete() || + !leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord())); + SearchResult prev = resultMatcher.setParentSearchResult(publish ? res : + resultMatcher.getParentSearchResult()); api.search(nphrase, resultMatcher); resultMatcher.setParentSearchResult(prev); } - + } @Override @@ -307,7 +307,7 @@ public class SearchCoreFactory { public int getMinimalSearchRadius(SearchPhrase phrase) { return phrase.getRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS); } - + @Override public int getNextSearchRadius(SearchPhrase phrase) { return phrase.getNextRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS); @@ -383,7 +383,7 @@ public class SearchCoreFactory { private void searchByName(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { - if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 || + if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 || phrase.hasMoreThanOneUnknownSearchWord()|| phrase.isSearchTypeAllowed(ObjectType.POSTCODE, true)) { final boolean locSpecified = phrase.getLastTokenLocation() != null; LatLon loc = phrase.getLastTokenLocation(); @@ -424,7 +424,7 @@ public class SearchCoreFactory { if (object.getName().startsWith("<")) { return false; } - + if (!phrase.getUnknownWordToSearchBuildingNameMatcher().matches(stripBraces(sr.localeName))) { sr.priorityDistance = 5; } @@ -558,7 +558,7 @@ public class SearchCoreFactory { } // Take into account POI [bar] - 'Hospital 512' // BEFORE: it was searching exact match of whole phrase.getUnknownSearchPhrase() [ Check feedback ] - + final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1]; Iterator offlineIterator = phrase.getRadiusOfflineIndexes(BBOX_RADIUS, SearchPhraseDataType.POI); @@ -670,7 +670,7 @@ public class SearchCoreFactory { return phrase.getNextRadiusSearch(BBOX_RADIUS); } } - + protected static class PoiTypeResult { public AbstractPoiType pt; public Set foundWords = new LinkedHashSet(); @@ -709,7 +709,7 @@ public class SearchCoreFactory { this.activePoiFilters.put(filterOrder.get(i), i); } } - + public Map getPoiTypeResults(NameStringMatcher nm, NameStringMatcher nmAdditional) { Map results = new LinkedHashMap<>(); for (AbstractPoiType pf : topVisibleFilters) { @@ -764,7 +764,7 @@ public class SearchCoreFactory { } else { String enTranslation = a.getEnTranslation().toLowerCase(); if (!"no".equals(enTranslation) // && !"yes".equals(enTranslation) - ) { + ) { PoiTypeResult ptr = checkPoiType(nm, a); if (ptr != null) { results.put(a.getKeyName(), ptr); @@ -816,12 +816,12 @@ public class SearchCoreFactory { categories = types.getCategories(false); } } - + @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent(); NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); - + initPoiTypes(); if (showTopFiltersOnly) { for (AbstractPoiType pt : topVisibleFilters) { @@ -830,10 +830,10 @@ public class SearchCoreFactory { res.object = pt; addPoiTypeResult(phrase, resultMatcher, showTopFiltersOnly, getStandardFilterId(pt), res); } - + } else { boolean includeAdditional = !phrase.hasMoreThanOneUnknownSearchWord(); - NameStringMatcher nmAdditional = includeAdditional ? + NameStringMatcher nmAdditional = includeAdditional ? new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) : null; Map poiTypes = getPoiTypeResults(nm, nmAdditional); for (PoiTypeResult ptr : poiTypes.values()) { @@ -869,7 +869,7 @@ public class SearchCoreFactory { } private void addPoiTypeResult(SearchPhrase phrase, SearchResultMatcher resultMatcher, boolean showTopFiltersOnly, - String stdFilterId, SearchResult res) { + String stdFilterId, SearchResult res) { res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; res.firstUnknownWordMatches = true; @@ -893,7 +893,7 @@ public class SearchCoreFactory { return SEARCH_AMENITY_TYPE_PRIORITY + i.intValue(); } - + public String getStandardFilterId(AbstractPoiType poi) { return STD_POI_FILTER_PREFIX + poi.getKeyName(); @@ -926,7 +926,7 @@ public class SearchCoreFactory { private MapPoiTypes types; private AbstractPoiType unselectedPoiType; private String nameFilter; - + public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) { super(ObjectType.POI); this.types = types; @@ -975,7 +975,7 @@ public class SearchCoreFactory { nameFilter = phrase.getUnknownSearchPhrase(); } else if (searchAmenityTypesAPI != null && phrase.isFirstUnknownSearchWordComplete()) { NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); - NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(), + NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) ; searchAmenityTypesAPI.initPoiTypes(); Map poiTypeResults = searchAmenityTypesAPI.getPoiTypeResults(nm, nmAdditional); @@ -1010,7 +1010,7 @@ public class SearchCoreFactory { List offlineIndexes = phrase.getOfflineIndexes(); Set searchedPois = new TreeSet<>(); for (BinaryMapIndexReader r : offlineIndexes) { - ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, + ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, searchedPois, poiAdditionals, countExtraWords); if (poiTypeFilter instanceof CustomSearchPoiFilter) { rm = ((CustomSearchPoiFilter) poiTypeFilter).wrapResultMatcher(rm); @@ -1025,12 +1025,12 @@ public class SearchCoreFactory { } - private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter, - final SearchResultMatcher resultMatcher, final String nameFilter, + private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter, + final SearchResultMatcher resultMatcher, final String nameFilter, final BinaryMapIndexReader selected, final Set searchedPois, final Collection poiAdditionals, final int countExtraWords) { - - + + final NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); return new ResultMatcher() { @@ -1186,7 +1186,7 @@ public class SearchCoreFactory { NameStringMatcher nm = phrase.getMainUnknownNameStringMatcher(); for (Street object : c.getStreets()) { SearchResult res = new SearchResult(phrase); - + res.localeName = object.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()); res.otherNames = object.getAllNames(true); boolean pub = true; @@ -1266,7 +1266,7 @@ public class SearchCoreFactory { if (s != null) { BinaryMapIndexReader file = phrase.getLastSelectedWord().getResult().file; - + if (cacheBuilding != s) { cacheBuilding = s; SearchRequest sr = BinaryMapIndexReader @@ -1325,13 +1325,13 @@ public class SearchCoreFactory { res.location = b.getLocation(); } res.preferredZoom = 17; - + resultMatcher.publish(res); } String streetIntersection = phrase.getUnknownWordToSearch(); NameStringMatcher streetMatch = phrase.getMainUnknownNameStringMatcher(); - if (Algorithms.isEmpty(streetIntersection) || - (!Character.isDigit(streetIntersection.charAt(0)) && + if (Algorithms.isEmpty(streetIntersection) || + (!Character.isDigit(streetIntersection.charAt(0)) && CommonWords.getCommonSearch(streetIntersection) == -1) ) { for (Street street : s.getIntersectedStreets()) { SearchResult res = new SearchResult(phrase); @@ -1369,7 +1369,7 @@ public class SearchCoreFactory { return SEARCH_BUILDING_BY_STREET_PRIORITY; } } - + protected static class PoiAdditionalCustomFilter extends AbstractPoiType { protected List additionalPoiTypes = new ArrayList(); @@ -1378,7 +1378,7 @@ public class SearchCoreFactory { super(pt.getKeyName(), registry); additionalPoiTypes.add(pt); } - + @Override public boolean isAdditional() { return true; @@ -1397,7 +1397,7 @@ public class SearchCoreFactory { } return acceptedTypes; } - + } public static class SearchLocationAndUrlAPI extends SearchBaseAPI { @@ -1527,7 +1527,7 @@ public class SearchCoreFactory { sp.location = new LatLon(pnt.getLatitude(), pnt.getLongitude()); sp.localeName = ((float)pnt.getLatitude()) +", " + ((float) pnt.getLongitude()); if (pnt.getZoom() > 0) { - sp.preferredZoom = (int) pnt.getZoom(); + sp.preferredZoom = pnt.getZoom(); } sp.objectType = ObjectType.LOCATION; resultMatcher.publish(sp); @@ -1569,7 +1569,7 @@ public class SearchCoreFactory { } return retName; } - + public static boolean isLastWordCityGroup(SearchPhrase p ) { return p.isLastWord(ObjectType.CITY) || p.isLastWord(ObjectType.POSTCODE) || p.isLastWord(ObjectType.VILLAGE); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index d84ef029f0..79d11a3fe0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -32,8 +32,7 @@ public class SearchResult { public double priorityDistance; public LatLon location; - public float pZ = 15; - public int preferredZoom = Math.round(pZ); + public int preferredZoom = 15; public String localeName; public String alternateName; diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index 3248f7ca05..b82a2cbedb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -82,7 +82,7 @@ public class GeoPointParserUtil { // amap.com uses | in their URLs, which is an illegal character for a URL uri = URI.create(uriString.replaceAll("\\s+", "+") .replaceAll("%20", "+") - .replaceAll("%2F", ",") + .replaceAll("%2C", ",") .replaceAll("\\|", ";") .replaceAll("\\(\\(\\S+\\)\\)", "")); } catch (IllegalArgumentException e) { @@ -142,7 +142,7 @@ public class GeoPointParserUtil { } else { // data in the query and/or feature strings double lat = 0; double lon = 0; - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; Map queryMap = getQueryParameters(uri); if (fragment != null) { if (fragment.startsWith("map=")) { @@ -187,7 +187,7 @@ public class GeoPointParserUtil { if (vls != null && vls.length >= 2) { double lat = parseSilentInt(vls[0]) / 100000.; double lon = parseSilentInt(vls[1]) / 100000.; - float zoom = parseZoom(zm); + int zoom = parseZoom(zm); return new GeoParsedPoint(lat, lon, zoom); } } else if (simpleDomains.contains(host)) { @@ -198,11 +198,11 @@ public class GeoPointParserUtil { if (params.containsKey("lat") && params.containsKey("lon")) { final double lat = parseSilentDouble(params.get("lat")); final double lon = parseSilentDouble(params.get("lon")); - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; if (params.containsKey("z")) { - zoom = (float) parseZoom(params.get("z")); + zoom = parseZoom(params.get("z")); } else if (params.containsKey("zoom")) { - zoom = (float) parseZoom(params.get("zoom")); + zoom = parseZoom(params.get("zoom")); } return new GeoParsedPoint(lat, lon, zoom); } @@ -459,7 +459,7 @@ public class GeoPointParserUtil { lon = Double.valueOf(positionMatcher.group(2)); } - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; String searchRequest = null; for (String param : queryPart.split("&")) { String paramName; @@ -474,8 +474,7 @@ public class GeoPointParserUtil { } if ("z".equals(paramName) && paramValue != null) { -// zoom = Double.valueOf(paramValue).intValue(); - zoom = Float.valueOf(paramValue); + zoom = (int) Float.parseFloat(paramValue); } else if ("q".equals(paramName) && paramValue != null) { searchRequest = URLDecoder.decode(paramValue); } @@ -541,7 +540,7 @@ public class GeoPointParserUtil { if (vls.length >= 2) { double lat = parseSilentDouble(vls[0], Double.NaN); double lon = parseSilentDouble(vls[1], Double.NaN); - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; if (vls.length >= 3 || zmPart.length() > 0) { if (zmPart.length() == 0) { zmPart = vls[2]; @@ -567,10 +566,10 @@ public class GeoPointParserUtil { return vl.split(split); } - private static float parseZoom(String zoom) { + private static int parseZoom(String zoom) { try { if (zoom != null) { - return Float.valueOf(zoom); + return (int) Float.parseFloat(zoom); } } catch (NumberFormatException e) { } @@ -584,7 +583,7 @@ public class GeoPointParserUtil { private static double parseSilentDouble(String zoom, double vl) { try { if (zoom != null) { - return Float.valueOf(zoom); + return Double.valueOf(zoom); } } catch (NumberFormatException e) { } @@ -602,11 +601,11 @@ public class GeoPointParserUtil { } public static class GeoParsedPoint { - public static final float NO_ZOOM = -1; + public static final int NO_ZOOM = -1; private double lat = 0; private double lon = 0; - private float zoom = NO_ZOOM; + private int zoom = NO_ZOOM; private String label; private String query; private boolean geoPoint; @@ -625,12 +624,12 @@ public class GeoPointParserUtil { this.label = label.replaceAll("\\+", " "); } - public GeoParsedPoint(double lat, double lon, float zoom) { + public GeoParsedPoint(double lat, double lon, int zoom) { this(lat, lon); this.zoom = zoom; } - public GeoParsedPoint(double lat, double lon, float zoom, String label) { + public GeoParsedPoint(double lat, double lon, int zoom, String label) { this(lat, lon, label); this.zoom = zoom; } @@ -685,7 +684,7 @@ public class GeoPointParserUtil { return lon; } - public double getZoom() { + public int getZoom() { return zoom; } @@ -756,7 +755,7 @@ public class GeoPointParserUtil { @Override public String toString() { return isGeoPoint() ? - String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%.5f, label=%s]", lat, lon, zoom, label) : + String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) : String.format("GeoParsedPoint [query=%s]",query); } } diff --git a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java index 9c642788b2..5b1db95e17 100644 --- a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java @@ -39,7 +39,7 @@ public class GeoPointParserUtilTest { final double dlat = 34.99393, dlon = -106.61568; final double longLat = 34.993933029174805, longLon = -106.615680694580078; final String name = "Treasure Island"; - float z = GeoParsedPoint.NO_ZOOM; + int z = GeoParsedPoint.NO_ZOOM; String url; String noQueryParameters[] = { @@ -63,7 +63,7 @@ public class GeoPointParserUtilTest { "geo:0,0?m", "geo:0,0?m=", "geo:0,0?m=foo", - "geo:0,0?q=%F0%9D%F0", + "geo:0,0?q=%D0%9D%D0", "http://download.osmand.net/go?lat", "http://download.osmand.net/go?lat=", "http://download.osmand.net/go?lat=34.99393", @@ -789,7 +789,7 @@ public class GeoPointParserUtilTest { actual.getQuery() + "' != '" + expected.getQuery()); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - double aZoom = actual.getZoom(), eZoom = expected.getZoom(); + int aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { @@ -816,7 +816,7 @@ public class GeoPointParserUtilTest { throw new RuntimeException("Query param not equal"); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - double aZoom = actual.getZoom(), eZoom = expected.getZoom(); + int aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index a71b74f8a4..5be1d95cee 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -414,7 +414,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name); app.getSettings().setMapLocationToShow( searchResult.location.getLatitude(), searchResult.location.getLongitude(), - (int) searchResult.preferredZoom, pointDescription, true, searchResult.object); + searchResult.preferredZoom, pointDescription, true, searchResult.object); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); @@ -444,7 +444,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC hide(); } else if (group.getPoints().size() == 1) { FavouritePoint p = group.getPoints().get(0); - app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), (int) word.getResult().preferredZoom); + app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), word.getResult().preferredZoom); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); hide(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 2dc07af2cb..f667595650 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -260,7 +260,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), - (int) searchResult.preferredZoom, pointDescription, object); + searchResult.preferredZoom, pointDescription, object); } }