Formatting

This commit is contained in:
Roman Inflianskas 2016-07-05 19:20:58 +03:00
parent 75eb46b71e
commit b8dc11bad9

View file

@ -57,7 +57,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
protected int distanceInd = 0; protected int distanceInd = 0;
// in kilometers // 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; private final MapPoiTypes poiTypes;
@ -78,7 +78,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
initSearchAll(); initSearchAll();
updatePoiAdditionals(); updatePoiAdditionals();
} else { } else {
if(type.isAdditional()) { if (type.isAdditional()) {
setSavedFilterByName(type.getKeyName().replace('_', ':')); setSavedFilterByName(type.getKeyName().replace('_', ':'));
} }
updateTypesToAccept(type); updateTypesToAccept(type);
@ -96,7 +96,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
// constructor for user defined filters // constructor for user defined filters
public PoiUIFilter(String name, String filterId, public PoiUIFilter(String name, String filterId,
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app){ Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app) {
this.app = app; this.app = app;
isStandardFilter = false; isStandardFilter = false;
poiTypes = app.getPoiTypes(); poiTypes = app.getPoiTypes();
@ -134,8 +134,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
if (prev != null) { if (prev != null) {
AmenityNameFilter nameFilter = getNameFilter(filterByName); AmenityNameFilter nameFilter = getNameFilter(filterByName);
List<Amenity> newResults = new ArrayList<Amenity>(); List<Amenity> newResults = new ArrayList<Amenity>();
for(Amenity a : prev) { for (Amenity a : prev) {
if(nameFilter.accept(a)) { if (nameFilter.accept(a)) {
newResults.add(a); newResults.add(a);
} }
} }
@ -154,7 +154,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public List<Amenity> searchAgain(double lat, double lon) { public List<Amenity> searchAgain(double lat, double lon) {
List<Amenity> amenityList ; List<Amenity> amenityList;
if (currentSearchResult != null) { if (currentSearchResult != null) {
amenityList = currentSearchResult; amenityList = currentSearchResult;
} else { } else {
@ -165,45 +165,45 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
} }
public List<Amenity> searchFurther(double latitude, double longitude, ResultMatcher<Amenity> matcher){ public List<Amenity> searchFurther(double latitude, double longitude, ResultMatcher<Amenity> matcher) {
if (distanceInd < distanceToSearchValues.length - 1) { if (distanceInd < distanceToSearchValues.length - 1) {
distanceInd ++; distanceInd++;
} }
List<Amenity> amenityList = searchAmenities( latitude, longitude, matcher); List<Amenity> amenityList = searchAmenities(latitude, longitude, matcher);
MapUtils.sortListOfMapObject(amenityList, latitude, longitude); MapUtils.sortListOfMapObject(amenityList, latitude, longitude);
return amenityList; return amenityList;
} }
private void initSearchAll(){ private void initSearchAll() {
for(PoiCategory t : poiTypes.getCategories(false)){ for (PoiCategory t : poiTypes.getCategories(false)) {
acceptedTypes.put(t, null); 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; return distanceInd < distanceToSearchValues.length - 1;
} }
public String getSearchArea(boolean next) { public String getSearchArea(boolean next) {
int distInd = distanceInd; int distInd = distanceInd;
if (next && (distanceInd < distanceToSearchValues.length - 1)) { 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; distInd = distanceInd + 1;
} }
double val = distanceToSearchValues[distInd]; double val = distanceToSearchValues[distInd];
if(val >= 1){ if (val >= 1) {
return " < " + OsmAndFormatter.getFormattedDistance(((int)val * 1000), app); //$NON-NLS-1$//$NON-NLS-2$ return " < " + OsmAndFormatter.getFormattedDistance(((int) val * 1000), app); //$NON-NLS-1$//$NON-NLS-2$
} else { } else {
return " < " + OsmAndFormatter.getFormattedDistance(500, app); //$NON-NLS-1$ return " < " + OsmAndFormatter.getFormattedDistance(500, app); //$NON-NLS-1$
} }
} }
public void clearPreviousZoom(){ public void clearPreviousZoom() {
distanceInd = 0; distanceInd = 0;
} }
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher){ public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher) {
clearPreviousZoom(); clearPreviousZoom();
List<Amenity> amenityList = searchAmenities(lat, lon, matcher); List<Amenity> amenityList = searchAmenities(lat, lon, matcher);
MapUtils.sortListOfMapObject(amenityList, lat, lon); MapUtils.sortListOfMapObject(amenityList, lat, lon);
@ -232,10 +232,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
double baseDistY = MapUtils.getDistance(lat, lon, lat - 1, lon); double baseDistY = MapUtils.getDistance(lat, lon, lat - 1, lon);
double baseDistX = MapUtils.getDistance(lat, lon, lat, lon - 1); double baseDistX = MapUtils.getDistance(lat, lon, lat, lon - 1);
double distance = distanceToSearchValues[distanceInd] * 1000; double distance = distanceToSearchValues[distanceInd] * 1000;
double topLatitude = Math.min(lat + (distance/ baseDistY ), 84.); double topLatitude = Math.min(lat + (distance / baseDistY), 84.);
double bottomLatitude = Math.max(lat - (distance/ baseDistY ), -84.); double bottomLatitude = Math.max(lat - (distance / baseDistY), -84.);
double leftLongitude = Math.max(lon - (distance / baseDistX), -180); 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); return searchAmenitiesInternal(lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, matcher);
} }
@ -284,16 +284,16 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
String[] items = filter.split(" "); String[] items = filter.split(" ");
boolean allTime = false; boolean allTime = false;
boolean open = false; boolean open = false;
Map<PoiType, String> poiAdditionalsFilter = null; Map<PoiType, String> poiAdditionalsFilter = null;
for(String s : items) { for (String s : items) {
s = s.trim(); s = s.trim();
if(!Algorithms.isEmpty(s)){ if (!Algorithms.isEmpty(s)) {
if(getNameToken24H().equalsIgnoreCase(s)){ if (getNameToken24H().equalsIgnoreCase(s)) {
allTime = true; allTime = true;
} else if(getNameTokenOpen().equalsIgnoreCase(s)){ } else if (getNameTokenOpen().equalsIgnoreCase(s)) {
open = true; open = true;
} else if(poiAdditionals.containsKey(s.toLowerCase())) { } else if (poiAdditionals.containsKey(s.toLowerCase())) {
if(poiAdditionalsFilter == null) { if (poiAdditionalsFilter == null) {
poiAdditionalsFilter = new LinkedHashMap<PoiType, String>(); poiAdditionalsFilter = new LinkedHashMap<PoiType, String>();
} }
poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null); poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null);
@ -320,14 +320,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
return false; return false;
} }
} }
if(poiAdditionals != null) { if (poiAdditionals != null) {
Iterator<Entry<PoiType, String>> it = poiAdditionals.entrySet().iterator(); Iterator<Entry<PoiType, String>> it = poiAdditionals.entrySet().iterator();
while(it.hasNext()) { while (it.hasNext()) {
Entry<PoiType, String> e = it.next(); Entry<PoiType, String> e = it.next();
String inf = a.getAdditionalInfo(e.getKey().getKeyName()); String inf = a.getAdditionalInfo(e.getKey().getKeyName());
if(inf == null) { if (inf == null) {
return false; return false;
} else if(e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) { } else if (e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) {
return false; return false;
} }
} }
@ -384,7 +384,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
}; };
} }
public String getName(){ public String getName() {
return name; return name;
} }
@ -430,14 +430,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
* @param type * @param type
* @return null if all subtypes are accepted/ empty list if type is not accepted at all * @return null if all subtypes are accepted/ empty list if type is not accepted at all
*/ */
public Set<String> getAcceptedSubtypes(PoiCategory type){ public Set<String> getAcceptedSubtypes(PoiCategory type) {
if(!acceptedTypes.containsKey(type)){ if (!acceptedTypes.containsKey(type)) {
return Collections.emptySet(); return Collections.emptySet();
} }
return acceptedTypes.get(type); return acceptedTypes.get(type);
} }
public boolean isTypeAccepted(PoiCategory t){ public boolean isTypeAccepted(PoiCategory t) {
return acceptedTypes.containsKey(t); return acceptedTypes.containsKey(t);
} }
@ -446,10 +446,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
poiAdditionals.clear(); poiAdditionals.clear();
} }
public boolean areAllTypesAccepted(){ public boolean areAllTypesAccepted() {
if(poiTypes.getCategories(false).size() == acceptedTypes.size()){ if (poiTypes.getCategories(false).size() == acceptedTypes.size()) {
for(PoiCategory a : acceptedTypes.keySet()){ for (PoiCategory a : acceptedTypes.keySet()) {
if(acceptedTypes.get(a) != null){ if (acceptedTypes.get(a) != null) {
return false; return false;
} }
} }
@ -473,7 +473,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add); poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
} }
if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) { if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
for(PoiType ps : ((PoiFilter) pt).getPoiTypes()) { for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
fillPoiAdditionals(ps); fillPoiAdditionals(ps);
} }
} }
@ -527,11 +527,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
combineWithPoiFilter(f); combineWithPoiFilter(f);
} }
public Map<PoiCategory, LinkedHashSet<String>> getAcceptedTypes(){ public Map<PoiCategory, LinkedHashSet<String>> getAcceptedTypes() {
return new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(acceptedTypes); return new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(acceptedTypes);
} }
public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet<String> accept){ public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet<String> accept) {
acceptedTypes.put(t, accept); acceptedTypes.put(t, accept);
fillPoiAdditionals(t); fillPoiAdditionals(t);
} }
@ -545,7 +545,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
updatePoiAdditionals(); updatePoiAdditionals();
} }
public String getFilterId(){ public String getFilterId() {
return filterId; return filterId;
} }
@ -553,7 +553,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
return poiAdditionals; return poiAdditionals;
} }
public String getIconId(){ public String getIconId() {
if (filterId.startsWith(STD_PREFIX)) { if (filterId.startsWith(STD_PREFIX)) {
return standardIconId; return standardIconId;
} else if (filterId.startsWith(USER_PREFIX)) { } else if (filterId.startsWith(USER_PREFIX)) {
@ -582,11 +582,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
if (!poiTypes.isRegisteredType(type)) { if (!poiTypes.isRegisteredType(type)) {
type = poiTypes.getOtherPoiCategory(); type = poiTypes.getOtherPoiCategory();
} }
if (!acceptedTypes.containsKey(type)){ if (!acceptedTypes.containsKey(type)) {
return false; return false;
} }
LinkedHashSet<String> set = acceptedTypes.get(type); LinkedHashSet<String> set = acceptedTypes.get(type);
if (set == null){ if (set == null) {
return true; return true;
} }
return set.contains(subtype); return set.contains(subtype);
@ -603,13 +603,13 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
if (another.filterId.equals(this.filterId)) { if (another.filterId.equals(this.filterId)) {
return 0; return 0;
} else { } else {
return this.name.compareTo(another.name); return this.name.compareTo(another.name);
} }
} }
public interface AmenityNameFilter { public interface AmenityNameFilter {
public boolean accept(Amenity a) ; public boolean accept(Amenity a);
} }
} }