Search in sources :

Example 1 with Collator

use of net.osmand.Collator in project Osmand by osmandapp.

the class BinaryMapIndexReader method searchPoiCategoriesByName.

public Map<PoiCategory, List<String>> searchPoiCategoriesByName(String query, Map<PoiCategory, List<String>> map) throws IOException {
    if (query == null || query.length() == 0) {
        throw new IllegalArgumentException();
    }
    Collator collator = OsmAndCollator.primaryCollator();
    for (PoiRegion poiIndex : poiIndexes) {
        poiAdapter.initCategories(poiIndex);
        for (int i = 0; i < poiIndex.categories.size(); i++) {
            String cat = poiIndex.categories.get(i);
            PoiCategory catType = poiIndex.categoriesType.get(i);
            if (CollatorStringMatcher.cmatches(collator, cat, query, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) {
                map.put(catType, null);
            } else {
                List<String> subcats = poiIndex.subcategories.get(i);
                for (int j = 0; j < subcats.size(); j++) {
                    if (CollatorStringMatcher.cmatches(collator, subcats.get(j), query, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) {
                        if (!map.containsKey(catType)) {
                            map.put(catType, new ArrayList<String>());
                        }
                        List<String> list = map.get(catType);
                        if (list != null) {
                            list.add(subcats.get(j));
                        }
                    }
                }
            }
        }
    }
    return map;
}
Also used : PoiCategory(net.osmand.osm.PoiCategory) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion) OsmAndCollator(net.osmand.OsmAndCollator) Collator(net.osmand.Collator)

Aggregations

Collator (net.osmand.Collator)1 OsmAndCollator (net.osmand.OsmAndCollator)1 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)1 PoiCategory (net.osmand.osm.PoiCategory)1