From 28bb3bf87366f6c93bb7f8e789c246ded6320bbb Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 17 Oct 2016 12:38:41 +0300 Subject: [PATCH] Added OR AND for poi additional filter --- .../src/net/osmand/plus/poi/PoiUIFilter.java | 67 ++++++++++++------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 51aa21ac9f..471af75800 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -1,18 +1,8 @@ package net.osmand.plus.poi; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeSet; +import android.content.Context; +import android.support.annotation.NonNull; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; @@ -34,8 +24,19 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser.OpeningHours; -import android.content.Context; -import android.support.annotation.NonNull; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeSet; public class PoiUIFilter implements SearchPoiTypeFilter, Comparable, CustomSearchPoiFilter { @@ -289,7 +290,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable String[] items = filter.split(" "); boolean allTime = false; boolean open = false; - Map poiAdditionalsFilter = null; + List poiAdditionalsFilter = null; for (String s : items) { s = s.trim(); if (!Algorithms.isEmpty(s)) { @@ -299,9 +300,12 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable open = true; } else if (poiAdditionals.containsKey(s.toLowerCase())) { if (poiAdditionalsFilter == null) { - poiAdditionalsFilter = new LinkedHashMap(); + poiAdditionalsFilter = new ArrayList<>(); + } + PoiType pt = poiAdditionals.get(s.toLowerCase()); + if (pt != null) { + poiAdditionalsFilter.add(pt); } - poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null); } else { nmFilter.append(s).append(" "); } @@ -311,7 +315,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, - final boolean allTime, final boolean open, final Map poiAdditionals) { + final boolean allTime, final boolean open, final List poiAdditionals) { final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; @@ -327,13 +331,26 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } } if (poiAdditionals != null) { - Iterator> it = poiAdditionals.entrySet().iterator(); - while (it.hasNext()) { - Entry e = it.next(); - String inf = a.getAdditionalInfo(e.getKey().getKeyName()); - if (inf == null) { - return false; - } else if (e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) { + Map> poiAdditionalCategoriesMap = new HashMap<>(); + for (PoiType pt : poiAdditionals) { + String category = pt.getPoiAdditionalCategory(); + List types = poiAdditionalCategoriesMap.get(category); + if (types == null) { + types = new ArrayList<>(); + poiAdditionalCategoriesMap.put(category, types); + } + types.add(pt); + } + for (List types : poiAdditionalCategoriesMap.values()) { + boolean acceptedAnyInCategory = false; + for (PoiType p : types) { + String inf = a.getAdditionalInfo(p.getKeyName()); + if (inf != null) { + acceptedAnyInCategory = true; + break; + } + } + if (!acceptedAnyInCategory) { return false; } }