From b8dc11bad9d124d5d1cbf9cc504d96e065c5d42d Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Tue, 5 Jul 2016 19:20:58 +0300 Subject: [PATCH] Formatting --- .../src/net/osmand/plus/poi/PoiUIFilter.java | 196 +++++++++--------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index fe3827a1fc..1a34060a2e 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -38,12 +38,12 @@ import android.content.Context; import android.support.annotation.NonNull; public class PoiUIFilter implements SearchPoiTypeFilter, Comparable { - + public final static String STD_PREFIX = "std_"; //$NON-NLS-1$ public final static String USER_PREFIX = "user_"; //$NON-NLS-1$ public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; //$NON-NLS-1$ public final static String BY_NAME_FILTER_ID = USER_PREFIX + "by_name"; //$NON-NLS-1$ - + private Map> acceptedTypes = new LinkedHashMap>(); private Map poiAdditionals = new HashMap(); @@ -52,15 +52,15 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable protected String standardIconId = ""; protected String name; protected boolean isStandardFilter; - + protected final OsmandApplication app; - + protected int distanceInd = 0; // in kilometers - protected double[] distanceToSearchValues = new double[] {1, 2, 5, 10, 20, 50, 100, 200, 500}; - + protected double[] distanceToSearchValues = new double[]{1, 2, 5, 10, 20, 50, 100, 200, 500}; + private final MapPoiTypes poiTypes; - + protected String filterByName = null; protected String savedFilterByName = null; protected List currentSearchResult = null; @@ -71,21 +71,21 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable isStandardFilter = true; standardIconId = (type == null ? null : type.getKeyName()); filterId = STD_PREFIX + standardIconId + idSuffix; - + poiTypes = application.getPoiTypes(); name = type == null ? application.getString(R.string.poi_filter_closest_poi) : (type.getTranslation() + idSuffix); //$NON-NLS-1$ if (type == null) { initSearchAll(); updatePoiAdditionals(); } else { - if(type.isAdditional()) { + if (type.isAdditional()) { setSavedFilterByName(type.getKeyName().replace('_', ':')); } updateTypesToAccept(type); } } - - + + // search by name standard protected PoiUIFilter(OsmandApplication application) { this.app = application; @@ -95,8 +95,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } // constructor for user defined filters - public PoiUIFilter(String name, String filterId, - Map> acceptedTypes, OsmandApplication app){ + public PoiUIFilter(String name, String filterId, + Map> acceptedTypes, OsmandApplication app) { this.app = app; isStandardFilter = false; poiTypes = app.getPoiTypes(); @@ -123,38 +123,38 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable public String getFilterByName() { return filterByName; } - + public void setFilterByName(String filterByName) { this.filterByName = filterByName; updateFilterResults(); } - + public void updateFilterResults() { List prev = currentSearchResult; if (prev != null) { AmenityNameFilter nameFilter = getNameFilter(filterByName); List newResults = new ArrayList(); - for(Amenity a : prev) { - if(nameFilter.accept(a)) { + for (Amenity a : prev) { + if (nameFilter.accept(a)) { newResults.add(a); } } currentSearchResult = newResults; } } - + public void setSavedFilterByName(String filterByName) { this.filterByName = filterByName; this.savedFilterByName = filterByName; } - + public String getSavedFilterByName() { return savedFilterByName; } - - + + public List searchAgain(double lat, double lon) { - List amenityList ; + List amenityList; if (currentSearchResult != null) { amenityList = currentSearchResult; } else { @@ -163,47 +163,47 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable MapUtils.sortListOfMapObject(amenityList, lat, lon); return amenityList; } - - public List searchFurther(double latitude, double longitude, ResultMatcher matcher){ + + public List searchFurther(double latitude, double longitude, ResultMatcher matcher) { if (distanceInd < distanceToSearchValues.length - 1) { - distanceInd ++; + distanceInd++; } - List amenityList = searchAmenities( latitude, longitude, matcher); + List amenityList = searchAmenities(latitude, longitude, matcher); MapUtils.sortListOfMapObject(amenityList, latitude, longitude); return amenityList; } - private void initSearchAll(){ - for(PoiCategory t : poiTypes.getCategories(false)){ + private void initSearchAll() { + for (PoiCategory t : poiTypes.getCategories(false)) { acceptedTypes.put(t, null); } - distanceToSearchValues = new double[] {0.5, 1, 2, 5, 10, 20, 50, 100}; + distanceToSearchValues = new double[]{0.5, 1, 2, 5, 10, 20, 50, 100}; } - public boolean isSearchFurtherAvailable(){ + public boolean isSearchFurtherAvailable() { return distanceInd < distanceToSearchValues.length - 1; } public String getSearchArea(boolean next) { int distInd = distanceInd; if (next && (distanceInd < distanceToSearchValues.length - 1)) { - //This is workaround for the SearchAmenityTask.onPreExecute() case + //This is workaround for the SearchAmenityTask.onPreExecute() case distInd = distanceInd + 1; } double val = distanceToSearchValues[distInd]; - if(val >= 1){ - return " < " + OsmAndFormatter.getFormattedDistance(((int)val * 1000), app); //$NON-NLS-1$//$NON-NLS-2$ + if (val >= 1) { + return " < " + OsmAndFormatter.getFormattedDistance(((int) val * 1000), app); //$NON-NLS-1$//$NON-NLS-2$ } else { return " < " + OsmAndFormatter.getFormattedDistance(500, app); //$NON-NLS-1$ } } - - public void clearPreviousZoom(){ + + public void clearPreviousZoom() { distanceInd = 0; } - - public List initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher matcher){ + + public List initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher matcher) { clearPreviousZoom(); List amenityList = searchAmenities(lat, lon, matcher); MapUtils.sortListOfMapObject(amenityList, lat, lon); @@ -221,24 +221,24 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable amenityList = searchFurther(lat, lon, matcher); } } - return amenityList; + return amenityList; } - + public boolean isAutomaticallyIncreaseSearch() { return true; } - + private List searchAmenities(double lat, double lon, ResultMatcher matcher) { double baseDistY = MapUtils.getDistance(lat, lon, lat - 1, lon); double baseDistX = MapUtils.getDistance(lat, lon, lat, lon - 1); double distance = distanceToSearchValues[distanceInd] * 1000; - double topLatitude = Math.min(lat + (distance/ baseDistY ), 84.); - double bottomLatitude = Math.max(lat - (distance/ baseDistY ), -84.); + double topLatitude = Math.min(lat + (distance / baseDistY), 84.); + double bottomLatitude = Math.max(lat - (distance / baseDistY), -84.); double leftLongitude = Math.max(lon - (distance / baseDistX), -180); - double rightLongitude = Math.min(lon + (distance/ baseDistX), 180); + double rightLongitude = Math.min(lon + (distance / baseDistX), 180); return searchAmenitiesInternal(lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, matcher); } - + public List searchAmenities(double top, double left, double bottom, double right, int zoom, ResultMatcher matcher) { List results = new ArrayList(); @@ -259,21 +259,21 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable results.addAll(amenities); return results; } - + public List searchAmenitiesOnThePath(List locs, int poiSearchDeviationRadius) { return app.getResourceManager().searchAmenitiesOnThePath(locs, poiSearchDeviationRadius, this, wrapResultMatcher(null)); } - + protected List searchAmenitiesInternal(double lat, double lon, double topLatitude, double bottomLatitude, double leftLongitude, double rightLongitude, final ResultMatcher matcher) { return app.getResourceManager().searchAmenities(this, topLatitude, leftLongitude, bottomLatitude, rightLongitude, -1, wrapResultMatcher(matcher)); } - + public AmenityNameFilter getNameFilter(String filter) { if (Algorithms.isEmpty(filter)) { return new AmenityNameFilter() { - + @Override public boolean accept(Amenity a) { return true; @@ -284,16 +284,16 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable String[] items = filter.split(" "); boolean allTime = false; boolean open = false; - Map poiAdditionalsFilter = null; - for(String s : items) { + Map poiAdditionalsFilter = null; + for (String s : items) { s = s.trim(); - if(!Algorithms.isEmpty(s)){ - if(getNameToken24H().equalsIgnoreCase(s)){ + if (!Algorithms.isEmpty(s)) { + if (getNameToken24H().equalsIgnoreCase(s)) { allTime = true; - } else if(getNameTokenOpen().equalsIgnoreCase(s)){ + } else if (getNameTokenOpen().equalsIgnoreCase(s)) { open = true; - } else if(poiAdditionals.containsKey(s.toLowerCase())) { - if(poiAdditionalsFilter == null) { + } else if (poiAdditionals.containsKey(s.toLowerCase())) { + if (poiAdditionalsFilter == null) { poiAdditionalsFilter = new LinkedHashMap(); } poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null); @@ -311,7 +311,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; return new AmenityNameFilter() { - + @Override public boolean accept(Amenity a) { if (sm != null) { @@ -320,14 +320,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable return false; } } - if(poiAdditionals != null) { + if (poiAdditionals != null) { Iterator> it = poiAdditionals.entrySet().iterator(); - while(it.hasNext()) { + while (it.hasNext()) { Entry e = it.next(); String inf = a.getAdditionalInfo(e.getKey().getKeyName()); - if(inf == null) { + if (inf == null) { return false; - } else if(e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) { + } else if (e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) { return false; } } @@ -354,11 +354,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } }; } - + public String getNameToken24H() { return app.getString(R.string.shared_string_is_open_24_7).replace(' ', '_').toLowerCase(); } - + public String getNameTokenOpen() { return app.getString(R.string.shared_string_is_open).replace(' ', '_').toLowerCase(); } @@ -366,7 +366,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable private ResultMatcher wrapResultMatcher(final ResultMatcher matcher) { final AmenityNameFilter nm = getNameFilter(filterByName); return new ResultMatcher() { - + @Override public boolean publish(Amenity a) { if (nm.accept(a)) { @@ -383,11 +383,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } }; } - - public String getName(){ + + public String getName() { return name; } - + public String getGeneratedName(int chars) { if (!filterId.equals(CUSTOM_FILTER_ID) || areAllTypesAccepted() || acceptedTypes.isEmpty()) { @@ -425,31 +425,31 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } return res.toString(); } - + /** * @param type * @return null if all subtypes are accepted/ empty list if type is not accepted at all */ - public Set getAcceptedSubtypes(PoiCategory type){ - if(!acceptedTypes.containsKey(type)){ + public Set getAcceptedSubtypes(PoiCategory type) { + if (!acceptedTypes.containsKey(type)) { return Collections.emptySet(); } return acceptedTypes.get(type); } - - public boolean isTypeAccepted(PoiCategory t){ + + public boolean isTypeAccepted(PoiCategory t) { return acceptedTypes.containsKey(t); } - + public void clearFilter() { acceptedTypes = new LinkedHashMap>(); poiAdditionals.clear(); } - - public boolean areAllTypesAccepted(){ - if(poiTypes.getCategories(false).size() == acceptedTypes.size()){ - for(PoiCategory a : acceptedTypes.keySet()){ - if(acceptedTypes.get(a) != null){ + + public boolean areAllTypesAccepted() { + if (poiTypes.getCategories(false).size() == acceptedTypes.size()) { + for (PoiCategory a : acceptedTypes.keySet()) { + if (acceptedTypes.get(a) != null) { return false; } } @@ -466,19 +466,19 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable fillPoiAdditionals(pt); } } - + private void fillPoiAdditionals(AbstractPoiType pt) { for (PoiType add : pt.getPoiAdditionals()) { poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add); poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add); } if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) { - for(PoiType ps : ((PoiFilter) pt).getPoiTypes()) { + for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) { fillPoiAdditionals(ps); } } } - + private void updatePoiAdditionals() { Iterator>> e = acceptedTypes.entrySet().iterator(); poiAdditionals.clear(); @@ -527,15 +527,15 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable combineWithPoiFilter(f); } - public Map> getAcceptedTypes(){ + public Map> getAcceptedTypes() { return new LinkedHashMap>(acceptedTypes); } - - public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet accept){ + + public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet accept) { acceptedTypes.put(t, accept); fillPoiAdditionals(t); } - + public void setTypeToAccept(PoiCategory poiCategory, boolean b) { if (b) { acceptedTypes.put(poiCategory, null); @@ -544,16 +544,16 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } updatePoiAdditionals(); } - - public String getFilterId(){ + + public String getFilterId() { return filterId; } - + public Map getPoiAdditionals() { return poiAdditionals; } - - public String getIconId(){ + + public String getIconId() { if (filterId.startsWith(STD_PREFIX)) { return standardIconId; } else if (filterId.startsWith(USER_PREFIX)) { @@ -561,19 +561,19 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } return filterId; } - + public boolean isStandardFilter() { return isStandardFilter; } - + public void setStandardFilter(boolean isStandardFilter) { this.isStandardFilter = isStandardFilter; } - + public Context getApplication() { return app; } - + @Override public boolean accept(PoiCategory type, String subtype) { if (type == null) { @@ -582,11 +582,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable if (!poiTypes.isRegisteredType(type)) { type = poiTypes.getOtherPoiCategory(); } - if (!acceptedTypes.containsKey(type)){ + if (!acceptedTypes.containsKey(type)) { return false; } LinkedHashSet set = acceptedTypes.get(type); - if (set == null){ + if (set == null) { return true; } return set.contains(subtype); @@ -603,13 +603,13 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable if (another.filterId.equals(this.filterId)) { return 0; } else { - return this.name.compareTo(another.name); + return this.name.compareTo(another.name); } } public interface AmenityNameFilter { - - public boolean accept(Amenity a) ; + + public boolean accept(Amenity a); } }